Ejemplo n.º 1
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            var isFirstRun = false;

            if (e.Args.Any() && e.Args[0].StartsWith("--squirrel"))
            {
                var cliHandler = new SquirrelCommandLineArgumentsHandler();
                if (cliHandler.HandleSquirrelArguments(e.Args))
                {
                    Log.Info("Handled Squirrel arguments. Shutting down.");
                    Current.Shutdown(1);
                    return;
                }

                isFirstRun = cliHandler.IsFirstRun;
            }

            if (!WaitForOtherInstancesToShutDown())
            {
                MessageBox.Show(
                    "Another Go To Window instance is already running." + Environment.NewLine +
                    "Exit by right-clicking the icon in the tray, and selecting 'Exit'.",
                    "Go To Window",
                    MessageBoxButton.OK,
                    MessageBoxImage.Information
                    );
                Log.Warn("Application already running. Shutting down.");
                Current.Shutdown(1);
                return;
            }

            // http://stackoverflow.com/questions/14635862/exception-occurs-while-pressing-a-button-on-touchscreen-using-a-stylus-or-a-fing
            DisableWpfTabletSupport();

            _context = new GoToWindowContext();

            _menu = new GoToWindowTrayIcon(_context);

            var shortcut = KeyboardShortcut.FromString(GoToWindow.Properties.Settings.Default.OpenShortcut);

            _context.EnableKeyboardHook(shortcut);

            _context.Init();

            if (shortcut.IsValid)
            {
                Log.InfoFormat("Application started. Shortcut is '{0}' ({1})", shortcut.ToHumanReadableString(), GoToWindow.Properties.Settings.Default.OpenShortcut);
            }
            else
            {
                Log.WarnFormat("Application started with invalid shortcut. Shortcut is '{0}', reason: {1}", GoToWindow.Properties.Settings.Default.OpenShortcut, shortcut.InvalidReason);
            }

            if (isFirstRun)
            {
                Log.Info("Squirrel: First run");
                Dispatcher.InvokeAsync(() =>
                {
                    new FirstRunWindow(_context)
                    {
                        DataContext = new FirstRunViewModel()
                    }.Show();
                });
            }
            else
            {
                _menu.ShowStartupTooltip();
            }

            SquirrelContext.AcquireUpdater().CheckForUpdates(_context.UpdateAvailable, null);
        }