Ejemplo n.º 1
0
        public FancyZonesViewModel(ISettingsRepository <GeneralSettings> settingsRepository, ISettingsRepository <FancyZonesSettings> moduleSettingsRepository, Func <string, int> ipcMSGCallBackFunc, string configFileSubfolder = "")
        {
            // To obtain the general settings configurations of PowerToys Settings.
            if (settingsRepository == null)
            {
                throw new ArgumentNullException(nameof(settingsRepository));
            }

            GeneralSettingsConfig    = settingsRepository.SettingsConfig;
            settingsConfigFileFolder = configFileSubfolder;

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

            Settings = moduleSettingsRepository.SettingsConfig;

            LaunchEditorEventHandler = new ButtonClickCommand(LaunchEditor);

            _shiftDrag                       = Settings.Properties.FancyzonesShiftDrag.Value;
            _mouseSwitch                     = Settings.Properties.FancyzonesMouseSwitch.Value;
            _overrideSnapHotkeys             = Settings.Properties.FancyzonesOverrideSnapHotkeys.Value;
            _moveWindowsAcrossMonitors       = Settings.Properties.FancyzonesMoveWindowsAcrossMonitors.Value;
            _moveWindowBehaviour             = Settings.Properties.FancyzonesMoveWindowsBasedOnPosition.Value ? MoveWindowBehaviour.MoveWindowBasedOnPosition : MoveWindowBehaviour.MoveWindowBasedOnZoneIndex;
            _overlappingZonesAlgorithm       = (OverlappingZonesAlgorithm)Settings.Properties.FancyzonesOverlappingZonesAlgorithm.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;
            _quickLayoutSwitch               = Settings.Properties.FancyzonesQuickLayoutSwitch.Value;
            _flashZonesOnQuickLayoutSwitch   = Settings.Properties.FancyzonesFlashZonesOnQuickSwitch.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 = !string.IsNullOrEmpty(inactiveColor) ? inactiveColor : "#F5FCFF";

            string borderColor = Settings.Properties.FancyzonesBorderColor.Value;

            _zoneBorderColor = !string.IsNullOrEmpty(borderColor) ? borderColor : "#FFFFFF";

            string highlightColor = Settings.Properties.FancyzonesZoneHighlightColor.Value;

            _zoneHighlightColor = !string.IsNullOrEmpty(highlightColor) ? highlightColor : "#0078D7";

            _isEnabled = GeneralSettingsConfig.Enabled.FancyZones;
        }
Ejemplo n.º 2
0
        public FancyZonesViewModel()
        {
            try
            {
                Settings = SettingsUtils.GetSettings <FancyZonesSettings>(ModuleName);
            }
            catch
            {
                Settings = new FancyZonesSettings();
                SettingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
            }

            LaunchEditorEventHandler = new ButtonClickCommand(LaunchEditor);

            _shiftDrag                       = Settings.Properties.FancyzonesShiftDrag.Value;
            _mouseSwitch                     = Settings.Properties.FancyzonesMouseSwitch.Value;
            _overrideSnapHotkeys             = Settings.Properties.FancyzonesOverrideSnapHotkeys.Value;
            _moveWindowsAcrossMonitors       = Settings.Properties.FancyzonesMoveWindowsAcrossMonitors.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;
            string inactiveColor = Settings.Properties.FancyzonesInActiveColor.Value;

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

            string borderColor = Settings.Properties.FancyzonesBorderColor.Value;

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

            string highlightColor = Settings.Properties.FancyzonesZoneHighlightColor.Value;

            _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);
            }

            _isEnabled = generalSettings.Enabled.FancyZones;
        }
Ejemplo n.º 3
0
        public GeneralViewModel(ISettingsRepository <GeneralSettings> settingsRepository, 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 = "")
        {
            CheckForUpdatesEventHandler       = new ButtonClickCommand(CheckForUpdatesClick);
            RestartElevatedButtonEventHandler = new ButtonClickCommand(RestartElevated);

            // To obtain the general settings configuration of PowerToys if it exists, else to create a new file and return the default configurations.
            if (settingsRepository == null)
            {
                throw new ArgumentNullException(nameof(settingsRepository));
            }

            GeneralSettingsConfig = settingsRepository.SettingsConfig;

            // 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(GeneralSettingsConfig.Theme);

            // Update Settings file folder:
            _settingsConfigFileFolder = configFileSubfolder;

            // Using Invariant here as these are internal strings and fxcop
            // expects strings to be normalized to uppercase. While the theme names
            // are represented in lowercase everywhere else, we'll use uppercase
            // normalization for switch statements
            switch (GeneralSettingsConfig.Theme.ToUpperInvariant())
            {
            case "LIGHT":
                _isLightThemeRadioButtonChecked = true;
                break;

            case "DARK":
                _isDarkThemeRadioButtonChecked = true;
                break;

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

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

            RunningAsUserDefaultText  = runAsUserText;
            RunningAsAdminDefaultText = runAsAdminText;

            _isAdmin = isAdmin;
        }
Ejemplo n.º 4
0
        public FancyZonesViewModel(ISettingsRepository <GeneralSettings> settingsRepository, ISettingsRepository <FancyZonesSettings> moduleSettingsRepository, Func <string, int> ipcMSGCallBackFunc, string configFileSubfolder = "")
        {
            // To obtain the general settings configurations of PowerToys Settings.
            GeneralSettingsConfig    = settingsRepository.SettingsConfig;
            settingsConfigFileFolder = configFileSubfolder;

            // To obtain the settings configurations of Fancy zones.
            Settings = moduleSettingsRepository.SettingsConfig;

            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";

            _isEnabled = GeneralSettingsConfig.Enabled.FancyZones;
        }
Ejemplo n.º 5
0
        public GeneralViewModel(ISettingsUtils settingsUtils, ISettingsRepository <GeneralSettings> settingsRepository, 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));

            // To obtain the general settings configuration of PowerToys if it exists, else to create a new file and return the default configurations.
            GeneralSettingsConfig = settingsRepository.SettingsConfig;

            // 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(GeneralSettingsConfig.Theme.ToLower());

            // Update Settings file folder:
            _settingsConfigFileFolder = configFileSubfolder;

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

            case "dark":
                _isDarkThemeRadioButtonChecked = true;
                break;

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

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

            RunningAsUserDefaultText  = runAsUserText;
            RunningAsAdminDefaultText = runAsAdminText;

            _isAdmin = isAdmin;
        }
        public SettingsConfigurationViewModel()
        {
            ChangeLocationButton = new ButtonClickCommand(this.ChangeBackupLocationClickEvent);

            SyncFromConfiguration();
        }
