Ejemplo n.º 1
0
        public static void Main()
        {
            Log.Info($"Starting PowerToys Run with PID={Process.GetCurrentProcess().Id}", typeof(App));
            if (SingleInstance <App> .InitializeAsFirstInstance())
            {
                using (var application = new App())
                {
                    application.InitializeComponent();
                    NativeEventWaiter.WaitForEventLoop(Constants.RunExitEvent(), () =>
                    {
                        Log.Warn("RunExitEvent was signaled. Exiting PowerToys", typeof(App));
                        ExitPowerToys(application);
                    });

                    int powerToysPid = GetPowerToysPId();
                    if (powerToysPid != 0)
                    {
                        Log.Info($"Runner pid={powerToysPid}", typeof(App));
                        RunnerHelper.WaitForPowerToysRunner(powerToysPid, () =>
                        {
                            Log.Info($"Runner with pid={powerToysPid} exited. Exiting PowerToys Run", typeof(App));
                            ExitPowerToys(application);
                        });
                    }

                    application.Run();
                }
            }
            else
            {
                Log.Error("There is already running PowerToys Run instance. Exiting PowerToys Run", typeof(App));
            }
        }
Ejemplo n.º 2
0
        protected override void OnStartup(StartupEventArgs e)
        {
            _args = e?.Args;

            // allow only one instance of color picker
            _instanceMutex = new Mutex(true, @"Local\PowerToys_ColorPicker_InstanceMutex", out bool createdNew);
            if (!createdNew)
            {
                Logger.LogWarning("There is ColorPicker instance running. Exiting Color Picker");
                _instanceMutex = null;
                Environment.Exit(0);
                return;
            }

            if (_args?.Length > 0)
            {
                _ = int.TryParse(_args[0], out _powerToysRunnerPid);

                Logger.LogInfo($"Color Picker started from the PowerToys Runner. Runner pid={_powerToysRunnerPid}");
                RunnerHelper.WaitForPowerToysRunner(_powerToysRunnerPid, () =>
                {
                    Logger.LogInfo("PowerToys Runner exited. Exiting ColorPicker");
                    Environment.Exit(0);
                });
            }
            else
            {
                _powerToysRunnerPid = -1;
            }

            _themeManager = new ThemeManager(this);
            base.OnStartup(e);
        }
Ejemplo n.º 3
0
        protected override void OnStartup(StartupEventArgs e)
        {
            // allow only one instance of color picker
            bool createdNew;

            _instanceMutex = new Mutex(true, @"Global\ColorPicker", out createdNew);
            if (!createdNew)
            {
                _instanceMutex = null;
                Application.Current.Shutdown();
                return;
            }

            if (_args.Length > 0)
            {
                _ = int.TryParse(_args[0], out _powerToysPid);
            }

            RunnerHelper.WaitForPowerToysRunner(_powerToysPid, () =>
            {
                Environment.Exit(0);
            });

            base.OnStartup(e);
        }
Ejemplo n.º 4
0
        protected override void OnStartup(StartupEventArgs e)
        {
            _args = e?.Args;

            // allow only one instance of color picker
            _instanceMutex = new Mutex(true, @"Local\PowerToys_ColorPicker_InstanceMutex", out bool createdNew);
            if (!createdNew)
            {
                _instanceMutex = null;
                Environment.Exit(0);
                return;
            }

            if (_args?.Length > 0)
            {
                _ = int.TryParse(_args[0], out _powerToysRunnerPid);

                RunnerHelper.WaitForPowerToysRunner(_powerToysRunnerPid, () =>
                {
                    Environment.Exit(0);
                });
            }
            else
            {
                _powerToysRunnerPid = -1;
            }

            _themeManager = new ThemeManager(this);
            base.OnStartup(e);
        }
