Ejemplo n.º 1
0
        public PowerRenameViewModel(ISettingsUtils settingsUtils, Func <string, int> ipcMSGCallBackFunc, string configFileSubfolder = "")
        {
            // Update Settings file folder:
            _settingsConfigFileFolder = configFileSubfolder;
            _settingsUtils            = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils));

            try
            {
                PowerRenameLocalProperties localSettings = _settingsUtils.GetSettings <PowerRenameLocalProperties>(GetSettingsSubPath(), "power-rename-settings.json");
                Settings = new PowerRenameSettings(localSettings);
            }
            catch
            {
                PowerRenameLocalProperties localSettings = new PowerRenameLocalProperties();
                Settings = new PowerRenameSettings(localSettings);
                _settingsUtils.SaveSettings(localSettings.ToJsonString(), GetSettingsSubPath(), "power-rename-settings.json");
            }

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

            _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;
        }
Ejemplo n.º 2
0
        public ShortcutGuideViewModel(ISettingsUtils settingsUtils, ISettingsRepository <GeneralSettings> settingsRepository, ISettingsRepository <ShortcutGuideSettings> moduleSettingsRepository, Func <string, int> ipcMSGCallBackFunc, string configFileSubfolder = "")
        {
            SettingsUtils = settingsUtils;

            // Update Settings file folder:
            _settingsConfigFileFolder = configFileSubfolder;

            // To obtain the general PowerToys settings.
            if (settingsRepository == null)
            {
                throw new ArgumentNullException(nameof(settingsRepository));
            }

            GeneralSettingsConfig = settingsRepository.SettingsConfig;

            // To obtain the shortcut guide settings, if the file exists.
            // If not, to create a file with the default settings and to return the default configurations.
            if (moduleSettingsRepository == null)
            {
                throw new ArgumentNullException(nameof(moduleSettingsRepository));
            }

            Settings = moduleSettingsRepository.SettingsConfig;

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

            _isEnabled    = GeneralSettingsConfig.Enabled.ShortcutGuide;
            _pressTime    = Settings.Properties.PressTime.Value;
            _opacity      = Settings.Properties.OverlayOpacity.Value;
            _disabledApps = Settings.Properties.DisabledApps.Value;

            switch (Settings.Properties.Theme.Value)
            {
            case "dark": _themeIndex = 0; break;

            case "light": _themeIndex = 1; break;

            case "system": _themeIndex = 2; break;
            }
        }
Ejemplo n.º 3
0
        public ColorPickerViewModel(ISettingsUtils settingsUtils, Func <string, int> ipcMSGCallBackFunc)
        {
            _settingsUtils = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils));
            if (_settingsUtils.SettingsExists(ColorPickerSettings.ModuleName))
            {
                _colorPickerSettings = _settingsUtils.GetSettings <ColorPickerSettings>(ColorPickerSettings.ModuleName);
            }
            else
            {
                _colorPickerSettings = new ColorPickerSettings();
            }

            if (_settingsUtils.SettingsExists())
            {
                var generalSettings = _settingsUtils.GetSettings <GeneralSettings>();
                _isEnabled = generalSettings.Enabled.ColorPicker;
            }

            // set the callback functions value to hangle outgoing IPC message.
            SendConfigMSG = ipcMSGCallBackFunc;
        }
