Exemplo n.º 1
0
 private void Application_Startup(object sender, StartupEventArgs e)
 {
     if (!ShowOobe && !ShowScoobe)
     {
         settingsWindow = new MainWindow();
         settingsWindow.Show();
         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.
         InitHiddenSettingsWindow();
         if (ShowOobe)
         {
             PowerToysTelemetry.Log.WriteEvent(new OobeStartedEvent());
             OobeWindow oobeWindow = new OobeWindow(Microsoft.PowerToys.Settings.UI.OOBE.Enums.PowerToysModulesEnum.Overview);
             oobeWindow.Show();
         }
         else if (ShowScoobe)
         {
             PowerToysTelemetry.Log.WriteEvent(new ScoobeStartedEvent());
             OobeWindow scoobeWindow = new OobeWindow(Microsoft.PowerToys.Settings.UI.OOBE.Enums.PowerToysModulesEnum.WhatsNew);
             scoobeWindow.Show();
         }
     }
 }
Exemplo n.º 2
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            if (!ShowOobe)
            {
                settingsWindow = new MainWindow();
                settingsWindow.Show();
            }
            else
            {
                PowerToysTelemetry.Log.WriteEvent(new OobeStartedEvent());

                // 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.
                InitHiddenSettingsWindow();

                OobeWindow oobeWindow = new OobeWindow();
                oobeWindow.Show();
            }
        }
Exemplo n.º 3
0
        private void WindowsXamlHost_ChildChanged(object sender, EventArgs e)
        {
            // If sender is null, it could lead to a NullReferenceException. This might occur on restarting as admin (check https://github.com/microsoft/PowerToys/issues/7393 for details)
            if (sender == null)
            {
                return;
            }

            // Hook up x:Bind source.
            WindowsXamlHost windowsXamlHost = sender as WindowsXamlHost;
            ShellPage       shellPage       = windowsXamlHost.GetUwpInternalObject() as ShellPage;

            if (shellPage != null)
            {
                // send IPC Message
                ShellPage.SetDefaultSndMessageCallback(msg =>
                {
                    // IPC Manager is null when launching runner directly
                    Program.GetTwoWayIPCManager()?.Send(msg);
                });

                // send IPC Message
                ShellPage.SetRestartAdminSndMessageCallback(msg =>
                {
                    Program.GetTwoWayIPCManager().Send(msg);
                    isOpen = false;
                    System.Windows.Application.Current.Shutdown(); // close application
                });

                // send IPC Message
                ShellPage.SetCheckForUpdatesMessageCallback(msg =>
                {
                    Program.GetTwoWayIPCManager().Send(msg);
                });

                // open oobe
                ShellPage.SetOpenOobeCallback(() =>
                {
                    var oobe = new OobeWindow();
                    oobe.Show();
                });

                // receive IPC Message
                Program.IPCMessageReceivedCallback = (string msg) =>
                {
                    if (ShellPage.ShellHandler.IPCResponseHandleList != null)
                    {
                        var success = JsonObject.TryParse(msg, out JsonObject json);
                        if (success)
                        {
                            foreach (Action <JsonObject> handle in ShellPage.ShellHandler.IPCResponseHandleList)
                            {
                                handle(json);
                            }
                        }
                        else
                        {
                            Logger.LogError("Failed to parse JSON from IPC message.");
                        }
                    }
                };

                ShellPage.SetElevationStatus(Program.IsElevated);
                ShellPage.SetIsUserAnAdmin(Program.IsUserAnAdmin);
                shellPage.Refresh();
            }

            // XAML Islands: If the window is open, explicitly force it to be shown to solve the blank dialog issue https://github.com/microsoft/PowerToys/issues/3384
            if (isOpen)
            {
                try
                {
                    Show();
                }
                catch (InvalidOperationException)
                {
                }
            }
        }