Пример #1
0
 public static void SetOobeWindow(OobeWindow window)
 {
     oobeWindow = window;
 }
Пример #2
0
 public static void ClearOobeWindow()
 {
     oobeWindow = null;
 }
Пример #3
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");
            }
        }