Ejemplo n.º 4
0
        public AlwaysOnTopViewModel(ISettingsUtils settingsUtils, ISettingsRepository <GeneralSettings> settingsRepository, ISettingsRepository <AlwaysOnTopSettings> moduleSettingsRepository, Func <string, int> ipcMSGCallBackFunc)
        {
            if (settingsUtils == null)
            {
                throw new ArgumentNullException(nameof(settingsUtils));
            }

            SettingsUtils = settingsUtils;

            // To obtain the general settings configurations of PowerToys Settings.
            if (settingsRepository == null)
            {
                throw new ArgumentNullException(nameof(settingsRepository));
            }

            GeneralSettingsConfig = settingsRepository.SettingsConfig;

            // To obtain the settings configurations of AlwaysOnTop.
            if (moduleSettingsRepository == null)
            {
                throw new ArgumentNullException(nameof(moduleSettingsRepository));
            }

            Settings = moduleSettingsRepository.SettingsConfig;

            _isEnabled               = GeneralSettingsConfig.Enabled.AlwaysOnTop;
            _hotkey                  = Settings.Properties.Hotkey.Value;
            _frameEnabled            = Settings.Properties.FrameEnabled.Value;
            _frameThickness          = Settings.Properties.FrameThickness.Value;
            _frameColor              = Settings.Properties.FrameColor.Value;
            _frameAccentColor        = Settings.Properties.FrameAccentColor.Value;
            _soundEnabled            = Settings.Properties.SoundEnabled.Value;
            _doNotActivateOnGameMode = Settings.Properties.DoNotActivateOnGameMode.Value;
            _roundCornersEnabled     = Settings.Properties.RoundCornersEnabled.Value;
            _excludedApps            = Settings.Properties.ExcludedApps.Value;
            _windows11               = Helper.Windows11();

            // set the callback functions value to hangle outgoing IPC message.
            SendConfigMSG = ipcMSGCallBackFunc;
        }
Ejemplo n.º 5
0
        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
            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.GetSettings <PowerLauncherSettings>(PowerLauncherSettings.ModuleName);
            }
            else
            {
                settings = new PowerLauncherSettings();
                settings.Properties.OpenPowerLauncher.Alt  = true;
                settings.Properties.OpenPowerLauncher.Code = defaultKeyCode;
                settings.Properties.MaximumNumberOfResults = 4;
                callback(settings);
            }
        }
Ejemplo n.º 6
0
        public ColorPickerViewModel(ISettingsUtils settingsUtils, ISettingsRepository <GeneralSettings> settingsRepository, Func <string, int> ipcMSGCallBackFunc)
        {
            // Obtain the general PowerToy settings configurations
            if (settingsRepository == null)
            {
                throw new ArgumentNullException(nameof(settingsRepository));
            }

            SelectableColorRepresentations = new Dictionary <ColorRepresentationType, string>
            {
                { ColorRepresentationType.CMYK, "CMYK - cmyk(100%, 50%, 75%, 0%)" },
                { ColorRepresentationType.HEX, "HEX - #FFAA00" },
                { ColorRepresentationType.HSB, "HSB - hsb(100, 50%, 75%)" },
                { ColorRepresentationType.HSI, "HSI - hsi(100, 50%, 75%)" },
                { ColorRepresentationType.HSL, "HSL - hsl(100, 50%, 75%)" },
                { ColorRepresentationType.HSV, "HSV - hsv(100, 50%, 75%)" },
                { ColorRepresentationType.HWB, "HWB - hwb(100, 50%, 75%)" },
                { ColorRepresentationType.NCol, "NCol - R10, 50%, 75%" },
                { ColorRepresentationType.RGB, "RGB - rgb(100, 50, 75)" },
            };

            GeneralSettingsConfig = settingsRepository.SettingsConfig;

            _settingsUtils = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils));
            if (_settingsUtils.SettingsExists(ColorPickerSettings.ModuleName))
            {
                _colorPickerSettings = _settingsUtils.GetSettings <ColorPickerSettings>(ColorPickerSettings.ModuleName);
            }
            else
            {
                _colorPickerSettings = new ColorPickerSettings();
            }

            _isEnabled = GeneralSettingsConfig.Enabled.ColorPicker;

            // set the callback functions value to hangle outgoing IPC message.
            SendConfigMSG = ipcMSGCallBackFunc;
        }