Ejemplo n.º 5
0
        public static void Main(string[] args)
        {
            using (new UI.App())
            {
                App app = new App();
                app.InitializeComponent();

                if (args != null && args.Length >= ArgumentsQty)
                {
                    _            = int.TryParse(args[2], out int powerToysPID);
                    PowerToysPID = powerToysPID;

                    if (args[4] == "true")
                    {
                        IsElevated = true;
                    }
                    else
                    {
                        IsElevated = false;
                    }

                    if (args[5] == "true")
                    {
                        IsUserAnAdmin = true;
                    }
                    else
                    {
                        IsUserAnAdmin = false;
                    }

                    RunnerHelper.WaitForPowerToysRunner(PowerToysPID, () =>
                    {
                        Environment.Exit(0);
                    });

                    ipcmanager = new TwoWayPipeMessageIPCManaged(args[1], args[0], (string message) =>
                    {
                        if (IPCMessageReceivedCallback != null && message.Length > 0)
                        {
                            Application.Current.Dispatcher.BeginInvoke(new System.Action(() =>
                            {
                                IPCMessageReceivedCallback(message);
                            }));
                        }
                    });
                    ipcmanager.Start();
                    app.Run();
                }
                else
                {
                    MessageBox.Show(
                        "The application cannot be run as a standalone process. Please start the application through the runner.",
                        "Forbidden",
                        MessageBoxButton.OK);
                    app.Shutdown();
                }
            }
        }
Ejemplo n.º 6
0
        public void CanadianFrench()
        {
            var assembly = typeof(ObjectRelatedTest).GetTypeInfo().Assembly;

            using (new CultureSession("fr-CA"))
            {
                RunnerHelper.RunAllTests(assembly, false);
            }
        }
Ejemplo n.º 7
0
        public void Japanese()
        {
            var assembly = typeof(ObjectRelatedTest).GetTypeInfo().Assembly;

            using (new CultureSession("ja-JP"))
            {
                RunnerHelper.RunAllTests(assembly, false);
            }
        }
Ejemplo n.º 8
0
        private void OnStartup(object sender, StartupEventArgs e)
        {
            AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;

            RunnerHelper.WaitForPowerToysRunner(PowerToysPID, () =>
            {
                Logger.LogInfo("Runner exited");
                Environment.Exit(0);
            });

            _themeManager = new ThemeManager(this);

            if (!FancyZonesEditorIO.ParseParams().Result)
            {
                FancyZonesEditorIO.ParseCommandLineArguments();
            }

            var parseResult = FancyZonesEditorIO.ParseZoneSettings();

            // 10ms retry loop with 1 second timeout
            if (!parseResult.Result)
            {
                CancellationTokenSource ts = new CancellationTokenSource();
                Task t = Task.Run(() =>
                {
                    while (!parseResult.Result && !ts.IsCancellationRequested)
                    {
                        Task.Delay(10).Wait();
                        parseResult = FancyZonesEditorIO.ParseZoneSettings();
                    }
                });

                try
                {
                    bool result = t.Wait(1000, ts.Token);
                    ts.Cancel();
                }
                catch (OperationCanceledException)
                {
                    ts.Dispose();
                }
            }

            // Error message if parsing failed
            if (!parseResult.Result)
            {
                Logger.LogError(ParsingErrorReportTag + ": " + parseResult.Message + "; " + ParsingErrorDataTag + ": " + parseResult.MalformedData);
                MessageBox.Show(parseResult.Message, FancyZonesEditor.Properties.Resources.Error_Parsing_Zones_Settings_Title, MessageBoxButton.OK);
            }

            MainWindowSettingsModel settings = ((App)Current).MainWindowSettings;

            settings.UpdateSelectedLayoutModel();

            Overlay.Show();
        }
