示例#1
0
        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 ToJsonString_ShouldReturnValidJSONOfModel_WhenSuccessful()
        {
            // Arrange
            string file_name          = "test\\BasePTModuleSettingsTest";
            string expectedSchemaText = @"
                {
                    '$schema': 'http://json-schema.org/draft-04/schema#',
                    'type': 'object',
                    'properties': {
                    'name': {
                        'type': 'string'
                    },
                    'version': {
                        'type': 'string'
                    }
                    },
                'additionalProperties': false
                }";

            string testSettingsConfigs = new BasePTSettingsTest().ToJsonString();

            SettingsUtils.SaveSettings(testSettingsConfigs, file_name);
            JsonSchema expectedSchema = JsonSchema.Parse(expectedSchemaText);

            // Act
            JObject actualSchema = JObject.Parse(SettingsUtils.GetSettings <BasePTSettingsTest>(file_name).ToJsonString());
            bool    valid        = actualSchema.IsValid(expectedSchema);

            // Assert
            Assert.IsTrue(valid);
        }
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            bool            isEnabled       = (bool)value;
            GeneralSettings generalSettings = SettingsUtils.GetSettings <GeneralSettings>(string.Empty);

            var defaultTheme = new Windows.UI.ViewManagement.UISettings();
            var uiTheme      = defaultTheme.GetColorValue(Windows.UI.ViewManagement.UIColorType.Background).ToString();

            string selectedTheme = generalSettings.Theme.ToLower();

            if (selectedTheme == "dark" || (selectedTheme == "system" && uiTheme == "#FF000000"))
            {
                // DARK
                if (isEnabled)
                {
                    return((SolidColorBrush)Application.Current.Resources["DarkForegroundBrush"]);
                }
                else
                {
                    return((SolidColorBrush)Application.Current.Resources["DarkForegroundDisabledBrush"]);
                }
            }
            else
            {
                // LIGHT
                if (isEnabled)
                {
                    return((SolidColorBrush)Application.Current.Resources["LightForegroundBrush"]);
                }
                else
                {
                    return((SolidColorBrush)Application.Current.Resources["LightForegroundDisabledBrush"]);
                }
            }
        }
        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 KeyboardManagerViewModel(Func <string, int> ipcMSGCallBackFunc, Func <List <KeysDataModel>, int> filterRemapKeysList)
        {
            // set the callback functions value to hangle outgoing IPC message.
            SendConfigMSG       = ipcMSGCallBackFunc;
            FilterRemapKeysList = filterRemapKeysList;

            if (SettingsUtils.SettingsExists(PowerToyName))
            {
                // Todo: Be more resilient while reading and saving settings.
                settings = SettingsUtils.GetSettings <KeyboardManagerSettings>(PowerToyName);

                // Load profile.
                if (!LoadProfile())
                {
                    profile = new KeyboardManagerProfile();
                }
            }
            else
            {
                settings = new KeyboardManagerSettings(PowerToyName);
                SettingsUtils.SaveSettings(settings.ToJsonString(), PowerToyName);
            }

            if (SettingsUtils.SettingsExists())
            {
                generalSettings = SettingsUtils.GetSettings <GeneralSettings>(string.Empty);
            }
            else
            {
                generalSettings = new GeneralSettings();
                SettingsUtils.SaveSettings(generalSettings.ToJsonString(), string.Empty);
            }
        }