Ejemplo n.º 7
0
        public ImageResizerViewModel(ISettingsUtils settingsUtils, ISettingsRepository <GeneralSettings> settingsRepository, Func <string, int> ipcMSGCallBackFunc)
        {
            _settingsUtils = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils));

            // To obtain the general settings configurations of PowerToys.
            GeneralSettingsConfig = settingsRepository.SettingsConfig;

            try
            {
                Settings = _settingsUtils.GetSettings <ImageResizerSettings>(ModuleName);
            }
            catch
            {
                Settings = new ImageResizerSettings();
                _settingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
            }

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

            _isEnabled          = GeneralSettingsConfig.Enabled.ImageResizer;
            _advancedSizes      = Settings.Properties.ImageresizerSizes.Value;
            _jpegQualityLevel   = Settings.Properties.ImageresizerJpegQualityLevel.Value;
            _pngInterlaceOption = Settings.Properties.ImageresizerPngInterlaceOption.Value;
            _tiffCompressOption = Settings.Properties.ImageresizerTiffCompressOption.Value;
            _fileName           = Settings.Properties.ImageresizerFileName.Value;
            _keepDateModified   = Settings.Properties.ImageresizerKeepDateModified.Value;
            _encoderGuidId      = GetEncoderIndex(Settings.Properties.ImageresizerFallbackEncoder.Value);

            int i = 0;

            foreach (ImageSize size in _advancedSizes)
            {
                size.Id = i;
                i++;
                size.PropertyChanged += SizePropertyChanged;
            }
        }
Ejemplo n.º 8
0
        public PowerPreviewViewModel(ISettingsUtils settingsUtils, Func <string, int> ipcMSGCallBackFunc, string configFileSubfolder = "")
        {
            // Update Settings file folder:
            _settingsConfigFileFolder = configFileSubfolder;
            _settingsUtils            = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils));

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

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

            _svgRenderIsEnabled    = Settings.Properties.EnableSvgPreview;
            _svgThumbnailIsEnabled = Settings.Properties.EnableSvgThumbnail;
            _mdRenderIsEnabled     = Settings.Properties.EnableMdPreview;
        }
Ejemplo n.º 9
0
 public MockSettingsRepository(ISettingsUtils settingsUtils)
 {
     _settingsUtils = settingsUtils;
 }
Ejemplo n.º 10
0
        public VideoConferenceViewModel(ISettingsUtils settingsUtils, ISettingsRepository <GeneralSettings> settingsRepository, Func <string, int> ipcMSGCallBackFunc, string configFileSubfolder = "")
        {
            if (settingsRepository == null)
            {
                throw new ArgumentNullException(nameof(settingsRepository));
            }

            GeneralSettingsConfig = settingsRepository.SettingsConfig;

            _settingsUtils = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils));

            SendConfigMSG = ipcMSGCallBackFunc;

            _settingsConfigFileFolder = configFileSubfolder;

            try
            {
                Settings = _settingsUtils.GetSettings <VideoConferenceSettings>(GetSettingsSubPath());
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch
#pragma warning restore CA1031 // Do not catch general exception types
            {
                Settings = new VideoConferenceSettings();
                _settingsUtils.SaveSettings(Settings.ToJsonString(), GetSettingsSubPath());
            }

            CameraNames     = interop.CommonManaged.GetAllVideoCaptureDeviceNames();
            MicrophoneNames = interop.CommonManaged.GetAllActiveMicrophoneDeviceNames();
            MicrophoneNames.Insert(0, "[All]");

            var shouldSaveSettings = false;

            if (string.IsNullOrEmpty(Settings.Properties.SelectedCamera.Value) && CameraNames.Count != 0)
            {
                _selectedCameraIndex = 0;
                Settings.Properties.SelectedCamera.Value = CameraNames[0];
                shouldSaveSettings = true;
            }
            else
            {
                _selectedCameraIndex = CameraNames.FindIndex(name => name == Settings.Properties.SelectedCamera.Value);
            }

            if (string.IsNullOrEmpty(Settings.Properties.SelectedMicrophone.Value))
            {
                _selectedMicrophoneIndex = 0;
                Settings.Properties.SelectedMicrophone.Value = MicrophoneNames[0];
                shouldSaveSettings = true;
            }
            else
            {
                _selectedMicrophoneIndex = MicrophoneNames.FindIndex(name => name == Settings.Properties.SelectedMicrophone.Value);
            }

            _isEnabled = GeneralSettingsConfig.Enabled.VideoConference;
            _cameraAndMicrophoneMuteHotkey = Settings.Properties.MuteCameraAndMicrophoneHotkey.Value;
            _mirophoneMuteHotkey           = Settings.Properties.MuteMicrophoneHotkey.Value;
            _cameraMuteHotkey      = Settings.Properties.MuteCameraHotkey.Value;
            CameraImageOverlayPath = Settings.Properties.CameraOverlayImagePath.Value;
            SelectOverlayImage     = new ButtonClickCommand(SelectOverlayImageAction);
            ClearOverlayImage      = new ButtonClickCommand(ClearOverlayImageAction);

            _hideToolbarWhenUnmuted = Settings.Properties.HideToolbarWhenUnmuted.Value;

            switch (Settings.Properties.ToolbarPosition.Value)
            {
            case "Top left corner":
                _toolbarPositionIndex = 0;
                break;

            case "Top center":
                _toolbarPositionIndex = 1;
                break;

            case "Top right corner":
                _toolbarPositionIndex = 2;
                break;

            case "Bottom left corner":
                _toolbarPositionIndex = 3;
                break;

            case "Bottom center":
                _toolbarPositionIndex = 4;
                break;

            case "Bottom right corner":
                _toolbarPositionIndex = 5;
                break;
            }

            switch (Settings.Properties.ToolbarMonitor.Value)
            {
            case "Main monitor":
                _toolbarMonitorIndex = 0;
                break;

            case "All monitors":
                _toolbarMonitorIndex = 1;
                break;
            }

            if (shouldSaveSettings)
            {
                _settingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
            }
        }
