Beispiel #1
0
        public void Initialize()
        {
            // Make sure we don't crash
            Assert.IsTrue(CommonManaged.ShouldNewSettingsBeUsed() == CommonManaged.ShouldNewSettingsBeUsed());

            ClientPipe = new TwoWayPipeMessageIPCManaged(ClientSidePipe, ServerSidePipe, null);
        }
Beispiel #2
0
        public void TestSend()
        {
            var testString = "This string is a test\n";

            using (var reset = new AutoResetEvent(false))
            {
                using (var serverPipe = new TwoWayPipeMessageIPCManaged(
                           ServerSidePipe,
                           ClientSidePipe,
                           (string msg) =>
                {
                    Assert.AreEqual(testString, msg);
                    reset.Set();
                }))
                {
                    serverPipe.Start();
                    ClientPipe.Start();

                    ClientPipe.Send(testString);
                    reset.WaitOne();

                    serverPipe.End();
                }
            }
        }
Beispiel #3
0
        public static void Main(string[] args)
        {
            using (new UI.App())
            {
                App app = new App();
                app.InitializeComponent();

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

                    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();
                }
            }
        }
Beispiel #4
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();
                }
            }
        }
Beispiel #5
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);
            }
        }
Beispiel #6
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();
                }
            }
        }
        public void TestSend()
        {
            var testString = "This string is a test\n";
            var reset      = new AutoResetEvent(false);

            var serverPipe = new TwoWayPipeMessageIPCManaged(
                SERVER_SIDE,
                CLIENT_SIDE,
                (string msg) =>
            {
                Assert.AreEqual(testString, msg);
                reset.Set();
            });

            serverPipe.Start();
            clientPipe.Start();

            clientPipe.Send(testString);
            reset.WaitOne();

            serverPipe.End();
        }
Beispiel #8
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();
                }
            }
        }
Beispiel #9
0
 public void Initialize()
 {
     ClientPipe = new TwoWayPipeMessageIPCManaged(ClientSidePipe, ServerSidePipe, null);
 }
 public void Initialize()
 {
     clientPipe = new TwoWayPipeMessageIPCManaged(CLIENT_SIDE, SERVER_SIDE, null);
 }
Beispiel #11
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");
            }
        }