示例#6
0
        public void OriginalFilesModificationTest(string version, string fileName)
        {
            var settingPathMock   = new Mock <ISettingsPath>();
            var mockIOProvider    = BackCompatTestProperties.GetModuleIOProvider(version, ShortcutGuideSettings.ModuleName, fileName);
            var mockSettingsUtils = new SettingsUtils(mockIOProvider.Object, settingPathMock.Object);
            ShortcutGuideSettings originalSettings = mockSettingsUtils.GetSettings <ShortcutGuideSettings>(ShortcutGuideSettings.ModuleName);

            var             mockGeneralIOProvider      = BackCompatTestProperties.GetGeneralSettingsIOProvider(version);
            var             mockGeneralSettingsUtils   = new SettingsUtils(mockGeneralIOProvider.Object, settingPathMock.Object);
            GeneralSettings originalGeneralSettings    = mockGeneralSettingsUtils.GetSettings <GeneralSettings>();
            var             generalSettingsRepository  = new BackCompatTestProperties.MockSettingsRepository <GeneralSettings>(mockGeneralSettingsUtils);
            var             shortcutSettingsRepository = new BackCompatTestProperties.MockSettingsRepository <ShortcutGuideSettings>(mockSettingsUtils);

            // Initialise View Model with test Config files
            Func <string, int>     SendMockIPCConfigMSG = msg => { return(0); };
            ShortcutGuideViewModel viewModel            = new ShortcutGuideViewModel(generalSettingsRepository, shortcutSettingsRepository, SendMockIPCConfigMSG);

            // Verify that the old settings persisted
            Assert.AreEqual(originalGeneralSettings.Enabled.ShortcutGuide, viewModel.IsEnabled);
            Assert.AreEqual(originalSettings.Properties.OverlayOpacity.Value, viewModel.OverlayOpacity);
            Assert.AreEqual(originalSettings.Properties.PressTime.Value, viewModel.PressTime);

            //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, ShortcutGuideSettings.ModuleName, expectedCallCount);
            BackCompatTestProperties.VerifyGeneralSettingsIOProviderWasRead(mockGeneralIOProvider, expectedCallCount);
        }
        private bool LoadProfile()
        {
            var success = true;

            try
            {
                using (var profileFileMutex = Mutex.OpenExisting(ProfileFileMutexName))
                {
                    if (profileFileMutex.WaitOne(ProfileFileMutexWaitTimeoutMilliseconds))
                    {
                        // update the UI element here.
                        try
                        {
                            profile = SettingsUtils.GetSettings <KeyboardManagerProfile>(PowerToyName, settings.Properties.ActiveConfiguration.Value + JsonFileType);
                        }
                        finally
                        {
                            // Make sure to release the mutex.
                            profileFileMutex.ReleaseMutex();
                        }
                    }
                    else
                    {
                        success = false;
                    }
                }
            }
            catch (Exception)
            {
                // Failed to load the configuration.
                success = false;
            }

            return(success);
        }
示例#8
0
        public void OriginalFilesModificationTest(string version, string fileName)
        {
            var mockIOProvider    = BackCompatTestProperties.GetModuleIOProvider(version, PowerRenameSettings.ModuleName, fileName);
            var mockSettingsUtils = new SettingsUtils(mockIOProvider.Object);
            PowerRenameLocalProperties originalSettings = mockSettingsUtils.GetSettings <PowerRenameLocalProperties>(PowerRenameSettings.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); };
            PowerRenameViewModel viewModel            = new PowerRenameViewModel(mockSettingsUtils, generalSettingsRepository, SendMockIPCConfigMSG);

            // Verifiy that the old settings persisted
            Assert.AreEqual(originalGeneralSettings.Enabled.PowerRename, viewModel.IsEnabled);
            Assert.AreEqual(originalSettings.ExtendedContextMenuOnly, viewModel.EnabledOnContextExtendedMenu);
            Assert.AreEqual(originalSettings.MRUEnabled, viewModel.MRUEnabled);
            Assert.AreEqual(originalSettings.ShowIcon, viewModel.EnabledOnContextMenu);

            //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, PowerRenameSettings.ModuleName, expectedCallCount);
            BackCompatTestProperties.VerifyGeneralSettingsIOProviderWasRead(mockGeneralIOProvider, expectedCallCount);
        }
        public KeyboardManagerViewModel()
        {
            dispatcher = Window.Current.Dispatcher;
            if (SettingsUtils.SettingsExists(PowerToyName))
            {
                // Todo: Be more resillent while reading and saving settings.
                settings = SettingsUtils.GetSettings <KeyboardManagerSettings>(PowerToyName);

                // Load profile.
                if (!LoadProfile())
                {
                    profile = new KeyboardManagerProfile();
                }
            }
            else
            {
                settings = new KeyboardManagerSettings(PowerToyName);
                SettingsUtils.SaveSettings(settings.ToJsonString(), PowerToyName);
            }

            if (SettingsUtils.SettingsExists())
            {
                generalSettings = SettingsUtils.GetSettings <GeneralSettings>(string.Empty);
            }
            else
            {
                generalSettings = new GeneralSettings();
                SettingsUtils.SaveSettings(generalSettings.ToJsonString(), string.Empty);
            }

            watcher = Helper.GetFileWatcher(
                PowerToyName,
                settings.Properties.ActiveConfiguration.Value + JsonFileType,
                OnConfigFileUpdate);
        }