Ejemplo n.º 11
0
 private static Task <SettingsRepository <GeneralSettings> > GetSettingsRepository(ISettingsUtils settingsUtils)
 {
     return(Task.Run(() =>
     {
         return SettingsRepository <GeneralSettings> .GetInstance(settingsUtils);
     }));
 }
Ejemplo n.º 12
0
        public MouseUtilsViewModel(ISettingsUtils settingsUtils, ISettingsRepository <GeneralSettings> settingsRepository, ISettingsRepository <FindMyMouseSettings> findMyMouseSettingsRepository, ISettingsRepository <MouseHighlighterSettings> mouseHighlighterSettingsRepository, ISettingsRepository <MousePointerCrosshairsSettings> mousePointerCrosshairsSettingsRepository, Func <string, int> ipcMSGCallBackFunc)
        {
            SettingsUtils = settingsUtils;

            // To obtain the general settings configurations of PowerToys Settings.
            if (settingsRepository == null)
            {
                throw new ArgumentNullException(nameof(settingsRepository));
            }

            GeneralSettingsConfig = settingsRepository.SettingsConfig;

            _isFindMyMouseEnabled = GeneralSettingsConfig.Enabled.FindMyMouse;

            _isMouseHighlighterEnabled = GeneralSettingsConfig.Enabled.MouseHighlighter;

            _isMousePointerCrosshairsEnabled = GeneralSettingsConfig.Enabled.MousePointerCrosshairs;

            // To obtain the find my mouse settings, if the file exists.
            // If not, to create a file with the default settings and to return the default configurations.
            if (findMyMouseSettingsRepository == null)
            {
                throw new ArgumentNullException(nameof(findMyMouseSettingsRepository));
            }

            FindMyMouseSettingsConfig           = findMyMouseSettingsRepository.SettingsConfig;
            _findMyMouseDoNotActivateOnGameMode = FindMyMouseSettingsConfig.Properties.DoNotActivateOnGameMode.Value;

            string backgroundColor = FindMyMouseSettingsConfig.Properties.BackgroundColor.Value;

            _findMyMouseBackgroundColor = !string.IsNullOrEmpty(backgroundColor) ? backgroundColor : "#000000";

            string spotlightColor = FindMyMouseSettingsConfig.Properties.SpotlightColor.Value;

            _findMyMouseSpotlightColor = !string.IsNullOrEmpty(spotlightColor) ? spotlightColor : "#FFFFFF";

            _findMyMouseOverlayOpacity       = FindMyMouseSettingsConfig.Properties.OverlayOpacity.Value;
            _findMyMouseSpotlightRadius      = FindMyMouseSettingsConfig.Properties.SpotlightRadius.Value;
            _findMyMouseAnimationDurationMs  = FindMyMouseSettingsConfig.Properties.AnimationDurationMs.Value;
            _findMyMouseSpotlightInitialZoom = FindMyMouseSettingsConfig.Properties.SpotlightInitialZoom.Value;

            if (mouseHighlighterSettingsRepository == null)
            {
                throw new ArgumentNullException(nameof(mouseHighlighterSettingsRepository));
            }

            MouseHighlighterSettingsConfig = mouseHighlighterSettingsRepository.SettingsConfig;
            string leftClickColor = MouseHighlighterSettingsConfig.Properties.LeftButtonClickColor.Value;

            _highlighterLeftButtonClickColor = !string.IsNullOrEmpty(leftClickColor) ? leftClickColor : "#FFFF00";

            string rightClickColor = MouseHighlighterSettingsConfig.Properties.RightButtonClickColor.Value;

            _highlighterRightButtonClickColor = !string.IsNullOrEmpty(rightClickColor) ? rightClickColor : "#0000FF";

            _highlighterOpacity      = MouseHighlighterSettingsConfig.Properties.HighlightOpacity.Value;
            _highlighterRadius       = MouseHighlighterSettingsConfig.Properties.HighlightRadius.Value;
            _highlightFadeDelayMs    = MouseHighlighterSettingsConfig.Properties.HighlightFadeDelayMs.Value;
            _highlightFadeDurationMs = MouseHighlighterSettingsConfig.Properties.HighlightFadeDurationMs.Value;

            if (mousePointerCrosshairsSettingsRepository == null)
            {
                throw new ArgumentNullException(nameof(mousePointerCrosshairsSettingsRepository));
            }

            MousePointerCrosshairsSettingsConfig = mousePointerCrosshairsSettingsRepository.SettingsConfig;

            string crosshairsColor = MousePointerCrosshairsSettingsConfig.Properties.CrosshairsColor.Value;

            _mousePointerCrosshairsColor = !string.IsNullOrEmpty(crosshairsColor) ? crosshairsColor : "#FF0000";

            string crosshairsBorderColor = MousePointerCrosshairsSettingsConfig.Properties.CrosshairsBorderColor.Value;

            _mousePointerCrosshairsBorderColor = !string.IsNullOrEmpty(crosshairsBorderColor) ? crosshairsBorderColor : "#FFFFFF";

            _mousePointerCrosshairsOpacity    = MousePointerCrosshairsSettingsConfig.Properties.CrosshairsOpacity.Value;
            _mousePointerCrosshairsRadius     = MousePointerCrosshairsSettingsConfig.Properties.CrosshairsRadius.Value;
            _mousePointerCrosshairsThickness  = MousePointerCrosshairsSettingsConfig.Properties.CrosshairsThickness.Value;
            _mousePointerCrosshairsBorderSize = MousePointerCrosshairsSettingsConfig.Properties.CrosshairsBorderSize.Value;

            // set the callback functions value to handle outgoing IPC message.
            SendConfigMSG = ipcMSGCallBackFunc;
        }
