Exemple #1
0
        private void OnStartup(object sender, StartupEventArgs e)
        {
            for (int i = 0; i + 1 < e.Args.Length; i++)
            {
                if (e.Args[i] == "-powerToysPid")
                {
                    int powerToysPid;
                    if (int.TryParse(e.Args[i + 1], out powerToysPid))
                    {
                        RunnerHelper.WaitForPowerToysRunner(powerToysPid, () =>
                        {
                            try
                            {
                                Dispose();
                            }
                            finally
                            {
                                Environment.Exit(0);
                            }
                        });
                    }

                    break;
                }
            }

            var bootTime = new System.Diagnostics.Stopwatch();

            bootTime.Start();
            Stopwatch.Normal("App.OnStartup - Startup cost", () =>
            {
                var textToLog = new StringBuilder();
                textToLog.AppendLine("Begin PowerToys Run startup ----------------------------------------------------");
                textToLog.AppendLine($"Runtime info:{ErrorReporting.RuntimeInfo()}");

                RegisterAppDomainExceptions();
                RegisterDispatcherUnhandledException();

                _themeManager = new ThemeManager(this);
                ImageLoader.Initialize(_themeManager.GetCurrentTheme());

                _settingsVM = new SettingWindowViewModel();
                _settings   = _settingsVM.Settings;
                _settings.UsePowerToysRunnerKeyboardHook = e.Args.Contains("--centralized-kb-hook");

                _stringMatcher         = new StringMatcher();
                StringMatcher.Instance = _stringMatcher;
                _stringMatcher.UserSettingSearchPrecision = _settings.QuerySearchPrecision;

                PluginManager.LoadPlugins(_settings.PluginSettings);
                _mainVM     = new MainViewModel(_settings);
                _mainWindow = new MainWindow(_settings, _mainVM);
                API         = new PublicAPIInstance(_settingsVM, _mainVM, _themeManager);
                PluginManager.InitializePlugins(API);

                Current.MainWindow       = _mainWindow;
                Current.MainWindow.Title = Constant.ExeFileName;

                // main windows needs initialized before theme change because of blur settings
                HttpClient.Proxy = _settings.Proxy;

                RegisterExitEvents();

                _settingsWatcher = new SettingsWatcher(_settings, _themeManager);

                _mainVM.MainWindowVisibility = Visibility.Visible;
                _mainVM.ColdStartFix();
                _themeManager.ThemeChanged += OnThemeChanged;
                textToLog.AppendLine("End PowerToys Run startup ----------------------------------------------------  ");

                bootTime.Stop();

                Log.Info(textToLog.ToString(), GetType());
                PowerToysTelemetry.Log.WriteEvent(new LauncherBootEvent()
                {
                    BootTimeMs = bootTime.ElapsedMilliseconds
                });

                // [Conditional("RELEASE")]
                // check update every 5 hours

                // check updates on startup
            });
        }