示例#10
0
        public void OriginalFilesModificationTest(string version, string fileName)
        {
            var settingPathMock = new Mock <ISettingsPath>();
            var fileMock        = BackCompatTestProperties.GetModuleIOProvider(version, PowerPreviewSettings.ModuleName, fileName);

            var mockSettingsUtils = new SettingsUtils(fileMock.Object, settingPathMock.Object);
            PowerPreviewSettings originalSettings = mockSettingsUtils.GetSettings <PowerPreviewSettings>(PowerPreviewSettings.ModuleName);
            var repository = new BackCompatTestProperties.MockSettingsRepository <PowerPreviewSettings>(mockSettingsUtils);

            var             mockGeneralIOProvider     = BackCompatTestProperties.GetGeneralSettingsIOProvider(version);
            var             mockGeneralSettingsUtils  = new SettingsUtils(mockGeneralIOProvider.Object, settingPathMock.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); };
            PowerPreviewViewModel viewModel            = new PowerPreviewViewModel(repository, generalSettingsRepository, SendMockIPCConfigMSG);

            // Verifiy that the old settings persisted
            Assert.AreEqual(originalGeneralSettings.IsElevated, viewModel.IsElevated);
            Assert.AreEqual(originalSettings.Properties.EnableMdPreview, viewModel.MDRenderIsEnabled);
            Assert.AreEqual(originalSettings.Properties.EnableSvgPreview, viewModel.SVGRenderIsEnabled);
            Assert.AreEqual(originalSettings.Properties.EnableSvgThumbnail, viewModel.SVGThumbnailIsEnabled);

            //Verify that the stub file was used
            var expectedCallCount = 2;  //once via the view model, and once by the test (GetSettings<T>)

            BackCompatTestProperties.VerifyModuleIOProviderWasRead(fileMock, PowerPreviewSettings.ModuleName, expectedCallCount);
        }
        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);
        }
