public void RegisterHotkey() { Log.Info("RegisterHotkey()", GetType()); if (_settings != null && _settings.UsePowerToysRunnerKeyboardHook) { NativeEventWaiter.WaitForEventLoop(Constants.PowerLauncherSharedEvent(), OnHotkey); _hotkeyHandle = 0; } else { HotkeyManager = new HotkeyManager(); _settings.PropertyChanged += (s, e) => { if (e.PropertyName == nameof(PowerToysRunSettings.Hotkey)) { Application.Current.Dispatcher.Invoke(() => { if (!string.IsNullOrEmpty(_settings.PreviousHotkey)) { HotkeyManager.UnregisterHotkey(_hotkeyHandle); } if (!string.IsNullOrEmpty(_settings.Hotkey)) { SetHotkey(_settings.Hotkey, OnHotkey); } }); } }; SetHotkey(_settings.Hotkey, OnHotkey); SetCustomPluginHotkey(); } }
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)); } }
public MainViewModel( IMouseInfoProvider mouseInfoProvider, ZoomWindowHelper zoomWindowHelper, AppStateHandler appStateHandler, KeyboardMonitor keyboardMonitor, IUserSettings userSettings) { _zoomWindowHelper = zoomWindowHelper; _appStateHandler = appStateHandler; _userSettings = userSettings; NativeEventWaiter.WaitForEventLoop(Constants.ShowColorPickerSharedEvent(), _appStateHandler.StartUserSession); NativeEventWaiter.WaitForEventLoop(Constants.ColorPickerSendSettingsTelemetryEvent(), _userSettings.SendSettingsTelemetry); if (mouseInfoProvider != null) { mouseInfoProvider.MouseColorChanged += Mouse_ColorChanged; mouseInfoProvider.OnMouseDown += MouseInfoProvider_OnMouseDown; mouseInfoProvider.OnMouseWheel += MouseInfoProvider_OnMouseWheel; } _userSettings.ShowColorName.PropertyChanged += (s, e) => { OnPropertyChanged(nameof(ShowColorName)); }; // Only start a local keyboard low level hook if running as a standalone. // Otherwise, the global keyboard hook from runner will be used to activate Color Picker through ShowColorPickerSharedEvent // and the Escape key will be registered as a shortcut by appStateHandler when ColorPicker is being used. // This is much lighter than using a local low level keyboard hook. if ((System.Windows.Application.Current as ColorPickerUI.App).IsRunningDetachedFromPowerToys()) { keyboardMonitor?.Start(); } }
public MainViewModel(PowerToysRunSettings settings) { _saved = false; _queryTextBeforeLeaveResults = string.Empty; _currentQuery = _emptyQuery; _disposed = false; _settings = settings ?? throw new ArgumentNullException(nameof(settings)); _historyItemsStorage = new WoxJsonStorage <QueryHistory>(); _userSelectedRecordStorage = new WoxJsonStorage <UserSelectedRecord>(); _topMostRecordStorage = new WoxJsonStorage <TopMostRecord>(); _history = _historyItemsStorage.Load(); _userSelectedRecord = _userSelectedRecordStorage.Load(); _topMostRecord = _topMostRecordStorage.Load(); ContextMenu = new ResultsViewModel(_settings); Results = new ResultsViewModel(_settings); History = new ResultsViewModel(_settings); _selectedResults = Results; InitializeKeyCommands(); RegisterResultsUpdatedEvent(); if (settings != null && settings.UsePowerToysRunnerKeyboardHook) { NativeEventWaiter.WaitForEventLoop(Constants.PowerLauncherSharedEvent(), OnHotkey); _hotkeyHandle = 0; } else { HotkeyManager = new HotkeyManager(); _settings.PropertyChanged += (s, e) => { if (e.PropertyName == nameof(PowerToysRunSettings.Hotkey)) { Application.Current.Dispatcher.Invoke(() => { if (!string.IsNullOrEmpty(_settings.PreviousHotkey)) { HotkeyManager.UnregisterHotkey(_hotkeyHandle); } if (!string.IsNullOrEmpty(_settings.Hotkey)) { SetHotkey(_settings.Hotkey, OnHotkey); } }); } }; SetHotkey(_settings.Hotkey, OnHotkey); SetCustomPluginHotkey(); } }
public MainWindow(PowerToysRunSettings settings, MainViewModel mainVM) : this() { DataContext = mainVM; _viewModel = mainVM; _settings = settings; InitializeComponent(); _firstDeleteTimer.Elapsed += CheckForFirstDelete; _firstDeleteTimer.Interval = 1000; NativeEventWaiter.WaitForEventLoop(Constants.RunSendSettingsTelemetryEvent(), SendSettingsTelemetry); }
public void RegisterHotkey(IntPtr hwnd) { Log.Info("RegisterHotkey()", GetType()); // Allow OOBE to call PowerToys Run. NativeEventWaiter.WaitForEventLoop(Constants.PowerLauncherSharedEvent(), OnHotkey); if (_settings.StartedFromPowerToysRunner) { // Allow runner to call PowerToys Run from the centralized keyboard hook. NativeEventWaiter.WaitForEventLoop(Constants.PowerLauncherCentralizedHookSharedEvent(), OnCentralizedKeyboardHookHotKey); } _settings.PropertyChanged += (s, e) => { if (e.PropertyName == nameof(PowerToysRunSettings.Hotkey) || e.PropertyName == nameof(PowerToysRunSettings.UseCentralizedKeyboardHook)) { Application.Current.Dispatcher.Invoke(() => { if (!string.IsNullOrEmpty(_settings.PreviousHotkey)) { if (_usingGlobalHotKey) { NativeMethods.UnregisterHotKey(_globalHotKeyHwnd, _globalHotKeyId); _usingGlobalHotKey = false; Log.Info("Unregistering previous global hotkey", GetType()); } if (_hotkeyHandle != 0) { HotkeyManager?.UnregisterHotkey(_hotkeyHandle); _hotkeyHandle = 0; Log.Info("Unregistering previous low level key handler", GetType()); } } if (!string.IsNullOrEmpty(_settings.Hotkey)) { SetHotkey(hwnd, _settings.Hotkey, OnHotkey); } }); } }; SetHotkey(hwnd, _settings.Hotkey, OnHotkey); // TODO: Custom plugin hotkeys. // SetCustomPluginHotkey(); }
public MainViewModel( IMouseInfoProvider mouseInfoProvider, ZoomWindowHelper zoomWindowHelper, AppStateHandler appStateHandler, KeyboardMonitor keyboardMonitor, IUserSettings userSettings) { _zoomWindowHelper = zoomWindowHelper; _appStateHandler = appStateHandler; _userSettings = userSettings; NativeEventWaiter.WaitForEventLoop(Constants.ShowColorPickerSharedEvent(), _appStateHandler.StartUserSession); NativeEventWaiter.WaitForEventLoop(Constants.ColorPickerSendSettingsTelemetryEvent(), _userSettings.SendSettingsTelemetry); if (mouseInfoProvider != null) { mouseInfoProvider.MouseColorChanged += Mouse_ColorChanged; mouseInfoProvider.OnMouseDown += MouseInfoProvider_OnMouseDown; mouseInfoProvider.OnMouseWheel += MouseInfoProvider_OnMouseWheel; } _userSettings.ShowColorName.PropertyChanged += (s, e) => { OnPropertyChanged(nameof(ShowColorName)); }; keyboardMonitor?.Start(); }
public MainViewModel( IMouseInfoProvider mouseInfoProvider, ZoomWindowHelper zoomWindowHelper, AppStateHandler appStateHandler, KeyboardMonitor keyboardMonitor, NativeEventWaiter nativeEventWaiter, IUserSettings userSettings) { _zoomWindowHelper = zoomWindowHelper; _appStateHandler = appStateHandler; _userSettings = userSettings; _nativeEventWaiter = nativeEventWaiter; if (mouseInfoProvider != null) { mouseInfoProvider.MouseColorChanged += Mouse_ColorChanged; mouseInfoProvider.OnMouseDown += MouseInfoProvider_OnMouseDown; mouseInfoProvider.OnMouseWheel += MouseInfoProvider_OnMouseWheel; } _userSettings.ShowColorName.PropertyChanged += (s, e) => { OnPropertyChanged(nameof(ShowColorName)); }; keyboardMonitor?.Start(); }