Ejemplo n.º 13
0
        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;
            }

            switch (settings.Properties.Position)
            {
            case StartupPosition.Cursor:
                _isCursorPositionRadioButtonChecked = true;
                break;

            case StartupPosition.PrimaryMonitor:
                _isPrimaryMonitorPositionRadioButtonChecked = true;
                break;

            case StartupPosition.Focus:
                _isFocusPositionRadioButtonChecked = true;
                break;
            }

            foreach (var plugin in Plugins)
            {
                plugin.PropertyChanged += OnPluginInfoChange;
            }
        }
Ejemplo n.º 14
0
        public FancyZonesViewModel(ISettingsUtils settingsUtils, Func <string, int> ipcMSGCallBackFunc, string configFileSubfolder = "")
        {
            settingsConfigFileFolder = configFileSubfolder;
            _settingsUtils           = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils));

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

            LaunchEditorEventHandler = new ButtonClickCommand(LaunchEditor);

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

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

            string inactiveColor = Settings.Properties.FancyzonesInActiveColor.Value;

            _zoneInActiveColor = inactiveColor != string.Empty ? inactiveColor : "#F5FCFF";

            string borderColor = Settings.Properties.FancyzonesBorderColor.Value;

            _zoneBorderColor = borderColor != string.Empty ? borderColor : "#FFFFFF";

            string highlightColor = Settings.Properties.FancyzonesZoneHighlightColor.Value;

            _zoneHighlightColor = highlightColor != string.Empty ? highlightColor : "#0078D7";

            GeneralSettings generalSettings;

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

            _isEnabled = generalSettings.Enabled.FancyZones;
        }