示例#12
0
        public void OriginalFilesModificationTest(string version, string fileName)
        {
            var mockIOProvider    = BackCompatTestProperties.GetModuleIOProvider(version, ImageResizerSettings.ModuleName, fileName);
            var mockSettingsUtils = new SettingsUtils(mockIOProvider.Object);
            ImageResizerSettings originalSettings = mockSettingsUtils.GetSettings <ImageResizerSettings>(ImageResizerSettings.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); };
            ImageResizerViewModel viewModel            = new ImageResizerViewModel(mockSettingsUtils, generalSettingsRepository, SendMockIPCConfigMSG);

            // Verifiy that the old settings persisted
            Assert.AreEqual(originalGeneralSettings.Enabled.ImageResizer, viewModel.IsEnabled);
            Assert.AreEqual(ImageResizerViewModel.GetEncoderIndex(originalSettings.Properties.ImageresizerFallbackEncoder.Value), viewModel.Encoder);
            Assert.AreEqual(originalSettings.Properties.ImageresizerFileName.Value, viewModel.FileName);
            Assert.AreEqual(originalSettings.Properties.ImageresizerJpegQualityLevel.Value, viewModel.JPEGQualityLevel);
            Assert.AreEqual(originalSettings.Properties.ImageresizerKeepDateModified.Value, viewModel.KeepDateModified);
            Assert.AreEqual(originalSettings.Properties.ImageresizerPngInterlaceOption.Value, viewModel.PngInterlaceOption);
            Assert.AreEqual(originalSettings.Properties.ImageresizerSizes.Value.Count, viewModel.Sizes.Count);
            Assert.AreEqual(originalSettings.Properties.ImageresizerTiffCompressOption.Value, viewModel.TiffCompressOption);

            //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, ImageResizerSettings.ModuleName, expectedCallCount);
            BackCompatTestProperties.VerifyGeneralSettingsIOProviderWasRead(mockGeneralIOProvider, expectedCallCount);
        }
示例#13
0
        public void FileName_ShouldNOTUpdateValue_WhenNameIsInValid()
        {
            // arrange
            ImageResizerViewModel viewModel = new ImageResizerViewModel();

            string[] invalidNames =
            {
                string.Empty,
                " ",            // no name.
                "%1",           // single name value.
                "%7 (%5)",      // name max index exceeded.
                "%8 (%8)",      // name max index exceeded.
                "%5 (%3 )",     // name contains extra spaces.
                "%5  (%3)",     // name contains extra spaces.
                "%5 ( %3)",     // name contains extra spaces.
                "% 5 ( %3)",    // name contains extra spaces.
                "%5 (% 3)",     // name contains extra spaces.
                "%5 ( %3 )",    // name contains extra spaces.
            };

            // act and Assert
            foreach (string invalidName in invalidNames)
            {
                viewModel          = new ImageResizerViewModel();
                viewModel.FileName = invalidName;
                Assert.AreNotEqual(invalidName, viewModel.FileName);

                ImageResizerSettings settings = SettingsUtils.GetSettings <ImageResizerSettings>(Module);
                Assert.AreNotEqual(invalidName, settings.Properties.ImageresizerFileName.Value);
            }
        }
        public PowerRenameViewModel()
        {
            try
            {
                PowerRenameLocalProperties localSettings = SettingsUtils.GetSettings <PowerRenameLocalProperties>(ModuleName, "power-rename-settings.json");
                Settings = new PowerRenameSettings(localSettings);
            }
            catch
            {
                PowerRenameLocalProperties localSettings = new PowerRenameLocalProperties();
                Settings = new PowerRenameSettings(localSettings);
                SettingsUtils.SaveSettings(localSettings.ToJsonString(), ModuleName, "power-rename-settings.json");
            }

            _powerRenameEnabledOnContextMenu         = Settings.Properties.ShowIcon.Value;
            _powerRenameEnabledOnContextExtendedMenu = Settings.Properties.ExtendedContextMenuOnly.Value;
            _powerRenameRestoreFlagsOnLaunch         = Settings.Properties.PersistState.Value;
            _powerRenameMaxDispListNumValue          = Settings.Properties.MaxMRUSize.Value;
            _autoComplete = Settings.Properties.MRUEnabled.Value;

            GeneralSettings generalSettings;

            try
            {
                generalSettings = SettingsUtils.GetSettings <GeneralSettings>(string.Empty);
            }
            catch
            {
                generalSettings = new GeneralSettings();
                SettingsUtils.SaveSettings(generalSettings.ToJsonString(), string.Empty);
            }

            _powerRenameEnabled = generalSettings.Enabled.PowerRename;
        }