Ejemplo n.º 9
0
        private void OnStartup(object sender, StartupEventArgs e)
        {
            AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;

            RunnerHelper.WaitForPowerToysRunner(PowerToysPID, () =>
            {
                Logger.LogInfo("Runner exited");
                Environment.Exit(0);
            });

            _themeManager = new ThemeManager(this);

            var parseResult = FancyZonesEditorIO.ParseParams();

            if (!parseResult.Result)
            {
                Logger.LogError(ParsingErrorReportTag + ": " + parseResult.Message + "; " + ParsingErrorDataTag + ": " + parseResult.MalformedData);
                MessageBox.Show(parseResult.Message, FancyZonesEditor.Properties.Resources.Error_Parsing_Data_Title, MessageBoxButton.OK);
            }

            parseResult = FancyZonesEditorIO.ParseAppliedLayouts();
            if (!parseResult.Result)
            {
                Logger.LogError(ParsingErrorReportTag + ": " + parseResult.Message + "; " + ParsingErrorDataTag + ": " + parseResult.MalformedData);
                MessageBox.Show(parseResult.Message, FancyZonesEditor.Properties.Resources.Error_Parsing_Data_Title, MessageBoxButton.OK);
            }

            parseResult = FancyZonesEditorIO.ParseCustomLayouts();
            if (!parseResult.Result)
            {
                Logger.LogError(ParsingErrorReportTag + ": " + parseResult.Message + "; " + ParsingErrorDataTag + ": " + parseResult.MalformedData);
                MessageBox.Show(parseResult.Message, FancyZonesEditor.Properties.Resources.Error_Parsing_Data_Title, MessageBoxButton.OK);
            }

            parseResult = FancyZonesEditorIO.ParseLayoutHotkeys();
            if (!parseResult.Result)
            {
                Logger.LogError(ParsingErrorReportTag + ": " + parseResult.Message + "; " + ParsingErrorDataTag + ": " + parseResult.MalformedData);
                MessageBox.Show(parseResult.Message, FancyZonesEditor.Properties.Resources.Error_Parsing_Data_Title, MessageBoxButton.OK);
            }

            parseResult = FancyZonesEditorIO.ParseLayoutTemplates();
            if (!parseResult.Result)
            {
                Logger.LogError(ParsingErrorReportTag + ": " + parseResult.Message + "; " + ParsingErrorDataTag + ": " + parseResult.MalformedData);
                MessageBox.Show(parseResult.Message, FancyZonesEditor.Properties.Resources.Error_Parsing_Data_Title, MessageBoxButton.OK);
            }

            MainWindowSettingsModel settings = ((App)Current).MainWindowSettings;

            settings.UpdateSelectedLayoutModel();

            Overlay.Show();
        }
Ejemplo n.º 10
0
        public static void Main(string[] args)
        {
            using (new UI.App())
            {
                App app = new App();
                app.InitializeComponent();

                if (args.Length >= ArgumentsQty)
                {
                    int.TryParse(args[2], out int powerToysPID);
                    PowerToysPID = powerToysPID;

                    if (args[4] == "true")
                    {
                        IsElevated = true;
                    }
                    else
                    {
                        IsElevated = false;
                    }

                    if (args[5] == "true")
                    {
                        IsUserAnAdmin = true;
                    }
                    else
                    {
                        IsUserAnAdmin = false;
                    }

                    RunnerHelper.WaitForPowerToysRunner(PowerToysPID, () => {
                        Environment.Exit(0);
                    });

                    ipcmanager = new TwoWayPipeMessageIPCManaged(args[1], args[0], null);
                    ipcmanager.Start();
                    app.Run();
                }
                else
                {
                    MessageBox.Show(
                        "The application cannot be run as a standalone process. Please start the application through the runner.",
                        "Forbidden",
                        MessageBoxButton.OK);
                    app.Shutdown();
                }

                // Terminate all threads of the process
                Environment.Exit(0);
            }
        }
Ejemplo n.º 11
0
        public static void Main(string[] args)
        {
            using (new Microsoft.PowerToys.Settings.UI.App())
            {
                App app = new App();
                app.InitializeComponent();

                if (args != null && args.Length >= RequiredArgumentsQty)
                {
                    _            = int.TryParse(args[(int)Arguments.PTPid], out int powerToysPID);
                    PowerToysPID = powerToysPID;

                    IsElevated    = args[(int)Arguments.ElevatedStatus] == "true";
                    IsUserAnAdmin = args[(int)Arguments.IsUserAdmin] == "true";

                    if (args.Length == RequiredAndOptionalArgumentsQty)
                    {
                        // open oobe window
                        app.ShowOobe = args[(int)Arguments.ShowOobeWindow] == "true";
                    }

                    RunnerHelper.WaitForPowerToysRunner(PowerToysPID, () =>
                    {
                        Environment.Exit(0);
                    });

                    ipcmanager = new TwoWayPipeMessageIPCManaged(args[(int)Arguments.SettingsPipeName], args[(int)Arguments.PTPipeName], (string message) =>
                    {
                        if (IPCMessageReceivedCallback != null && message.Length > 0)
                        {
                            Application.Current.Dispatcher.BeginInvoke(new System.Action(() =>
                            {
                                IPCMessageReceivedCallback(message);
                            }));
                        }
                    });
                    ipcmanager.Start();
                    app.Run();
                }
                else
                {
                    MessageBox.Show(
                        "The application cannot be run as a standalone process. Please start the application through the runner.",
                        "Forbidden",
                        MessageBoxButton.OK);
                    app.Shutdown();
                }
            }
        }
