PowerToys/src/core/Microsoft.PowerToys.Settings.UI.Lib/ViewModels/PowerLauncherViewModel.cs

289 lines
8.3 KiB
C#
Raw Normal View History

2020-08-17 19:00:56 +02:00
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Globalization;
2020-08-17 19:00:56 +02:00
using System.Runtime.CompilerServices;
using System.Text.Json;
using Microsoft.PowerToys.Settings.UI.Lib.Helpers;
Fix for settings crash on toggling enable button for any PowerToy (#6620) * Removed getSettings from moduleEnabled so that it doesn't have to reopen the file everytime * To Lower to while checking the theme * color picker doesn't reopen the file * use the generalView model config directly for FZ * Made the same change for all the viewmodels so that they access the general view model value directly instead of opening and reading the value from a file each time * removed unused variable * Fix initialization in tests * should read the file only if general settings does not exist * Added interfaces for all the powertoys to use the generalSettings singleton class * Runner is responding to changes in settings, only issue is that every time the general settings page is loaded the information is being read because isInitialized property could not be ignored during serialization * All tests pass * Settings and runner are working as expected with the settings cache * added a null check to read from the file only when the settings process is started * use converter to deserialize an interface * Renamed generalSettings within the cache to be called CommonSettingsConfig * All tests pass, had to initialize the common settings config instance * Added few comments to newly created classes * encapsulating load and store of general view model * reading from file is encapsulated * settings and runner wotk with generic singleton * Shortcut guide works as expected * Fancyzones, shortcutguide and power preview use the settings repository and work as expected * referencing GeneralSettings instead of the settingsRepository<GeneralSettings> within viewmodels * unified access to General settings and removed the IGeneralSettingsData interface * Passing settings to viewmodel as a parameter * removed ISettingsConfig interface from the viewmodels which are not using the singleton to access settings * have to use ISettingsConfig to use GetSettings * refactored tests, all tests pass * Added test for settingsRepository that a single instance is created * Added comments and removed unnecessary headers/code * added settings repository tests * moq for each settings file * Img resizer tests pass * General tests pass * FancyZones tests pass * PowerPreview tests pass * PowerRename tests pass * shortcut guide tests pass * Added GetModuleName to ISettingsConfig * unify the way the Modulename is accessed. It was redeclared in multiple places and this would cause an issue if the name is changed only in one place. All the module names are accessed using the <T>Settings.ModuleName, eg: ShortcutGuideSettings.ModuleName. * create PTRun settings file if it does not exist * GetFile is now a private function. Modified the logic of KBM default.json access and PT Run so that we can re-use GetSettings instead of GetFile. * Added UpgradeSettingsConfiguration to the ISettingsConfig interface so that the settings file can be upgraded based on some condition. Presently, only the GeneralSettings file is utilizing this to change the PT Version number based on the old PT version and the current PT version that it receives from the helper function. Verified that if the PT version is lower in the general settings.json file, settings saves the file with the new version info. * The naming for the PowerToys was inconsistent and the variables were redeclared in multiple places. To have the settings.ModuleName as the main name, all other places should refer to that name. In the tests file the module name for ImgResizer was 'ImageResizer' and not 'Image Resizer'. * renamed lock * Remove unnecessary GetSettingsFileNAme function. It is no longer in use because the code does not use types to create a new BasePTModule object
2020-09-23 22:20:32 +02:00
using Microsoft.PowerToys.Settings.UI.Lib.Interface;
2020-08-17 19:00:56 +02:00
namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
2020-08-17 19:00:56 +02:00
{
public class PowerLauncherViewModel : Observable
{
Fix for settings crash on toggling enable button for any PowerToy (#6620) * Removed getSettings from moduleEnabled so that it doesn't have to reopen the file everytime * To Lower to while checking the theme * color picker doesn't reopen the file * use the generalView model config directly for FZ * Made the same change for all the viewmodels so that they access the general view model value directly instead of opening and reading the value from a file each time * removed unused variable * Fix initialization in tests * should read the file only if general settings does not exist * Added interfaces for all the powertoys to use the generalSettings singleton class * Runner is responding to changes in settings, only issue is that every time the general settings page is loaded the information is being read because isInitialized property could not be ignored during serialization * All tests pass * Settings and runner are working as expected with the settings cache * added a null check to read from the file only when the settings process is started * use converter to deserialize an interface * Renamed generalSettings within the cache to be called CommonSettingsConfig * All tests pass, had to initialize the common settings config instance * Added few comments to newly created classes * encapsulating load and store of general view model * reading from file is encapsulated * settings and runner wotk with generic singleton * Shortcut guide works as expected * Fancyzones, shortcutguide and power preview use the settings repository and work as expected * referencing GeneralSettings instead of the settingsRepository<GeneralSettings> within viewmodels * unified access to General settings and removed the IGeneralSettingsData interface * Passing settings to viewmodel as a parameter * removed ISettingsConfig interface from the viewmodels which are not using the singleton to access settings * have to use ISettingsConfig to use GetSettings * refactored tests, all tests pass * Added test for settingsRepository that a single instance is created * Added comments and removed unnecessary headers/code * added settings repository tests * moq for each settings file * Img resizer tests pass * General tests pass * FancyZones tests pass * PowerPreview tests pass * PowerRename tests pass * shortcut guide tests pass * Added GetModuleName to ISettingsConfig * unify the way the Modulename is accessed. It was redeclared in multiple places and this would cause an issue if the name is changed only in one place. All the module names are accessed using the <T>Settings.ModuleName, eg: ShortcutGuideSettings.ModuleName. * create PTRun settings file if it does not exist * GetFile is now a private function. Modified the logic of KBM default.json access and PT Run so that we can re-use GetSettings instead of GetFile. * Added UpgradeSettingsConfiguration to the ISettingsConfig interface so that the settings file can be upgraded based on some condition. Presently, only the GeneralSettings file is utilizing this to change the PT Version number based on the old PT version and the current PT version that it receives from the helper function. Verified that if the PT version is lower in the general settings.json file, settings saves the file with the new version info. * The naming for the PowerToys was inconsistent and the variables were redeclared in multiple places. To have the settings.ModuleName as the main name, all other places should refer to that name. In the tests file the module name for ImgResizer was 'ImageResizer' and not 'Image Resizer'. * renamed lock * Remove unnecessary GetSettingsFileNAme function. It is no longer in use because the code does not use types to create a new BasePTModule object
2020-09-23 22:20:32 +02:00
private GeneralSettings GeneralSettingsConfig { get; set; }
private readonly ISettingsUtils _settingsUtils;
2020-08-17 19:00:56 +02:00
private PowerLauncherSettings settings;
public delegate void SendCallback(PowerLauncherSettings settings);
private readonly SendCallback callback;
private Func<string, int> SendConfigMSG { get; }
Fix for settings crash on toggling enable button for any PowerToy (#6620) * Removed getSettings from moduleEnabled so that it doesn't have to reopen the file everytime * To Lower to while checking the theme * color picker doesn't reopen the file * use the generalView model config directly for FZ * Made the same change for all the viewmodels so that they access the general view model value directly instead of opening and reading the value from a file each time * removed unused variable * Fix initialization in tests * should read the file only if general settings does not exist * Added interfaces for all the powertoys to use the generalSettings singleton class * Runner is responding to changes in settings, only issue is that every time the general settings page is loaded the information is being read because isInitialized property could not be ignored during serialization * All tests pass * Settings and runner are working as expected with the settings cache * added a null check to read from the file only when the settings process is started * use converter to deserialize an interface * Renamed generalSettings within the cache to be called CommonSettingsConfig * All tests pass, had to initialize the common settings config instance * Added few comments to newly created classes * encapsulating load and store of general view model * reading from file is encapsulated * settings and runner wotk with generic singleton * Shortcut guide works as expected * Fancyzones, shortcutguide and power preview use the settings repository and work as expected * referencing GeneralSettings instead of the settingsRepository<GeneralSettings> within viewmodels * unified access to General settings and removed the IGeneralSettingsData interface * Passing settings to viewmodel as a parameter * removed ISettingsConfig interface from the viewmodels which are not using the singleton to access settings * have to use ISettingsConfig to use GetSettings * refactored tests, all tests pass * Added test for settingsRepository that a single instance is created * Added comments and removed unnecessary headers/code * added settings repository tests * moq for each settings file * Img resizer tests pass * General tests pass * FancyZones tests pass * PowerPreview tests pass * PowerRename tests pass * shortcut guide tests pass * Added GetModuleName to ISettingsConfig * unify the way the Modulename is accessed. It was redeclared in multiple places and this would cause an issue if the name is changed only in one place. All the module names are accessed using the <T>Settings.ModuleName, eg: ShortcutGuideSettings.ModuleName. * create PTRun settings file if it does not exist * GetFile is now a private function. Modified the logic of KBM default.json access and PT Run so that we can re-use GetSettings instead of GetFile. * Added UpgradeSettingsConfiguration to the ISettingsConfig interface so that the settings file can be upgraded based on some condition. Presently, only the GeneralSettings file is utilizing this to change the PT Version number based on the old PT version and the current PT version that it receives from the helper function. Verified that if the PT version is lower in the general settings.json file, settings saves the file with the new version info. * The naming for the PowerToys was inconsistent and the variables were redeclared in multiple places. To have the settings.ModuleName as the main name, all other places should refer to that name. In the tests file the module name for ImgResizer was 'ImageResizer' and not 'Image Resizer'. * renamed lock * Remove unnecessary GetSettingsFileNAme function. It is no longer in use because the code does not use types to create a new BasePTModule object
2020-09-23 22:20:32 +02:00
public PowerLauncherViewModel(ISettingsUtils settingsUtils, ISettingsRepository<GeneralSettings> settingsRepository, Func<string, int> ipcMSGCallBackFunc, int defaultKeyCode)
2020-08-17 19:00:56 +02:00
{
_settingsUtils = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils));
Fix for settings crash on toggling enable button for any PowerToy (#6620) * Removed getSettings from moduleEnabled so that it doesn't have to reopen the file everytime * To Lower to while checking the theme * color picker doesn't reopen the file * use the generalView model config directly for FZ * Made the same change for all the viewmodels so that they access the general view model value directly instead of opening and reading the value from a file each time * removed unused variable * Fix initialization in tests * should read the file only if general settings does not exist * Added interfaces for all the powertoys to use the generalSettings singleton class * Runner is responding to changes in settings, only issue is that every time the general settings page is loaded the information is being read because isInitialized property could not be ignored during serialization * All tests pass * Settings and runner are working as expected with the settings cache * added a null check to read from the file only when the settings process is started * use converter to deserialize an interface * Renamed generalSettings within the cache to be called CommonSettingsConfig * All tests pass, had to initialize the common settings config instance * Added few comments to newly created classes * encapsulating load and store of general view model * reading from file is encapsulated * settings and runner wotk with generic singleton * Shortcut guide works as expected * Fancyzones, shortcutguide and power preview use the settings repository and work as expected * referencing GeneralSettings instead of the settingsRepository<GeneralSettings> within viewmodels * unified access to General settings and removed the IGeneralSettingsData interface * Passing settings to viewmodel as a parameter * removed ISettingsConfig interface from the viewmodels which are not using the singleton to access settings * have to use ISettingsConfig to use GetSettings * refactored tests, all tests pass * Added test for settingsRepository that a single instance is created * Added comments and removed unnecessary headers/code * added settings repository tests * moq for each settings file * Img resizer tests pass * General tests pass * FancyZones tests pass * PowerPreview tests pass * PowerRename tests pass * shortcut guide tests pass * Added GetModuleName to ISettingsConfig * unify the way the Modulename is accessed. It was redeclared in multiple places and this would cause an issue if the name is changed only in one place. All the module names are accessed using the <T>Settings.ModuleName, eg: ShortcutGuideSettings.ModuleName. * create PTRun settings file if it does not exist * GetFile is now a private function. Modified the logic of KBM default.json access and PT Run so that we can re-use GetSettings instead of GetFile. * Added UpgradeSettingsConfiguration to the ISettingsConfig interface so that the settings file can be upgraded based on some condition. Presently, only the GeneralSettings file is utilizing this to change the PT Version number based on the old PT version and the current PT version that it receives from the helper function. Verified that if the PT version is lower in the general settings.json file, settings saves the file with the new version info. * The naming for the PowerToys was inconsistent and the variables were redeclared in multiple places. To have the settings.ModuleName as the main name, all other places should refer to that name. In the tests file the module name for ImgResizer was 'ImageResizer' and not 'Image Resizer'. * renamed lock * Remove unnecessary GetSettingsFileNAme function. It is no longer in use because the code does not use types to create a new BasePTModule object
2020-09-23 22:20:32 +02:00
// To obtain the general Settings configurations of PowerToys
if (settingsRepository == null)
{
throw new ArgumentNullException(nameof(settingsRepository));
}
Fix for settings crash on toggling enable button for any PowerToy (#6620) * Removed getSettings from moduleEnabled so that it doesn't have to reopen the file everytime * To Lower to while checking the theme * color picker doesn't reopen the file * use the generalView model config directly for FZ * Made the same change for all the viewmodels so that they access the general view model value directly instead of opening and reading the value from a file each time * removed unused variable * Fix initialization in tests * should read the file only if general settings does not exist * Added interfaces for all the powertoys to use the generalSettings singleton class * Runner is responding to changes in settings, only issue is that every time the general settings page is loaded the information is being read because isInitialized property could not be ignored during serialization * All tests pass * Settings and runner are working as expected with the settings cache * added a null check to read from the file only when the settings process is started * use converter to deserialize an interface * Renamed generalSettings within the cache to be called CommonSettingsConfig * All tests pass, had to initialize the common settings config instance * Added few comments to newly created classes * encapsulating load and store of general view model * reading from file is encapsulated * settings and runner wotk with generic singleton * Shortcut guide works as expected * Fancyzones, shortcutguide and power preview use the settings repository and work as expected * referencing GeneralSettings instead of the settingsRepository<GeneralSettings> within viewmodels * unified access to General settings and removed the IGeneralSettingsData interface * Passing settings to viewmodel as a parameter * removed ISettingsConfig interface from the viewmodels which are not using the singleton to access settings * have to use ISettingsConfig to use GetSettings * refactored tests, all tests pass * Added test for settingsRepository that a single instance is created * Added comments and removed unnecessary headers/code * added settings repository tests * moq for each settings file * Img resizer tests pass * General tests pass * FancyZones tests pass * PowerPreview tests pass * PowerRename tests pass * shortcut guide tests pass * Added GetModuleName to ISettingsConfig * unify the way the Modulename is accessed. It was redeclared in multiple places and this would cause an issue if the name is changed only in one place. All the module names are accessed using the <T>Settings.ModuleName, eg: ShortcutGuideSettings.ModuleName. * create PTRun settings file if it does not exist * GetFile is now a private function. Modified the logic of KBM default.json access and PT Run so that we can re-use GetSettings instead of GetFile. * Added UpgradeSettingsConfiguration to the ISettingsConfig interface so that the settings file can be upgraded based on some condition. Presently, only the GeneralSettings file is utilizing this to change the PT Version number based on the old PT version and the current PT version that it receives from the helper function. Verified that if the PT version is lower in the general settings.json file, settings saves the file with the new version info. * The naming for the PowerToys was inconsistent and the variables were redeclared in multiple places. To have the settings.ModuleName as the main name, all other places should refer to that name. In the tests file the module name for ImgResizer was 'ImageResizer' and not 'Image Resizer'. * renamed lock * Remove unnecessary GetSettingsFileNAme function. It is no longer in use because the code does not use types to create a new BasePTModule object
2020-09-23 22:20:32 +02:00
GeneralSettingsConfig = settingsRepository.SettingsConfig;
2020-09-10 18:44:10 +02:00
// set the callback functions value to hangle outgoing IPC message.
SendConfigMSG = ipcMSGCallBackFunc;
callback = (PowerLauncherSettings settings) =>
2020-08-17 19:00:56 +02:00
{
2020-09-10 18:44:10 +02:00
// Propagate changes to Power Launcher through IPC
// Using InvariantCulture as this is an IPC message
2020-09-10 18:44:10 +02:00
SendConfigMSG(
string.Format(
CultureInfo.InvariantCulture,
"{{ \"powertoys\": {{ \"{0}\": {1} }} }}",
PowerLauncherSettings.ModuleName,
JsonSerializer.Serialize(settings)));
2020-09-10 18:44:10 +02:00
};
Fix for settings crash on toggling enable button for any PowerToy (#6620) * Removed getSettings from moduleEnabled so that it doesn't have to reopen the file everytime * To Lower to while checking the theme * color picker doesn't reopen the file * use the generalView model config directly for FZ * Made the same change for all the viewmodels so that they access the general view model value directly instead of opening and reading the value from a file each time * removed unused variable * Fix initialization in tests * should read the file only if general settings does not exist * Added interfaces for all the powertoys to use the generalSettings singleton class * Runner is responding to changes in settings, only issue is that every time the general settings page is loaded the information is being read because isInitialized property could not be ignored during serialization * All tests pass * Settings and runner are working as expected with the settings cache * added a null check to read from the file only when the settings process is started * use converter to deserialize an interface * Renamed generalSettings within the cache to be called CommonSettingsConfig * All tests pass, had to initialize the common settings config instance * Added few comments to newly created classes * encapsulating load and store of general view model * reading from file is encapsulated * settings and runner wotk with generic singleton * Shortcut guide works as expected * Fancyzones, shortcutguide and power preview use the settings repository and work as expected * referencing GeneralSettings instead of the settingsRepository<GeneralSettings> within viewmodels * unified access to General settings and removed the IGeneralSettingsData interface * Passing settings to viewmodel as a parameter * removed ISettingsConfig interface from the viewmodels which are not using the singleton to access settings * have to use ISettingsConfig to use GetSettings * refactored tests, all tests pass * Added test for settingsRepository that a single instance is created * Added comments and removed unnecessary headers/code * added settings repository tests * moq for each settings file * Img resizer tests pass * General tests pass * FancyZones tests pass * PowerPreview tests pass * PowerRename tests pass * shortcut guide tests pass * Added GetModuleName to ISettingsConfig * unify the way the Modulename is accessed. It was redeclared in multiple places and this would cause an issue if the name is changed only in one place. All the module names are accessed using the <T>Settings.ModuleName, eg: ShortcutGuideSettings.ModuleName. * create PTRun settings file if it does not exist * GetFile is now a private function. Modified the logic of KBM default.json access and PT Run so that we can re-use GetSettings instead of GetFile. * Added UpgradeSettingsConfiguration to the ISettingsConfig interface so that the settings file can be upgraded based on some condition. Presently, only the GeneralSettings file is utilizing this to change the PT Version number based on the old PT version and the current PT version that it receives from the helper function. Verified that if the PT version is lower in the general settings.json file, settings saves the file with the new version info. * The naming for the PowerToys was inconsistent and the variables were redeclared in multiple places. To have the settings.ModuleName as the main name, all other places should refer to that name. In the tests file the module name for ImgResizer was 'ImageResizer' and not 'Image Resizer'. * renamed lock * Remove unnecessary GetSettingsFileNAme function. It is no longer in use because the code does not use types to create a new BasePTModule object
2020-09-23 22:20:32 +02:00
if (_settingsUtils.SettingsExists(PowerLauncherSettings.ModuleName))
2020-09-10 18:44:10 +02:00
{
settings = _settingsUtils.GetSettings<PowerLauncherSettings>(PowerLauncherSettings.ModuleName);
2020-09-10 18:44:10 +02:00
}
else
{
settings = new PowerLauncherSettings();
settings.Properties.OpenPowerLauncher.Alt = true;
settings.Properties.OpenPowerLauncher.Code = defaultKeyCode;
settings.Properties.MaximumNumberOfResults = 4;
callback(settings);
}
2020-08-17 19:00:56 +02:00
}
public PowerLauncherViewModel(PowerLauncherSettings settings, SendCallback callback)
{
this.settings = settings;
this.callback = callback;
}
private void UpdateSettings([CallerMemberName] string propertyName = null)
{
// Notify UI of property change
OnPropertyChanged(propertyName);
callback(settings);
}
public bool EnablePowerLauncher
{
get
{
Fix for settings crash on toggling enable button for any PowerToy (#6620) * Removed getSettings from moduleEnabled so that it doesn't have to reopen the file everytime * To Lower to while checking the theme * color picker doesn't reopen the file * use the generalView model config directly for FZ * Made the same change for all the viewmodels so that they access the general view model value directly instead of opening and reading the value from a file each time * removed unused variable * Fix initialization in tests * should read the file only if general settings does not exist * Added interfaces for all the powertoys to use the generalSettings singleton class * Runner is responding to changes in settings, only issue is that every time the general settings page is loaded the information is being read because isInitialized property could not be ignored during serialization * All tests pass * Settings and runner are working as expected with the settings cache * added a null check to read from the file only when the settings process is started * use converter to deserialize an interface * Renamed generalSettings within the cache to be called CommonSettingsConfig * All tests pass, had to initialize the common settings config instance * Added few comments to newly created classes * encapsulating load and store of general view model * reading from file is encapsulated * settings and runner wotk with generic singleton * Shortcut guide works as expected * Fancyzones, shortcutguide and power preview use the settings repository and work as expected * referencing GeneralSettings instead of the settingsRepository<GeneralSettings> within viewmodels * unified access to General settings and removed the IGeneralSettingsData interface * Passing settings to viewmodel as a parameter * removed ISettingsConfig interface from the viewmodels which are not using the singleton to access settings * have to use ISettingsConfig to use GetSettings * refactored tests, all tests pass * Added test for settingsRepository that a single instance is created * Added comments and removed unnecessary headers/code * added settings repository tests * moq for each settings file * Img resizer tests pass * General tests pass * FancyZones tests pass * PowerPreview tests pass * PowerRename tests pass * shortcut guide tests pass * Added GetModuleName to ISettingsConfig * unify the way the Modulename is accessed. It was redeclared in multiple places and this would cause an issue if the name is changed only in one place. All the module names are accessed using the <T>Settings.ModuleName, eg: ShortcutGuideSettings.ModuleName. * create PTRun settings file if it does not exist * GetFile is now a private function. Modified the logic of KBM default.json access and PT Run so that we can re-use GetSettings instead of GetFile. * Added UpgradeSettingsConfiguration to the ISettingsConfig interface so that the settings file can be upgraded based on some condition. Presently, only the GeneralSettings file is utilizing this to change the PT Version number based on the old PT version and the current PT version that it receives from the helper function. Verified that if the PT version is lower in the general settings.json file, settings saves the file with the new version info. * The naming for the PowerToys was inconsistent and the variables were redeclared in multiple places. To have the settings.ModuleName as the main name, all other places should refer to that name. In the tests file the module name for ImgResizer was 'ImageResizer' and not 'Image Resizer'. * renamed lock * Remove unnecessary GetSettingsFileNAme function. It is no longer in use because the code does not use types to create a new BasePTModule object
2020-09-23 22:20:32 +02:00
return GeneralSettingsConfig.Enabled.PowerLauncher;
2020-08-17 19:00:56 +02:00
}
set
{
Fix for settings crash on toggling enable button for any PowerToy (#6620) * Removed getSettings from moduleEnabled so that it doesn't have to reopen the file everytime * To Lower to while checking the theme * color picker doesn't reopen the file * use the generalView model config directly for FZ * Made the same change for all the viewmodels so that they access the general view model value directly instead of opening and reading the value from a file each time * removed unused variable * Fix initialization in tests * should read the file only if general settings does not exist * Added interfaces for all the powertoys to use the generalSettings singleton class * Runner is responding to changes in settings, only issue is that every time the general settings page is loaded the information is being read because isInitialized property could not be ignored during serialization * All tests pass * Settings and runner are working as expected with the settings cache * added a null check to read from the file only when the settings process is started * use converter to deserialize an interface * Renamed generalSettings within the cache to be called CommonSettingsConfig * All tests pass, had to initialize the common settings config instance * Added few comments to newly created classes * encapsulating load and store of general view model * reading from file is encapsulated * settings and runner wotk with generic singleton * Shortcut guide works as expected * Fancyzones, shortcutguide and power preview use the settings repository and work as expected * referencing GeneralSettings instead of the settingsRepository<GeneralSettings> within viewmodels * unified access to General settings and removed the IGeneralSettingsData interface * Passing settings to viewmodel as a parameter * removed ISettingsConfig interface from the viewmodels which are not using the singleton to access settings * have to use ISettingsConfig to use GetSettings * refactored tests, all tests pass * Added test for settingsRepository that a single instance is created * Added comments and removed unnecessary headers/code * added settings repository tests * moq for each settings file * Img resizer tests pass * General tests pass * FancyZones tests pass * PowerPreview tests pass * PowerRename tests pass * shortcut guide tests pass * Added GetModuleName to ISettingsConfig * unify the way the Modulename is accessed. It was redeclared in multiple places and this would cause an issue if the name is changed only in one place. All the module names are accessed using the <T>Settings.ModuleName, eg: ShortcutGuideSettings.ModuleName. * create PTRun settings file if it does not exist * GetFile is now a private function. Modified the logic of KBM default.json access and PT Run so that we can re-use GetSettings instead of GetFile. * Added UpgradeSettingsConfiguration to the ISettingsConfig interface so that the settings file can be upgraded based on some condition. Presently, only the GeneralSettings file is utilizing this to change the PT Version number based on the old PT version and the current PT version that it receives from the helper function. Verified that if the PT version is lower in the general settings.json file, settings saves the file with the new version info. * The naming for the PowerToys was inconsistent and the variables were redeclared in multiple places. To have the settings.ModuleName as the main name, all other places should refer to that name. In the tests file the module name for ImgResizer was 'ImageResizer' and not 'Image Resizer'. * renamed lock * Remove unnecessary GetSettingsFileNAme function. It is no longer in use because the code does not use types to create a new BasePTModule object
2020-09-23 22:20:32 +02:00
if (GeneralSettingsConfig.Enabled.PowerLauncher != value)
2020-08-17 19:00:56 +02:00
{
Fix for settings crash on toggling enable button for any PowerToy (#6620) * Removed getSettings from moduleEnabled so that it doesn't have to reopen the file everytime * To Lower to while checking the theme * color picker doesn't reopen the file * use the generalView model config directly for FZ * Made the same change for all the viewmodels so that they access the general view model value directly instead of opening and reading the value from a file each time * removed unused variable * Fix initialization in tests * should read the file only if general settings does not exist * Added interfaces for all the powertoys to use the generalSettings singleton class * Runner is responding to changes in settings, only issue is that every time the general settings page is loaded the information is being read because isInitialized property could not be ignored during serialization * All tests pass * Settings and runner are working as expected with the settings cache * added a null check to read from the file only when the settings process is started * use converter to deserialize an interface * Renamed generalSettings within the cache to be called CommonSettingsConfig * All tests pass, had to initialize the common settings config instance * Added few comments to newly created classes * encapsulating load and store of general view model * reading from file is encapsulated * settings and runner wotk with generic singleton * Shortcut guide works as expected * Fancyzones, shortcutguide and power preview use the settings repository and work as expected * referencing GeneralSettings instead of the settingsRepository<GeneralSettings> within viewmodels * unified access to General settings and removed the IGeneralSettingsData interface * Passing settings to viewmodel as a parameter * removed ISettingsConfig interface from the viewmodels which are not using the singleton to access settings * have to use ISettingsConfig to use GetSettings * refactored tests, all tests pass * Added test for settingsRepository that a single instance is created * Added comments and removed unnecessary headers/code * added settings repository tests * moq for each settings file * Img resizer tests pass * General tests pass * FancyZones tests pass * PowerPreview tests pass * PowerRename tests pass * shortcut guide tests pass * Added GetModuleName to ISettingsConfig * unify the way the Modulename is accessed. It was redeclared in multiple places and this would cause an issue if the name is changed only in one place. All the module names are accessed using the <T>Settings.ModuleName, eg: ShortcutGuideSettings.ModuleName. * create PTRun settings file if it does not exist * GetFile is now a private function. Modified the logic of KBM default.json access and PT Run so that we can re-use GetSettings instead of GetFile. * Added UpgradeSettingsConfiguration to the ISettingsConfig interface so that the settings file can be upgraded based on some condition. Presently, only the GeneralSettings file is utilizing this to change the PT Version number based on the old PT version and the current PT version that it receives from the helper function. Verified that if the PT version is lower in the general settings.json file, settings saves the file with the new version info. * The naming for the PowerToys was inconsistent and the variables were redeclared in multiple places. To have the settings.ModuleName as the main name, all other places should refer to that name. In the tests file the module name for ImgResizer was 'ImageResizer' and not 'Image Resizer'. * renamed lock * Remove unnecessary GetSettingsFileNAme function. It is no longer in use because the code does not use types to create a new BasePTModule object
2020-09-23 22:20:32 +02:00
GeneralSettingsConfig.Enabled.PowerLauncher = value;
2020-08-17 19:00:56 +02:00
OnPropertyChanged(nameof(EnablePowerLauncher));
Fix for settings crash on toggling enable button for any PowerToy (#6620) * Removed getSettings from moduleEnabled so that it doesn't have to reopen the file everytime * To Lower to while checking the theme * color picker doesn't reopen the file * use the generalView model config directly for FZ * Made the same change for all the viewmodels so that they access the general view model value directly instead of opening and reading the value from a file each time * removed unused variable * Fix initialization in tests * should read the file only if general settings does not exist * Added interfaces for all the powertoys to use the generalSettings singleton class * Runner is responding to changes in settings, only issue is that every time the general settings page is loaded the information is being read because isInitialized property could not be ignored during serialization * All tests pass * Settings and runner are working as expected with the settings cache * added a null check to read from the file only when the settings process is started * use converter to deserialize an interface * Renamed generalSettings within the cache to be called CommonSettingsConfig * All tests pass, had to initialize the common settings config instance * Added few comments to newly created classes * encapsulating load and store of general view model * reading from file is encapsulated * settings and runner wotk with generic singleton * Shortcut guide works as expected * Fancyzones, shortcutguide and power preview use the settings repository and work as expected * referencing GeneralSettings instead of the settingsRepository<GeneralSettings> within viewmodels * unified access to General settings and removed the IGeneralSettingsData interface * Passing settings to viewmodel as a parameter * removed ISettingsConfig interface from the viewmodels which are not using the singleton to access settings * have to use ISettingsConfig to use GetSettings * refactored tests, all tests pass * Added test for settingsRepository that a single instance is created * Added comments and removed unnecessary headers/code * added settings repository tests * moq for each settings file * Img resizer tests pass * General tests pass * FancyZones tests pass * PowerPreview tests pass * PowerRename tests pass * shortcut guide tests pass * Added GetModuleName to ISettingsConfig * unify the way the Modulename is accessed. It was redeclared in multiple places and this would cause an issue if the name is changed only in one place. All the module names are accessed using the <T>Settings.ModuleName, eg: ShortcutGuideSettings.ModuleName. * create PTRun settings file if it does not exist * GetFile is now a private function. Modified the logic of KBM default.json access and PT Run so that we can re-use GetSettings instead of GetFile. * Added UpgradeSettingsConfiguration to the ISettingsConfig interface so that the settings file can be upgraded based on some condition. Presently, only the GeneralSettings file is utilizing this to change the PT Version number based on the old PT version and the current PT version that it receives from the helper function. Verified that if the PT version is lower in the general settings.json file, settings saves the file with the new version info. * The naming for the PowerToys was inconsistent and the variables were redeclared in multiple places. To have the settings.ModuleName as the main name, all other places should refer to that name. In the tests file the module name for ImgResizer was 'ImageResizer' and not 'Image Resizer'. * renamed lock * Remove unnecessary GetSettingsFileNAme function. It is no longer in use because the code does not use types to create a new BasePTModule object
2020-09-23 22:20:32 +02:00
OutGoingGeneralSettings outgoing = new OutGoingGeneralSettings(GeneralSettingsConfig);
SendConfigMSG(outgoing.ToString());
2020-08-17 19:00:56 +02:00
}
}
}
public string SearchResultPreference
{
get
{
return settings.Properties.SearchResultPreference;
}
set
{
if (settings.Properties.SearchResultPreference != value)
{
settings.Properties.SearchResultPreference = value;
UpdateSettings();
}
}
}
public string SearchTypePreference
{
get
{
return settings.Properties.SearchTypePreference;
}
set
{
if (settings.Properties.SearchTypePreference != value)
{
settings.Properties.SearchTypePreference = value;
UpdateSettings();
}
}
}
public int MaximumNumberOfResults
{
get
{
return settings.Properties.MaximumNumberOfResults;
}
set
{
if (settings.Properties.MaximumNumberOfResults != value)
{
settings.Properties.MaximumNumberOfResults = value;
UpdateSettings();
}
}
}
public HotkeySettings OpenPowerLauncher
{
get
{
return settings.Properties.OpenPowerLauncher;
}
set
{
if (settings.Properties.OpenPowerLauncher != value)
{
settings.Properties.OpenPowerLauncher = value;
UpdateSettings();
}
}
}
public HotkeySettings OpenFileLocation
{
get
{
return settings.Properties.OpenFileLocation;
}
set
{
if (settings.Properties.OpenFileLocation != value)
{
settings.Properties.OpenFileLocation = value;
UpdateSettings();
}
}
}
public HotkeySettings CopyPathLocation
{
get
{
return settings.Properties.CopyPathLocation;
}
set
{
if (settings.Properties.CopyPathLocation != value)
{
settings.Properties.CopyPathLocation = value;
UpdateSettings();
}
}
}
public bool OverrideWinRKey
{
get
{
return settings.Properties.OverrideWinkeyR;
}
set
{
if (settings.Properties.OverrideWinkeyR != value)
{
settings.Properties.OverrideWinkeyR = value;
UpdateSettings();
}
}
}
public bool OverrideWinSKey
{
get
{
return settings.Properties.OverrideWinkeyS;
}
set
{
if (settings.Properties.OverrideWinkeyS != value)
{
settings.Properties.OverrideWinkeyS = value;
UpdateSettings();
}
}
}
public bool IgnoreHotkeysInFullScreen
{
get
{
return settings.Properties.IgnoreHotkeysInFullscreen;
}
set
{
if (settings.Properties.IgnoreHotkeysInFullscreen != value)
{
settings.Properties.IgnoreHotkeysInFullscreen = value;
UpdateSettings();
}
}
}
public bool ClearInputOnLaunch
{
get
{
return settings.Properties.ClearInputOnLaunch;
}
set
{
if (settings.Properties.ClearInputOnLaunch != value)
{
settings.Properties.ClearInputOnLaunch = value;
UpdateSettings();
}
}
}
public bool DisableDriveDetectionWarning
{
get
{
return settings.Properties.DisableDriveDetectionWarning;
}
set
{
if (settings.Properties.DisableDriveDetectionWarning != value)
{
settings.Properties.DisableDriveDetectionWarning = value;
UpdateSettings();
}
}
}
}
}