示例#15
0
        public void OriginalFilesModificationTest(string version, string fileName)
        {
            // Arrange
            var mockIOProvider  = BackCompatTestProperties.GetModuleIOProvider(version, ColorPickerSettings.ModuleName, fileName);
            var settingPathMock = new Mock <ISettingsPath>();

            var mockSettingsUtils = new SettingsUtils(mockIOProvider.Object, settingPathMock.Object);
            ColorPickerSettings originalSettings = mockSettingsUtils.GetSettings <ColorPickerSettings>(ColorPickerSettings.ModuleName);

            var mockGeneralIOProvider = BackCompatTestProperties.GetGeneralSettingsIOProvider(version);

            var             mockGeneralSettingsUtils  = new SettingsUtils(mockGeneralIOProvider.Object, settingPathMock.Object);
            GeneralSettings originalGeneralSettings   = mockGeneralSettingsUtils.GetSettings <GeneralSettings>();
            var             generalSettingsRepository = new BackCompatTestProperties.MockSettingsRepository <GeneralSettings>(mockGeneralSettingsUtils);

            // Act
            // Initialise View Model with test Config files
            using (var viewModel = new ColorPickerViewModel(mockSettingsUtils, generalSettingsRepository, ColorPickerIsEnabledByDefaultIPC))
            {
                // Assert
                // Verify that the old settings persisted
                Assert.AreEqual(originalGeneralSettings.Enabled.ColorPicker, viewModel.IsEnabled);
                Assert.AreEqual(originalSettings.Properties.ActivationShortcut.ToString(), viewModel.ActivationShortcut.ToString());
                Assert.AreEqual(originalSettings.Properties.ChangeCursor, viewModel.ChangeCursor);

                // 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, ColorPickerSettings.ModuleName, expectedCallCount);
                BackCompatTestProperties.VerifyGeneralSettingsIOProviderWasRead(mockGeneralIOProvider, expectedCallCount);
            }
        }
示例#16
0
        public void OverloadSettings()
        {
            Monitor.Enter(_watcherSyncObject);
            var retry = true;

            for (int i = 0; retry && i < MAX_RETRIES; i++)
            {
                retry = false;
                try
                {
                    var overloadSettings = SettingsUtils.GetSettings <PowerLauncherSettings>(PowerLauncherSettings.POWERTOYNAME);

                    var openPowerlauncher = ConvertHotkey(overloadSettings.properties.open_powerlauncher);
                    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.maximum_number_of_results)
                    {
                        _settings.MaxResultsToShow = overloadSettings.properties.maximum_number_of_results;
                    }

                    if (_settings.IgnoreHotkeysOnFullscreen != overloadSettings.properties.ignore_hotkeys_in_fullscreen)
                    {
                        _settings.IgnoreHotkeysOnFullscreen = overloadSettings.properties.ignore_hotkeys_in_fullscreen;
                    }

                    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.clear_input_on_launch)
                    {
                        _settings.ClearInputOnLaunch = overloadSettings.properties.clear_input_on_launch;
                    }
                }
                // 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)
                {
                    retry = true;
                    Thread.Sleep(1000);
                    Debug.WriteLine(e.Message);
                }
            }
            Monitor.Exit(_watcherSyncObject);
        }