Ejemplo n.º 12
0
        public static void Main()
        {
            Log.Info($"Starting PowerToys Run with PID={Environment.ProcessId}", typeof(App));
            int powerToysPid = GetPowerToysPId();

            if (powerToysPid != 0)
            {
                // The process started from the PT Run module interface. One instance is handled there.
                Log.Info($"Runner pid={powerToysPid}", typeof(App));
                SingleInstance <App> .CreateInstanceMutex();
            }
            else
            {
                // If PT Run is started as standalone application check if there is already running instance
                if (!SingleInstance <App> .InitializeAsFirstInstance())
                {
                    Log.Warn("There is already running PowerToys Run instance. Exiting PowerToys Run", typeof(App));
                    return;
                }
            }

            using (var application = new App())
            {
                application.InitializeComponent();
                new Thread(() =>
                {
                    var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.RunExitEvent());
                    if (eventHandle.WaitOne())
                    {
                        Log.Warn("RunExitEvent was signaled. Exiting PowerToys", typeof(App));
                        ExitPowerToys(application);
                    }
                }).Start();

                if (powerToysPid != 0)
                {
                    RunnerHelper.WaitForPowerToysRunner(powerToysPid, () =>
                    {
                        Log.Info($"Runner with pid={powerToysPid} exited. Exiting PowerToys Run", typeof(App));
                        ExitPowerToys(application);
                    });
                }

                application.Run();
            }
        }
Ejemplo n.º 13
0
        public void ForceNegationOnAllTest()
        {
            if (!CheckContext.DefaulNegated)
            {
                return;
            }

            CheckContext.DefaulNegated = false;
            try
            {
                RunnerHelper.RunAllTests(false);
            }
            finally
            {
                CheckContext.DefaulNegated = true;
            }
        }
Ejemplo n.º 14
0
        private void OnStartup(object sender, StartupEventArgs e)
        {
            AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;

            RunnerHelper.WaitForPowerToysRunner(Settings.PowerToysPID, () =>
            {
                Environment.Exit(0);
            });

            LayoutModel foundModel = null;

            foreach (LayoutModel model in ZoneSettings.DefaultModels)
            {
                if (model.Type == Settings.ActiveZoneSetLayoutType)
                {
                    // found match
                    foundModel = model;
                    break;
                }
            }

            if (foundModel == null)
            {
                foreach (LayoutModel model in Settings.CustomModels)
                {
                    if ("{" + model.Guid.ToString().ToUpper() + "}" == Settings.ActiveZoneSetUUid.ToUpper())
                    {
                        // found match
                        foundModel = model;
                        break;
                    }
                }
            }

            if (foundModel == null)
            {
                foundModel = ZoneSettings.DefaultModels[0];
            }

            foundModel.IsSelected = true;

            EditorOverlay overlay = new EditorOverlay();

            overlay.Show();
            overlay.DataContext = foundModel;
        }
Ejemplo n.º 15
0
        public void ForceNegationOnAllTest()
        {
            if (!CheckContext.DefaulNegated)
            {
                return;
            }

            CheckContext.DefaulNegated = false;
            try
            {
                var assembly = typeof(ObjectRelatedTest).GetTypeInfo().Assembly;
                RunnerHelper.RunAllTests(assembly, false);
            }
            finally
            {
                CheckContext.DefaulNegated = true;
            }
        }