Ejemplo n.º 15
0
        public GeneralViewModel(ISettingsUtils settingsUtils, string runAsAdminText, string runAsUserText, bool isElevated, bool isAdmin, Func <string, int> updateTheme, Func <string, int> ipcMSGCallBackFunc, Func <string, int> ipcMSGRestartAsAdminMSGCallBackFunc, Func <string, int> ipcMSGCheckForUpdatesCallBackFunc, string configFileSubfolder = "")
        {
            CheckFoUpdatesEventHandler        = new ButtonClickCommand(CheckForUpdates_Click);
            RestartElevatedButtonEventHandler = new ButtonClickCommand(Restart_Elevated);
            _settingsUtils = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils));

            try
            {
                GeneralSettingsConfigs = _settingsUtils.GetSettings <GeneralSettings>(string.Empty);

                if (Helper.CompareVersions(GeneralSettingsConfigs.PowertoysVersion, Helper.GetProductVersion()) < 0)
                {
                    // Update settings
                    GeneralSettingsConfigs.PowertoysVersion = Helper.GetProductVersion();
                    _settingsUtils.SaveSettings(GeneralSettingsConfigs.ToJsonString(), string.Empty);
                }
            }
            catch (FormatException e)
            {
                // If there is an issue with the version number format, don't migrate settings.
                Debug.WriteLine(e.Message);
            }
            catch
            {
                GeneralSettingsConfigs = new GeneralSettings();
                _settingsUtils.SaveSettings(GeneralSettingsConfigs.ToJsonString(), string.Empty);
            }

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

            // set the callback function value to update the UI theme.
            UpdateUIThemeCallBack = updateTheme;
            UpdateUIThemeCallBack(GeneralSettingsConfigs.Theme.ToLower());

            // Update Settings file folder:
            _settingsConfigFileFolder = configFileSubfolder;

            switch (GeneralSettingsConfigs.Theme.ToLower())
            {
            case "light":
                _isLightThemeRadioButtonChecked = true;
                break;

            case "dark":
                _isDarkThemeRadioButtonChecked = true;
                break;

            case "system":
                _isSystemThemeRadioButtonChecked = true;
                break;
            }

            _startup             = GeneralSettingsConfigs.Startup;
            _autoDownloadUpdates = GeneralSettingsConfigs.AutoDownloadUpdates;
            _isElevated          = isElevated;
            _runElevated         = GeneralSettingsConfigs.RunElevated;

            RunningAsUserDefaultText  = runAsUserText;
            RunningAsAdminDefaultText = runAsAdminText;

            _isAdmin = isAdmin;
        }