示例#17
0
        private void LoadSettingsFromJson()
        {
            // TODO this IO call should by Async, update GetFileWatcher helper to support async
            lock (_loadingSettingsLock)
            {
                {
                    var retry      = true;
                    var retryCount = 0;

                    while (retry)
                    {
                        try
                        {
                            retryCount++;

                            if (!SettingsUtils.SettingsExists(ColorPickerModuleName))
                            {
                                Logger.LogInfo("ColorPicker settings.json was missing, creating a new one");
                                var defaultColorPickerSettings = new ColorPickerSettings();
                                defaultColorPickerSettings.Save();
                            }

                            var settings = SettingsUtils.GetSettings <ColorPickerSettings>(ColorPickerModuleName);
                            if (settings != null)
                            {
                                ChangeCursor.Value              = settings.Properties.ChangeCursor;
                                ActivationShortcut.Value        = settings.Properties.ActivationShortcut.ToString();
                                CopiedColorRepresentation.Value = settings.Properties.CopiedColorRepresentation;
                            }

                            retry = false;
                        }
                        catch (IOException ex)
                        {
                            if (retryCount > MaxNumberOfRetry)
                            {
                                retry = false;
                            }

                            Logger.LogError("Failed to read changed settings", ex);
                            Thread.Sleep(500);
                        }
#pragma warning disable CA1031 // Do not catch general exception types
                        catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
                        {
                            if (retryCount > MaxNumberOfRetry)
                            {
                                retry = false;
                            }

                            Logger.LogError("Failed to read changed settings", ex);
                            Thread.Sleep(500);
                        }
                    }
                }
            }
        }
        public FancyZonesViewModel()
        {
            try
            {
                Settings = SettingsUtils.GetSettings <FancyZonesSettings>(ModuleName);
            }
            catch
            {
                Settings = new FancyZonesSettings();
                SettingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
            }

            this.LaunchEditorEventHandler = new ButtonClickCommand(LaunchEditor);

            this._shiftDrag                       = Settings.Properties.FancyzonesShiftDrag.Value;
            this._mouseSwitch                     = Settings.Properties.FancyzonesMouseSwitch.Value;
            this._overrideSnapHotkeys             = Settings.Properties.FancyzonesOverrideSnapHotkeys.Value;
            this._moveWindowsAcrossMonitors       = Settings.Properties.FancyzonesMoveWindowsAcrossMonitors.Value;
            this._displayChangemoveWindows        = Settings.Properties.FancyzonesDisplayChangeMoveWindows.Value;
            this._zoneSetChangeMoveWindows        = Settings.Properties.FancyzonesZoneSetChangeMoveWindows.Value;
            this._appLastZoneMoveWindows          = Settings.Properties.FancyzonesAppLastZoneMoveWindows.Value;
            this._openWindowOnActiveMonitor       = Settings.Properties.FancyzonesOpenWindowOnActiveMonitor.Value;
            this._restoreSize                     = Settings.Properties.FancyzonesRestoreSize.Value;
            this._useCursorPosEditorStartupScreen = Settings.Properties.UseCursorposEditorStartupscreen.Value;
            this._showOnAllMonitors               = Settings.Properties.FancyzonesShowOnAllMonitors.Value;
            this._makeDraggedWindowTransparent    = Settings.Properties.FancyzonesMakeDraggedWindowTransparent.Value;
            this._highlightOpacity                = Settings.Properties.FancyzonesHighlightOpacity.Value;
            this._excludedApps                    = Settings.Properties.FancyzonesExcludedApps.Value;
            this.EditorHotkey                     = Settings.Properties.FancyzonesEditorHotkey.Value;

            string inactiveColor = Settings.Properties.FancyzonesInActiveColor.Value;

            this._zoneInActiveColor = inactiveColor != string.Empty ? inactiveColor.ToColor() : "#F5FCFF".ToColor();

            string borderColor = Settings.Properties.FancyzonesBorderColor.Value;

            this._zoneBorderColor = borderColor != string.Empty ? borderColor.ToColor() : "#FFFFFF".ToColor();

            string highlightColor = Settings.Properties.FancyzonesZoneHighlightColor.Value;

            this._zoneHighlightColor = highlightColor != string.Empty ? highlightColor.ToColor() : "#0078D7".ToColor();

            GeneralSettings generalSettings;

            try
            {
                generalSettings = SettingsUtils.GetSettings <GeneralSettings>(string.Empty);
            }
            catch
            {
                generalSettings = new GeneralSettings();
                SettingsUtils.SaveSettings(generalSettings.ToJsonString(), string.Empty);
            }

            this._isEnabled = generalSettings.Enabled.FancyZones;
        }
