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; }
public GeneralViewModel(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 = "") { 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); } // 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; }