/ src / settings-ui / Settings.UI / SettingsXAML / OOBE / Views / OobeRun.xaml.cs
OobeRun.xaml.cs
 1  // Copyright (c) Microsoft Corporation
 2  // The Microsoft Corporation licenses this file to you under the MIT license.
 3  // See the LICENSE file in the project root for more information.
 4  
 5  using System.Threading;
 6  
 7  using Microsoft.PowerToys.Settings.UI.Library;
 8  using Microsoft.PowerToys.Settings.UI.Library.Helpers;
 9  using Microsoft.PowerToys.Settings.UI.OOBE.Enums;
10  using Microsoft.PowerToys.Settings.UI.OOBE.ViewModel;
11  using Microsoft.PowerToys.Settings.UI.Views;
12  using Microsoft.UI.Xaml.Controls;
13  using Microsoft.UI.Xaml.Navigation;
14  
15  namespace Microsoft.PowerToys.Settings.UI.OOBE.Views
16  {
17      /// <summary>
18      /// An empty page that can be used on its own or navigated to within a Frame.
19      /// </summary>
20      public sealed partial class OobeRun : Page
21      {
22          public OobePowerToysModule ViewModel { get; set; }
23  
24          public OobeRun()
25          {
26              this.InitializeComponent();
27              ViewModel = new OobePowerToysModule(OobeShellPage.OobeShellHandler.Modules[(int)PowerToysModules.Run]);
28              DataContext = ViewModel;
29          }
30  
31          private void Start_Run_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
32          {
33              if (OobeShellPage.RunSharedEventCallback != null)
34              {
35                  using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, OobeShellPage.RunSharedEventCallback()))
36                  {
37                      eventHandle.Set();
38                  }
39              }
40  
41              ViewModel.LogRunningModuleEvent();
42          }
43  
44          private void SettingsLaunchButton_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
45          {
46              if (OobeShellPage.OpenMainWindowCallback != null)
47              {
48                  OobeShellPage.OpenMainWindowCallback(typeof(PowerLauncherPage));
49              }
50  
51              ViewModel.LogOpeningSettingsEvent();
52          }
53  
54          protected override void OnNavigatedTo(NavigationEventArgs e)
55          {
56              ViewModel.LogOpeningModuleEvent();
57  
58              HotkeyControl.Keys = SettingsRepository<PowerLauncherSettings>.GetInstance(SettingsUtils.Default).SettingsConfig.Properties.OpenPowerLauncher.GetKeysList();
59  
60              // Disable the Launch button if the module is disabled
61              var generalSettings = SettingsRepository<GeneralSettings>.GetInstance(SettingsUtils.Default).SettingsConfig;
62              LaunchButton.IsEnabled = ModuleHelper.GetIsModuleEnabled(generalSettings, ManagedCommon.ModuleType.PowerLauncher);
63          }
64  
65          protected override void OnNavigatedFrom(NavigationEventArgs e)
66          {
67              ViewModel.LogClosingModuleEvent();
68          }
69      }
70  }