示例#19
0
        public void Restart_Elevated()
        {
            GeneralSettings settings = SettingsUtils.GetSettings <GeneralSettings>(SettingsConfigFileFolder);

            settings.CustomActionName = "restart_elevation";

            OutGoingGeneralSettings     outsettings  = new OutGoingGeneralSettings(settings);
            GeneralSettingsCustomAction customaction = new GeneralSettingsCustomAction(outsettings);

            SendRestartAsAdminConfigMSG(customaction.ToString());
        }
示例#20
0
        public void Restart_Elevated()
        {
            GeneralSettings settings = SettingsUtils.GetSettings <GeneralSettings>(string.Empty);

            settings.CustomActionName = "restart_elevation";

            OutGoingGeneralSettings     outsettings  = new OutGoingGeneralSettings(settings);
            GeneralSettingsCustomAction customaction = new GeneralSettingsCustomAction(outsettings);

            ShellPage.SndRestartAsAdminMsgCallback?.Invoke(customaction.ToString());
        }
示例#21
0
        // callback function to launch the URL to check for updates.
        private void CheckForUpdates_Click()
        {
            GeneralSettings settings = SettingsUtils.GetSettings <GeneralSettings>(string.Empty);

            settings.CustomActionName = "check_for_updates";

            OutGoingGeneralSettings     outsettings  = new OutGoingGeneralSettings(settings);
            GeneralSettingsCustomAction customaction = new GeneralSettingsCustomAction(outsettings);

            ShellPage.CheckForUpdatesMsgCallback?.Invoke(customaction.ToString());
        }
示例#22
0
        // callback function to launch the URL to check for updates.
        private async void CheckForUpdates_Click()
        {
            GeneralSettings settings = SettingsUtils.GetSettings <GeneralSettings>(SettingsConfigFileFolder);

            settings.CustomActionName = "check_for_updates";

            OutGoingGeneralSettings     outsettings  = new OutGoingGeneralSettings(settings);
            GeneralSettingsCustomAction customaction = new GeneralSettingsCustomAction(outsettings);

            SendCheckForUpdatesConfigMSG(customaction.ToString());
        }
示例#23
0
        public void KeepDateModified_ShouldUpdateValue_WhenSuccessful()
        {
            // arrange
            ImageResizerViewModel viewModel = new ImageResizerViewModel();

            // act
            viewModel.KeepDateModified = true;

            // Assert
            ImageResizerSettings settings = SettingsUtils.GetSettings <ImageResizerSettings>(Module);

            Assert.AreEqual(true, settings.Properties.ImageresizerKeepDateModified.Value);
        }
示例#24
0
        public void SettingsUtilsMustReturnDefaultItemWhenFileIsCorrupt()
        {
            // Arrange
            var mockFileSystem    = new MockFileSystem();
            var mockSettingsUtils = new SettingsUtils(mockFileSystem);

            // Act
            TestClass settings = mockSettingsUtils.GetSettings <TestClass>(string.Empty);

            // Assert
            Assert.AreEqual(settings.TestInt, 100);
            Assert.AreEqual(settings.TestString, "test");
        }
示例#25
0
        public void SettingsUtilsMustReturnDefaultItemWhenFileIsCorrupt()
        {
            // Arrange
            var mockIOProvider    = BackCompatTestProperties.GetModuleIOProvider("CorruptJson", string.Empty, "settings.json");
            var mockSettingsUtils = new SettingsUtils(mockIOProvider.Object);

            // Act
            TestClass settings = mockSettingsUtils.GetSettings <TestClass>(string.Empty);

            // Assert
            Assert.AreEqual(settings.TestInt, 100);
            Assert.AreEqual(settings.TestString, "test");
        }