Ejemplo n.º 16
0
        private void OnStartup(object sender, StartupEventArgs e)
        {
            AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;

            RunnerHelper.WaitForPowerToysRunner(PowerToysPID, () =>
            {
                Environment.Exit(0);
            });

            FancyZonesEditorIO.ParseCommandLineArguments();
            FancyZonesEditorIO.ParseDeviceInfoData();

            MainWindowSettingsModel settings = ((App)Current).MainWindowSettings;

            settings.UpdateSelectedLayoutModel();

            Overlay.Show();
        }
Ejemplo n.º 17
0
        private void OnStartup(object sender, StartupEventArgs e)
        {
            RunnerHelper.WaitForPowerToysRunner(_powerToysPid, () =>
            {
                try
                {
                    Dispose();
                }
                finally
                {
                    Environment.Exit(0);
                }
            });

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

            bootTime.Start();
            Stopwatch.Normal("|App.OnStartup|Startup cost", () =>
            {
                Log.Info("|App.OnStartup|Begin PowerToys Run startup ----------------------------------------------------");
                Log.Info($"|App.OnStartup|Runtime info:{ErrorReporting.RuntimeInfo()}");
                RegisterAppDomainExceptions();
                RegisterDispatcherUnhandledException();

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

                _settingsVM = new SettingWindowViewModel();
                _settings   = _settingsVM.Settings;

                _alphabet.Initialize(_settings);
                _stringMatcher         = new StringMatcher(_alphabet);
                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, _alphabet, _themeManager);
                PluginManager.InitializePlugins(API);

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

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

                RegisterExitEvents();

                _settingsWatcher = new SettingsWatcher(_settings);

                _mainVM.MainWindowVisibility = Visibility.Visible;
                _mainVM.ColdStartFix();
                _themeManager.ThemeChanged += OnThemeChanged;
                Log.Info("|App.OnStartup|End PowerToys Run startup ----------------------------------------------------  ");

                bootTime.Stop();

                PowerToysTelemetry.Log.WriteEvent(new LauncherBootEvent()
                {
                    BootTimeMs = bootTime.ElapsedMilliseconds
                });

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

                // check updates on startup
            });
        }
Ejemplo n.º 18
0
        private void OnStartup(object sender, StartupEventArgs e)
        {
            AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;

            RunnerHelper.WaitForPowerToysRunner(PowerToysPID, () =>
            {
                Environment.Exit(0);
            });

            _themeManager = new ThemeManager(this);

            if (!FancyZonesEditorIO.ParseParams().Result)
            {
                FancyZonesEditorIO.ParseCommandLineArguments();
            }

            var parseResult = FancyZonesEditorIO.ParseZoneSettings();

            // 10ms retry loop with 1 second timeout
            if (!parseResult.Result)
            {
                CancellationTokenSource ts = new CancellationTokenSource();
                Task t = Task.Run(() =>
                {
                    while (!parseResult.Result && !ts.IsCancellationRequested)
                    {
                        Task.Delay(10).Wait();
                        parseResult = FancyZonesEditorIO.ParseZoneSettings();
                    }
                });

                try
                {
                    bool result = t.Wait(1000, ts.Token);
                    ts.Cancel();
                }
                catch (OperationCanceledException)
                {
                    ts.Dispose();
                }
            }

            // Error message if parsing failed
            if (!parseResult.Result)
            {
                var sb = new StringBuilder();
                sb.AppendLine();
                sb.AppendLine("## " + ParsingErrorReportTag);
                sb.AppendLine();
                sb.AppendLine(parseResult.Message);
                sb.AppendLine();
                sb.AppendLine(ParsingErrorDataTag);
                sb.AppendLine(parseResult.MalformedData);

                string message = parseResult.Message + Environment.NewLine + Environment.NewLine + FancyZonesEditor.Properties.Resources.Error_Parsing_Zones_Settings_User_Choice;
                if (MessageBox.Show(message, FancyZonesEditor.Properties.Resources.Error_Parsing_Zones_Settings_Title, MessageBoxButton.YesNo) == MessageBoxResult.No)
                {
                    // TODO: log error
                    ShowExceptionReportMessageBox(sb.ToString());
                    Environment.Exit(0);
                }

                ShowExceptionReportMessageBox(sb.ToString());
            }

            MainWindowSettingsModel settings = ((App)Current).MainWindowSettings;

            settings.UpdateSelectedLayoutModel();

            Overlay.Show();
        }