Ejemplo n.º 7
0
        public FancyZonesViewModel(Func <string, int> ipcMSGCallBackFunc, string configFileSubfolder = "")
        {
            settingsConfigFileFolder = configFileSubfolder;

            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;
            _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.º 8
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.º 9
0
 private void OnButtonClick()
 {
     this.ButtonClick?.Invoke(this, EventArgs.Empty);
     ButtonClickCommand?.Execute(null);
 }
Ejemplo n.º 10
0
        public GeneralViewModel()
        {
            this.CheckFoUpdatesEventHandler        = new ButtonClickCommand(CheckForUpdates_Click);
            this.RestartElevatedButtonEventHandler = new ButtonClickCommand(Restart_Elevated);

            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);
            }

            switch (GeneralSettingsConfigs.Theme.ToLower())
            {
            case "light":
                _isLightThemeRadioButtonChecked = true;
                try
                {
                    ShellPage.ShellHandler.RequestedTheme = ElementTheme.Light;
                }
                catch
                {
                }

                break;

            case "dark":
                _isDarkThemeRadioButtonChecked = true;
                try
                {
                    ShellPage.ShellHandler.RequestedTheme = ElementTheme.Dark;
                }
                catch
                {
                }

                break;

            case "system":
                _isSystemThemeRadioButtonChecked = true;
                try
                {
                    ShellPage.ShellHandler.RequestedTheme = ElementTheme.Default;
                }
                catch
                {
                }

                break;
            }

            _startup             = GeneralSettingsConfigs.Startup;
            _autoDownloadUpdates = GeneralSettingsConfigs.AutoDownloadUpdates;
            _isElevated          = ShellPage.IsElevated;
            _runElevated         = GeneralSettingsConfigs.RunElevated;
            _isAdmin             = ShellPage.IsUserAnAdmin;
        }
Ejemplo n.º 11
0
        public GeneralViewModel(ISettingsRepository <GeneralSettings> settingsRepository, 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 = "", Action dispatcherAction = null)
        {
            CheckForUpdatesEventHandler       = new ButtonClickCommand(CheckForUpdatesClick);
            RestartElevatedButtonEventHandler = new ButtonClickCommand(RestartElevated);
            UpdateNowButtonEventHandler       = new ButtonClickCommand(UpdateNowClick);

            // To obtain the general settings configuration of PowerToys if it exists, else to create a new file and return the default configurations.
            if (settingsRepository == null)
            {
                throw new ArgumentNullException(nameof(settingsRepository));
            }

            GeneralSettingsConfig  = settingsRepository.SettingsConfig;
            UpdatingSettingsConfig = UpdatingSettings.LoadSettings();
            if (UpdatingSettingsConfig == null)
            {
                UpdatingSettingsConfig = new UpdatingSettings();
            }

            // 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(GeneralSettingsConfig.Theme);

            // Update Settings file folder:
            _settingsConfigFileFolder = configFileSubfolder;

            // Using Invariant here as these are internal strings and fxcop
            // expects strings to be normalized to uppercase. While the theme names
            // are represented in lowercase everywhere else, we'll use uppercase
            // normalization for switch statements
            switch (GeneralSettingsConfig.Theme.ToUpperInvariant())
            {
            case "DARK":
                _themeIndex = 0;
                break;

            case "LIGHT":
                _themeIndex = 1;
                break;

            case "SYSTEM":
                _themeIndex = 2;
                break;
            }

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

            RunningAsUserDefaultText  = runAsUserText;
            RunningAsAdminDefaultText = runAsAdminText;

            _isAdmin = isAdmin;

            _updatingState           = UpdatingSettingsConfig.State;
            _newAvailableVersion     = UpdatingSettingsConfig.NewVersion;
            _newAvailableVersionLink = UpdatingSettingsConfig.ReleasePageLink;
            _updateCheckedDate       = UpdatingSettingsConfig.LastCheckedDateLocalized;

            if (dispatcherAction != null)
            {
                _fileWatcher = Helper.GetFileWatcher(string.Empty, UpdatingSettings.SettingsFile, dispatcherAction);
            }
        }
Ejemplo n.º 12
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;
        }