示例#26
0
        public ShortcutGuideViewModel(Func <string, int> ipcMSGCallBackFunc, string configFileSubfolder = "")
        {
            // Update Settings file folder:
            _settingsConfigFileFolder = configFileSubfolder;

            try
            {
                Settings = SettingsUtils.GetSettings <ShortcutGuideSettings>(GetSettingsSubPath());
            }
            catch
            {
                Settings = new ShortcutGuideSettings();
                SettingsUtils.SaveSettings(Settings.ToJsonString(), GetSettingsSubPath());
            }

            GeneralSettings generalSettings;

            try
            {
                generalSettings = SettingsUtils.GetSettings <GeneralSettings>(string.Empty);
            }
            catch
            {
                generalSettings = new GeneralSettings();
                SettingsUtils.SaveSettings(generalSettings.ToJsonString(), string.Empty);
            }

            // set the callback functions value to hangle outgoing IPC message.
            SendConfigMSG = ipcMSGCallBackFunc;

            _isEnabled = generalSettings.Enabled.ShortcutGuide;
            _pressTime = Settings.Properties.PressTime.Value;
            _opacity   = Settings.Properties.OverlayOpacity.Value;

            string theme = Settings.Properties.Theme.Value;

            if (theme == "dark")
            {
                _themeIndex = 0;
            }

            if (theme == "light")
            {
                _themeIndex = 1;
            }

            if (theme == "system")
            {
                _themeIndex = 2;
            }
        }
示例#27
0
        public void KeepDateModified_ShouldUpdateValue_WhenSuccessful()
        {
            // arrange
            Func <string, int>    SendMockIPCConfigMSG = msg => { return(0); };
            ImageResizerViewModel viewModel            = new ImageResizerViewModel(SendMockIPCConfigMSG);

            // act
            viewModel.KeepDateModified = true;

            // Assert
            ImageResizerSettings settings = SettingsUtils.GetSettings <ImageResizerSettings>(Module);

            Assert.AreEqual(true, settings.Properties.ImageresizerKeepDateModified.Value);
        }
示例#28
0
        public PowerPreviewViewModel()
        {
            try
            {
                Settings = SettingsUtils.GetSettings <PowerPreviewSettings>(ModuleName);
            }
            catch
            {
                Settings = new PowerPreviewSettings();
                SettingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
            }

            this._svgRenderIsEnabled = Settings.properties.EnableSvg;
            this._mdRenderIsEnabled  = Settings.properties.EnableMd;
        }
示例#29
0
        public void SaveSettings_SaveSettingsToFile_WhenFilePathExists()
        {
            // Arrange
            string file_name = "\\test";
            string file_contents_correct_json_content = "{\"name\":\"powertoy module name\",\"version\":\"powertoy version\"}";

            BasePTSettingsTest expected_json = JsonSerializer.Deserialize <BasePTSettingsTest>(file_contents_correct_json_content);

            // Act
            SettingsUtils.SaveSettings(file_contents_correct_json_content, file_name);
            BasePTSettingsTest actual_json = SettingsUtils.GetSettings <BasePTSettingsTest>(file_name);

            // Assert
            Assert.IsTrue(actual_json.Equals(actual_json));
        }
示例#30
0
        public void SaveSettingsShouldCreateFileWhenFilePathIsNotFound()
        {
            // Arrange
            var    mockFileSystem = new MockFileSystem();
            var    settingsUtils  = new SettingsUtils(mockFileSystem);
            string file_name      = "test\\Test Folder";
            string file_contents_correct_json_content = "{\"name\":\"powertoy module name\",\"version\":\"powertoy version\"}";

            BasePTSettingsTest expected_json = JsonSerializer.Deserialize <BasePTSettingsTest>(file_contents_correct_json_content);

            settingsUtils.SaveSettings(file_contents_correct_json_content, file_name);
            BasePTSettingsTest actual_json = settingsUtils.GetSettings <BasePTSettingsTest>(file_name);

            // Assert
            Assert.AreEqual(expected_json.ToJsonString(), actual_json.ToJsonString());
        }