Ejemplo n.º 19
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;

                _mainVM         = new MainViewModel(_settings);
                _mainWindow     = new MainWindow(_settings, _mainVM);
                API             = new PublicAPIInstance(_settingsVM, _mainVM, _themeManager);
                _settingsReader = new SettingsReader(_settings, _themeManager);
                _settingsReader.ReadSettings();

                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();

                _settingsReader.ReadSettingsOnChange();

                _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
            });
        }
Ejemplo n.º 20
0
        public static void Main(string[] args)
        {
            using (new Microsoft.PowerToys.Settings.UI.App())
            {
                App app = new App();
                app.InitializeComponent();

                if (args != null && args.Length >= RequiredArgumentsQty)
                {
                    _            = int.TryParse(args[(int)Arguments.PTPid], out int powerToysPID);
                    PowerToysPID = powerToysPID;

                    IsElevated    = args[(int)Arguments.ElevatedStatus] == "true";
                    IsUserAnAdmin = args[(int)Arguments.IsUserAdmin] == "true";
                    app.ShowOobe  = args[(int)Arguments.ShowOobeWindow] == "true";

                    if (args.Length == RequiredAndOptionalArgumentsQty)
                    {
                        // open specific window
                        switch (args[(int)Arguments.SettingsWindow])
                        {
                        case "Overview": app.StartupPage = typeof(Microsoft.PowerToys.Settings.UI.Views.GeneralPage); break;

                        case "Awake": app.StartupPage = typeof(Microsoft.PowerToys.Settings.UI.Views.AwakePage); break;

                        case "ColorPicker": app.StartupPage = typeof(Microsoft.PowerToys.Settings.UI.Views.ColorPickerPage); break;

                        case "FancyZones": app.StartupPage = typeof(Microsoft.PowerToys.Settings.UI.Views.FancyZonesPage); break;

                        case "Run": app.StartupPage = typeof(Microsoft.PowerToys.Settings.UI.Views.PowerLauncherPage); break;

                        case "ImageResizer": app.StartupPage = typeof(Microsoft.PowerToys.Settings.UI.Views.ImageResizerPage); break;

                        case "KBM": app.StartupPage = typeof(Microsoft.PowerToys.Settings.UI.Views.KeyboardManagerPage); break;

                        case "PowerRename": app.StartupPage = typeof(Microsoft.PowerToys.Settings.UI.Views.PowerRenamePage); break;

                        case "FileExplorer": app.StartupPage = typeof(Microsoft.PowerToys.Settings.UI.Views.PowerPreviewPage); break;

                        case "ShortcutGuide": app.StartupPage = typeof(Microsoft.PowerToys.Settings.UI.Views.ShortcutGuidePage); break;

                        case "VideoConference": app.StartupPage = typeof(Microsoft.PowerToys.Settings.UI.Views.VideoConferencePage); break;

                        default: Debug.Assert(false, "Unexpected SettingsWindow argument value"); break;
                        }
                    }

                    RunnerHelper.WaitForPowerToysRunner(PowerToysPID, () =>
                    {
                        Environment.Exit(0);
                    });

                    ipcmanager = new TwoWayPipeMessageIPCManaged(args[(int)Arguments.SettingsPipeName], args[(int)Arguments.PTPipeName], (string message) =>
                    {
                        if (IPCMessageReceivedCallback != null && message.Length > 0)
                        {
                            Application.Current.Dispatcher.BeginInvoke(new System.Action(() =>
                            {
                                IPCMessageReceivedCallback(message);
                            }));
                        }
                    });
                    ipcmanager.Start();
                    app.Run();
                }
                else
                {
                    MessageBox.Show(
                        "The application cannot be run as a standalone process. Please start the application through the runner.",
                        "Forbidden",
                        MessageBoxButton.OK);
                    app.Shutdown();
                }
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used such as when the application is launched to open a specific file.
        /// </summary>
        /// <param name="args">Details about the launch request and process.</param>
        protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
        {
            var cmdArgs = Environment.GetCommandLineArgs();

            if (cmdArgs != null && cmdArgs.Length >= RequiredArgumentsQty)
            {
                // Skip the first argument which is prepended when launched by explorer
                if (cmdArgs[0].EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase) && cmdArgs[1].EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase) && (cmdArgs.Length >= RequiredArgumentsQty + 1))
                {
                    cmdArgs = cmdArgs.Skip(1).ToArray();
                }

                _            = int.TryParse(cmdArgs[(int)Arguments.PTPid], out int powerToysPID);
                PowerToysPID = powerToysPID;

                IsElevated    = cmdArgs[(int)Arguments.ElevatedStatus] == "true";
                IsUserAnAdmin = cmdArgs[(int)Arguments.IsUserAdmin] == "true";
                ShowOobe      = cmdArgs[(int)Arguments.ShowOobeWindow] == "true";
                ShowScoobe    = cmdArgs[(int)Arguments.ShowScoobeWindow] == "true";

                if (cmdArgs.Length == RequiredAndOptionalArgumentsQty)
                {
                    // open specific window
                    switch (cmdArgs[(int)Arguments.SettingsWindow])
                    {
                    case "Overview": StartupPage = typeof(Views.GeneralPage); break;

                    case "AlwaysOnTop": StartupPage = typeof(Views.AlwaysOnTopPage); break;

                    case "Awake": StartupPage = typeof(Views.AwakePage); break;

                    case "ColorPicker": StartupPage = typeof(Views.ColorPickerPage); break;

                    case "FancyZones": StartupPage = typeof(Views.FancyZonesPage); break;

                    case "Run": StartupPage = typeof(Views.PowerLauncherPage); break;

                    case "ImageResizer": StartupPage = typeof(Views.ImageResizerPage); break;

                    case "KBM": StartupPage = typeof(Views.KeyboardManagerPage); break;

                    case "MouseUtils": StartupPage = typeof(Views.MouseUtilsPage); break;

                    case "PowerRename": StartupPage = typeof(Views.PowerRenamePage); break;

                    case "FileExplorer": StartupPage = typeof(Views.PowerPreviewPage); break;

                    case "ShortcutGuide": StartupPage = typeof(Views.ShortcutGuidePage); break;

                    case "VideoConference": StartupPage = typeof(Views.VideoConferencePage); break;

                    default: Debug.Assert(false, "Unexpected SettingsWindow argument value"); break;
                    }
                }

                RunnerHelper.WaitForPowerToysRunner(PowerToysPID, () =>
                {
                    Environment.Exit(0);
                });

                ipcmanager = new TwoWayPipeMessageIPCManaged(cmdArgs[(int)Arguments.SettingsPipeName], cmdArgs[(int)Arguments.PTPipeName], (string message) =>
                {
                    if (IPCMessageReceivedCallback != null && message.Length > 0)
                    {
                        IPCMessageReceivedCallback(message);
                    }
                });
                ipcmanager.Start();

                settingsWindow = new MainWindow();
                if (!ShowOobe && !ShowScoobe)
                {
                    settingsWindow.Activate();
                    settingsWindow.NavigateToSection(StartupPage);
                }
                else
                {
                    // Create the Settings window so that it's fully initialized and
                    // it will be ready to receive the notification if the user opens
                    // the Settings from the tray icon.
                    if (ShowOobe)
                    {
                        PowerToysTelemetry.Log.WriteEvent(new OobeStartedEvent());
                        OobeWindow oobeWindow = new OobeWindow(OOBE.Enums.PowerToysModules.Overview);
                        oobeWindow.Activate();
                        SetOobeWindow(oobeWindow);
                    }
                    else if (ShowScoobe)
                    {
                        PowerToysTelemetry.Log.WriteEvent(new ScoobeStartedEvent());
                        OobeWindow scoobeWindow = new OobeWindow(OOBE.Enums.PowerToysModules.WhatsNew);
                        scoobeWindow.Activate();
                        SetOobeWindow(scoobeWindow);
                    }
                }
            }
            else
            {
                // For debugging purposes
                // Window is also needed to show MessageDialog
                settingsWindow = new MainWindow();
                settingsWindow.Activate();
                ShowMessageDialog("The application cannot be run as a standalone process. Please start the application through the runner.", "Forbidden");
            }
        }