public PowerLauncherViewModel(ISettingsUtils settingsUtils, ISettingsRepository <GeneralSettings> settingsRepository, Func <string, int> ipcMSGCallBackFunc, int defaultKeyCode) { _settingsUtils = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils)); // To obtain the general Settings configurations of PowerToys GeneralSettingsConfig = settingsRepository.SettingsConfig; // set the callback functions value to hangle outgoing IPC message. SendConfigMSG = ipcMSGCallBackFunc; callback = (PowerLauncherSettings settings) => { // Propagate changes to Power Launcher through IPC SendConfigMSG( string.Format("{{ \"powertoys\": {{ \"{0}\": {1} }} }}", PowerLauncherSettings.ModuleName, JsonSerializer.Serialize(settings))); }; if (_settingsUtils.SettingsExists(PowerLauncherSettings.ModuleName)) { settings = _settingsUtils.GetSettings <PowerLauncherSettings>(PowerLauncherSettings.ModuleName); } else { settings = new PowerLauncherSettings(); settings.Properties.OpenPowerLauncher.Alt = true; settings.Properties.OpenPowerLauncher.Code = defaultKeyCode; settings.Properties.MaximumNumberOfResults = 4; callback(settings); } }
public PowerLauncherViewModel(ISettingsUtils settingsUtils, ISettingsRepository <GeneralSettings> settingsRepository, Func <string, int> ipcMSGCallBackFunc, int defaultKeyCode, Func <bool> isDark) { _settingsUtils = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils)); this.isDark = isDark; // To obtain the general Settings configurations of PowerToys if (settingsRepository == null) { throw new ArgumentNullException(nameof(settingsRepository)); } GeneralSettingsConfig = settingsRepository.SettingsConfig; // set the callback functions value to hangle outgoing IPC message. SendConfigMSG = ipcMSGCallBackFunc; callback = (PowerLauncherSettings settings) => { // Propagate changes to Power Launcher through IPC // Using InvariantCulture as this is an IPC message SendConfigMSG( string.Format( CultureInfo.InvariantCulture, "{{ \"powertoys\": {{ \"{0}\": {1} }} }}", PowerLauncherSettings.ModuleName, JsonSerializer.Serialize(settings))); }; if (_settingsUtils.SettingsExists(PowerLauncherSettings.ModuleName)) { settings = _settingsUtils.GetSettingsOrDefault <PowerLauncherSettings>(PowerLauncherSettings.ModuleName); } else { settings = new PowerLauncherSettings(); settings.Properties.OpenPowerLauncher.Alt = true; settings.Properties.OpenPowerLauncher.Code = defaultKeyCode; settings.Properties.MaximumNumberOfResults = 4; callback(settings); } switch (settings.Properties.Theme) { case Theme.Light: _isLightThemeRadioButtonChecked = true; break; case Theme.Dark: _isDarkThemeRadioButtonChecked = true; break; case Theme.System: _isSystemThemeRadioButtonChecked = true; break; } foreach (var plugin in Plugins) { plugin.PropertyChanged += OnPluginInfoChange; } }
public void OriginalFilesModificationTest(string version, string fileName) { var mockIOProvider = BackCompatTestProperties.GetModuleIOProvider(version, PowerLauncherSettings.ModuleName, fileName); var mockSettingsUtils = new SettingsUtils(mockIOProvider.Object); PowerLauncherSettings originalSettings = mockSettingsUtils.GetSettings <PowerLauncherSettings>(PowerLauncherSettings.ModuleName); var mockGeneralIOProvider = BackCompatTestProperties.GetGeneralSettingsIOProvider(version); var mockGeneralSettingsUtils = new SettingsUtils(mockGeneralIOProvider.Object); GeneralSettings originalGeneralSettings = mockGeneralSettingsUtils.GetSettings <GeneralSettings>(); var generalSettingsRepository = new BackCompatTestProperties.MockSettingsRepository <GeneralSettings>(mockGeneralSettingsUtils); // Initialise View Model with test Config files Func <string, int> SendMockIPCConfigMSG = msg => { return(0); }; PowerLauncherViewModel viewModel = new PowerLauncherViewModel(mockSettingsUtils, generalSettingsRepository, SendMockIPCConfigMSG, 32); // Verifiy that the old settings persisted Assert.AreEqual(originalGeneralSettings.Enabled.PowerLauncher, viewModel.EnablePowerLauncher); Assert.AreEqual(originalSettings.Properties.ClearInputOnLaunch, viewModel.ClearInputOnLaunch); Assert.AreEqual(originalSettings.Properties.CopyPathLocation.ToString(), viewModel.CopyPathLocation.ToString()); Assert.AreEqual(originalSettings.Properties.DisableDriveDetectionWarning, viewModel.DisableDriveDetectionWarning); Assert.AreEqual(originalSettings.Properties.IgnoreHotkeysInFullscreen, viewModel.IgnoreHotkeysInFullScreen); Assert.AreEqual(originalSettings.Properties.MaximumNumberOfResults, viewModel.MaximumNumberOfResults); Assert.AreEqual(originalSettings.Properties.OpenPowerLauncher.ToString(), viewModel.OpenPowerLauncher.ToString()); Assert.AreEqual(originalSettings.Properties.OverrideWinkeyR, viewModel.OverrideWinRKey); Assert.AreEqual(originalSettings.Properties.OverrideWinkeyS, viewModel.OverrideWinSKey); Assert.AreEqual(originalSettings.Properties.SearchResultPreference, viewModel.SearchResultPreference); Assert.AreEqual(originalSettings.Properties.SearchTypePreference, viewModel.SearchTypePreference); //Verify that the stub file was used var expectedCallCount = 2; //once via the view model, and once by the test (GetSettings<T>) BackCompatTestProperties.VerifyModuleIOProviderWasRead(mockIOProvider, PowerLauncherSettings.ModuleName, expectedCallCount); BackCompatTestProperties.VerifyGeneralSettingsIOProviderWasRead(mockGeneralIOProvider, expectedCallCount); }
public PowerLauncherViewModel(Func <string, int> ipcMSGCallBackFunc, int defaultKeyCode) { // set the callback functions value to hangle outgoing IPC message. SendConfigMSG = ipcMSGCallBackFunc; callback = (PowerLauncherSettings settings) => { // Propagate changes to Power Launcher through IPC SendConfigMSG( string.Format("{{ \"powertoys\": {{ \"{0}\": {1} }} }}", PowerLauncherSettings.ModuleName, JsonSerializer.Serialize(settings))); }; if (SettingsUtils.SettingsExists(PowerLauncherSettings.ModuleName)) { settings = SettingsUtils.GetSettings <PowerLauncherSettings>(PowerLauncherSettings.ModuleName); } else { settings = new PowerLauncherSettings(); settings.Properties.OpenPowerLauncher.Alt = true; settings.Properties.OpenPowerLauncher.Code = defaultKeyCode; settings.Properties.MaximumNumberOfResults = 4; callback(settings); } if (SettingsUtils.SettingsExists()) { generalSettings = SettingsUtils.GetSettings <GeneralSettings>(); } else { generalSettings = new GeneralSettings(); } }
public PowerLauncherViewModel() { callback = (PowerLauncherSettings settings) => { // Propagate changes to Power Launcher through IPC ShellPage.DefaultSndMSGCallback( string.Format("{{ \"powertoys\": {{ \"{0}\": {1} }} }}", PowerLauncherSettings.POWERTOYNAME, JsonSerializer.Serialize(settings))); }; if (SettingsUtils.SettingsExists(PowerLauncherSettings.POWERTOYNAME)) { settings = SettingsUtils.GetSettings <PowerLauncherSettings>(PowerLauncherSettings.POWERTOYNAME); } else { settings = new PowerLauncherSettings(); settings.properties.open_powerlauncher.Alt = true; settings.properties.open_powerlauncher.Code = (int)Windows.System.VirtualKey.Space; settings.properties.maximum_number_of_results = 4; callback(settings); } if (SettingsUtils.SettingsExists()) { generalSettings = SettingsUtils.GetSettings <GeneralSettings>(); } else { generalSettings = new GeneralSettings(); } }
public void Initialize() { mockSettings = new PowerLauncherSettings(); sendCallbackMock = new SendCallbackMock(); viewModel = new PowerLauncherViewModel( mockSettings, new PowerLauncherViewModel.SendCallback(sendCallbackMock.OnSend)); }
public static void CreateSettingsIfNotExists() { if (!SettingsUtils.SettingsExists(PowerLauncherSettings.ModuleName)) { Log.Info("|SettingsWatcher.OverloadSettings|PT Run settings.json was missing, creating a new one"); var defaultSettings = new PowerLauncherSettings(); defaultSettings.Save(); } }
public void CreateSettingsIfNotExists() { if (!_settingsUtils.SettingsExists(PowerLauncherSettings.ModuleName)) { Log.Info("PT Run settings.json was missing, creating a new one", GetType()); var defaultSettings = new PowerLauncherSettings(); defaultSettings.Save(_settingsUtils); } }
public PowerLauncherPage() { InitializeComponent(); var settingsUtils = new SettingsUtils(); _lastIPCMessageSentTick = Environment.TickCount; PowerLauncherSettings settings = settingsUtils.GetSettingsOrDefault <PowerLauncherSettings>(PowerLauncherSettings.ModuleName); ViewModel = new PowerLauncherViewModel(settings, SettingsRepository <GeneralSettings> .GetInstance(settingsUtils), SendDefaultIPCMessageTimed, App.IsDarkTheme); DataContext = ViewModel; _ = Helper.GetFileWatcher(PowerLauncherSettings.ModuleName, "settings.json", () => { if (Environment.TickCount < _lastIPCMessageSentTick + 500) { // Don't try to update data from the file if we tried to write to it through IPC in the last 500 milliseconds. return; } PowerLauncherSettings powerLauncherSettings = null; try { powerLauncherSettings = settingsUtils.GetSettingsOrDefault <PowerLauncherSettings>(PowerLauncherSettings.ModuleName); } catch (IOException ex) { Logger.LogInfo(ex.Message); } if (powerLauncherSettings != null && !ViewModel.IsUpToDate(powerLauncherSettings)) { _ = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { DataContext = ViewModel = new PowerLauncherViewModel(powerLauncherSettings, SettingsRepository <GeneralSettings> .GetInstance(settingsUtils), ShellPage.SendDefaultIPCMessage, App.IsDarkTheme); this.Bindings.Update(); }); } }); var loader = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView(); searchResultPreferencesOptions = new ObservableCollection <Tuple <string, string> >(); searchResultPreferencesOptions.Add(Tuple.Create(loader.GetString("PowerLauncher_SearchResultPreference_AlphabeticalOrder"), "alphabetical_order")); searchResultPreferencesOptions.Add(Tuple.Create(loader.GetString("PowerLauncher_SearchResultPreference_MostRecentlyUsed"), "most_recently_used")); searchResultPreferencesOptions.Add(Tuple.Create(loader.GetString("PowerLauncher_SearchResultPreference_RunningProcessesOpenApplications"), "running_processes_open_applications")); searchTypePreferencesOptions = new ObservableCollection <Tuple <string, string> >(); searchTypePreferencesOptions.Add(Tuple.Create(loader.GetString("PowerLauncher_SearchTypePreference_ApplicationName"), "application_name")); searchTypePreferencesOptions.Add(Tuple.Create(loader.GetString("PowerLauncher_SearchTypePreference_StringInApplication"), "string_in_application")); searchTypePreferencesOptions.Add(Tuple.Create(loader.GetString("PowerLauncher_SearchTypePreference_ExecutableName"), "executable_name")); }
/// <summary> /// Add new plugins and updates additional options for existing ones /// </summary> private static void UpdateSettings(PowerLauncherSettings settings) { var defaultPlugins = GetDefaultPluginsSettings().ToDictionary(x => x.Id); foreach (PowerLauncherPluginSettings plugin in settings.Plugins) { if (defaultPlugins.ContainsKey(plugin.Id)) { var additionalOptions = CombineAdditionalOptions(defaultPlugins[plugin.Id].AdditionalOptions, plugin.AdditionalOptions); plugin.Name = defaultPlugins[plugin.Id].Name; plugin.Description = defaultPlugins[plugin.Id].Description; defaultPlugins[plugin.Id] = plugin; defaultPlugins[plugin.Id].AdditionalOptions = additionalOptions; } } settings.Plugins = defaultPlugins.Values.ToList(); }
public PowerLauncherPage() { InitializeComponent(); var settingsUtils = new SettingsUtils(); PowerLauncherSettings settings = settingsUtils.GetSettingsOrDefault <PowerLauncherSettings>(PowerLauncherSettings.ModuleName); ViewModel = new PowerLauncherViewModel(settings, SettingsRepository <GeneralSettings> .GetInstance(settingsUtils), ShellPage.SendDefaultIPCMessage, App.IsDarkTheme); DataContext = ViewModel; _ = Helper.GetFileWatcher(PowerLauncherSettings.ModuleName, "settings.json", () => { _ = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { PowerLauncherSettings powerLauncherSettings = null; try { powerLauncherSettings = settingsUtils.GetSettingsOrDefault <PowerLauncherSettings>(PowerLauncherSettings.ModuleName); } catch (IOException ex) { Logger.LogInfo(ex.Message); } if (powerLauncherSettings != null) { DataContext = ViewModel = new PowerLauncherViewModel(powerLauncherSettings, SettingsRepository <GeneralSettings> .GetInstance(settingsUtils), ShellPage.SendDefaultIPCMessage, App.IsDarkTheme); this.Bindings.Update(); } }); }); var loader = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView(); searchResultPreferencesOptions = new ObservableCollection <Tuple <string, string> >(); searchResultPreferencesOptions.Add(Tuple.Create(loader.GetString("PowerLauncher_SearchResultPreference_AlphabeticalOrder"), "alphabetical_order")); searchResultPreferencesOptions.Add(Tuple.Create(loader.GetString("PowerLauncher_SearchResultPreference_MostRecentlyUsed"), "most_recently_used")); searchResultPreferencesOptions.Add(Tuple.Create(loader.GetString("PowerLauncher_SearchResultPreference_RunningProcessesOpenApplications"), "running_processes_open_applications")); searchTypePreferencesOptions = new ObservableCollection <Tuple <string, string> >(); searchTypePreferencesOptions.Add(Tuple.Create(loader.GetString("PowerLauncher_SearchTypePreference_ApplicationName"), "application_name")); searchTypePreferencesOptions.Add(Tuple.Create(loader.GetString("PowerLauncher_SearchTypePreference_StringInApplication"), "string_in_application")); searchTypePreferencesOptions.Add(Tuple.Create(loader.GetString("PowerLauncher_SearchTypePreference_ExecutableName"), "executable_name")); }
public PowerLauncherViewModel(PowerLauncherSettings settings, SendCallback callback) { this.settings = settings; this.callback = callback; }
public void UpdateSettings(PowerLauncherSettings settings) { _settings.MaxSearchCount = settings.Properties.MaximumNumberOfResults; _driveDetection.IsDriveDetectionWarningCheckBoxSelected = settings.Properties.DisableDriveDetectionWarning; }
public void UpdateSettings(PowerLauncherSettings settings) { _settings.MaxSearchCount = settings.properties.maximum_number_of_results; }
public PowerLauncherViewModel(PowerLauncherSettings settings, ISettingsRepository <GeneralSettings> settingsRepository, Func <string, int> ipcMSGCallBackFunc, Func <bool> isDark) { if (settings == null) { throw new ArgumentException("settings argument can not be null"); } this.settings = settings; this.isDark = isDark; // To obtain the general Settings configurations of PowerToys if (settingsRepository == null) { throw new ArgumentNullException(nameof(settingsRepository)); } GeneralSettingsConfig = settingsRepository.SettingsConfig; // set the callback functions value to hangle outgoing IPC message. SendConfigMSG = ipcMSGCallBackFunc; callback = (PowerLauncherSettings s) => { // Propagate changes to Power Launcher through IPC // Using InvariantCulture as this is an IPC message SendConfigMSG( string.Format( CultureInfo.InvariantCulture, "{{ \"powertoys\": {{ \"{0}\": {1} }} }}", PowerLauncherSettings.ModuleName, JsonSerializer.Serialize(s))); }; switch (settings.Properties.Theme) { case Theme.Dark: _themeIndex = 0; break; case Theme.Light: _themeIndex = 1; break; case Theme.System: _themeIndex = 2; break; } switch (settings.Properties.Position) { case StartupPosition.Cursor: _monitorPositionIndex = 0; break; case StartupPosition.PrimaryMonitor: _monitorPositionIndex = 1; break; case StartupPosition.Focus: _monitorPositionIndex = 2; break; } foreach (var plugin in Plugins) { plugin.PropertyChanged += OnPluginInfoChange; } SearchPluginsCommand = new RelayCommand(SearchPlugins); }
public void UpdateSettings(PowerLauncherSettings settings) { _driveDetection.IsDriveDetectionWarningCheckBoxSelected = settings.Properties.DisableDriveDetectionWarning; }
public void UpdateSettings(PowerLauncherSettings settings) { _settings.MaxSearchCount = settings.Properties.maximum_number_of_results; _driveDetection.IsDriveDetectionWarningCheckBoxSelected = settings.Properties.disable_drive_detection_warning; }
public void OnSend(PowerLauncherSettings settings) { TimesSent++; }
public static void UpdateSettings(PowerLauncherSettings _) { }
public void OverloadSettings() { Monitor.Enter(_watcherSyncObject); var retry = true; var retryCount = 0; while (retry) { try { retryCount++; if (!SettingsUtils.SettingsExists(PowerLauncherSettings.ModuleName)) { Debug.WriteLine("PT Run settings.json was missing, creating a new one"); var defaultSettings = new PowerLauncherSettings(); defaultSettings.Save(); } var overloadSettings = SettingsUtils.GetSettings <PowerLauncherSettings>(PowerLauncherSettings.ModuleName); var openPowerlauncher = ConvertHotkey(overloadSettings.Properties.OpenPowerLauncher); if (_settings.Hotkey != openPowerlauncher) { _settings.Hotkey = openPowerlauncher; } var shell = PluginManager.AllPlugins.Find(pp => pp.Metadata.Name == "Shell"); if (shell != null) { var shellSettings = shell.Plugin as ISettingProvider; shellSettings.UpdateSettings(overloadSettings); } if (_settings.MaxResultsToShow != overloadSettings.Properties.MaximumNumberOfResults) { _settings.MaxResultsToShow = overloadSettings.Properties.MaximumNumberOfResults; } if (_settings.IgnoreHotkeysOnFullscreen != overloadSettings.Properties.IgnoreHotkeysInFullscreen) { _settings.IgnoreHotkeysOnFullscreen = overloadSettings.Properties.IgnoreHotkeysInFullscreen; } var indexer = PluginManager.AllPlugins.Find(p => p.Metadata.Name.Equals("Windows Indexer Plugin", StringComparison.OrdinalIgnoreCase)); if (indexer != null) { var indexerSettings = indexer.Plugin as ISettingProvider; indexerSettings.UpdateSettings(overloadSettings); } if (_settings.ClearInputOnLaunch != overloadSettings.Properties.ClearInputOnLaunch) { _settings.ClearInputOnLaunch = overloadSettings.Properties.ClearInputOnLaunch; } retry = false; } // the settings application can hold a lock on the settings.json file which will result in a IOException. // This should be changed to properly synch with the settings app instead of retrying. catch (IOException e) { if (retryCount > _maxRetries) { retry = false; } Thread.Sleep(1000); Debug.WriteLine(e.Message); } } Monitor.Exit(_watcherSyncObject); }
public void UpdateSettings(PowerLauncherSettings settings) { }
public void UpdateSettings(PowerLauncherSettings settings) { //_settings.ReplaceWinR = settings.properties.override_win_r_key; }