2020-03-30 17:02:25 +08:00
|
|
|
// <copyright file="GeneralPage.xaml.cs" company="Microsoft Corp">
|
2020-03-25 10:55:02 +08:00
|
|
|
// Copyright (c) Microsoft Corp. All rights reserved.
|
|
|
|
// </copyright>
|
2020-03-12 14:25:24 +08:00
|
|
|
|
|
|
|
namespace Microsoft.PowerToys.Settings.UI.Views
|
|
|
|
{
|
2020-03-25 10:55:02 +08:00
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Lib;
|
|
|
|
using Microsoft.PowerToys.Settings.UI.ViewModels;
|
2020-03-31 20:32:22 +08:00
|
|
|
using Windows.System;
|
2020-03-25 10:55:02 +08:00
|
|
|
using Windows.UI.Popups;
|
|
|
|
using Windows.UI.Xaml;
|
|
|
|
using Windows.UI.Xaml.Controls;
|
|
|
|
using Windows.UI.Xaml.Navigation;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// General Settings Page.
|
|
|
|
/// </summary>
|
2020-03-12 14:25:24 +08:00
|
|
|
public sealed partial class GeneralPage : Page
|
|
|
|
{
|
2020-03-25 10:55:02 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Gets view model.
|
|
|
|
/// </summary>
|
2020-03-12 14:25:24 +08:00
|
|
|
public GeneralViewModel ViewModel { get; } = new GeneralViewModel();
|
|
|
|
|
2020-03-25 10:55:02 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="GeneralPage"/> class.
|
|
|
|
/// General Settings page constructor.
|
|
|
|
/// </summary>
|
2020-03-12 14:25:24 +08:00
|
|
|
public GeneralPage()
|
|
|
|
{
|
|
|
|
this.InitializeComponent();
|
|
|
|
}
|
2020-04-02 21:08:56 +08:00
|
|
|
|
2020-03-25 10:55:02 +08:00
|
|
|
/// <inheritdoc/>
|
|
|
|
protected override void OnNavigatedTo(NavigationEventArgs e)
|
|
|
|
{
|
|
|
|
base.OnNavigatedTo(e);
|
2020-03-30 17:02:25 +08:00
|
|
|
GeneralSettings settings = null;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// get settings file if they exist.
|
|
|
|
settings = SettingsUtils.GetSettings<GeneralSettings>(string.Empty);
|
|
|
|
// load and apply theme settings
|
|
|
|
this.ReLoadTheme(settings.theme);
|
|
|
|
|
|
|
|
// load run on start-up settings value and update the ui state.
|
|
|
|
this.ToggleSwitch_RunAtStartUp.IsOn = settings.startup;
|
|
|
|
}
|
|
|
|
catch (Exception exp)
|
|
|
|
{
|
|
|
|
// create settings file if one is not found.
|
|
|
|
settings = new GeneralSettings();
|
2020-04-02 21:08:56 +08:00
|
|
|
SettingsUtils.SaveSettings(settings.ToJsonString(), string.Empty);
|
2020-03-30 17:02:25 +08:00
|
|
|
// load and apply theme settings
|
|
|
|
this.ReLoadTheme(settings.theme);
|
|
|
|
|
|
|
|
// load run on start up ui settings value and update the ui state.
|
|
|
|
this.ToggleSwitch_RunAtStartUp.IsOn = settings.startup;
|
|
|
|
}
|
2020-03-25 10:55:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Update and save theme settings to json file.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="themeName">theme name.</param>
|
|
|
|
private void ReLoadTheme(string themeName)
|
|
|
|
{
|
|
|
|
switch (themeName.ToLower())
|
|
|
|
{
|
|
|
|
case "light":
|
|
|
|
ShellPage.ShellHandler.RequestedTheme = ElementTheme.Light;
|
2020-03-31 20:32:22 +08:00
|
|
|
this.Radio_Theme_Light.IsChecked = true;
|
2020-03-25 10:55:02 +08:00
|
|
|
break;
|
|
|
|
case "dark":
|
|
|
|
ShellPage.ShellHandler.RequestedTheme = ElementTheme.Dark;
|
2020-03-31 20:32:22 +08:00
|
|
|
this.Radio_Theme_Dark.IsChecked = true;
|
2020-03-25 10:55:02 +08:00
|
|
|
break;
|
|
|
|
case "system":
|
|
|
|
ShellPage.ShellHandler.RequestedTheme = ElementTheme.Default;
|
2020-03-31 20:32:22 +08:00
|
|
|
this.Radio_Theme_Default.IsChecked = true;
|
2020-03-25 10:55:02 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ToggleSwitch_RunAtStartUp_Toggled(object sender, RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
ToggleSwitch swt = sender as ToggleSwitch;
|
|
|
|
|
|
|
|
if (swt != null)
|
|
|
|
{
|
|
|
|
GeneralSettings settings = SettingsUtils.GetSettings<GeneralSettings>(string.Empty);
|
|
|
|
|
|
|
|
string startup = swt.IsOn.ToString().ToLower();
|
|
|
|
switch (startup)
|
|
|
|
{
|
|
|
|
case "true":
|
|
|
|
settings.startup = true;
|
|
|
|
break;
|
|
|
|
case "false":
|
|
|
|
settings.startup = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-04-02 21:08:56 +08:00
|
|
|
SettingsUtils.SaveSettings(settings.ToJsonString(), string.Empty);
|
2020-03-25 10:55:02 +08:00
|
|
|
OutGoingGeneralSettings outsettings = new OutGoingGeneralSettings(settings);
|
|
|
|
|
2020-03-30 17:02:25 +08:00
|
|
|
if (ShellPage.Default_SndMSG_Callback != null)
|
2020-03-25 10:55:02 +08:00
|
|
|
{
|
2020-03-30 17:02:25 +08:00
|
|
|
ShellPage.Default_SndMSG_Callback(outsettings.ToString());
|
2020-03-25 10:55:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Restart_Elevated(object sender, RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
GeneralSettings settings = SettingsUtils.GetSettings<GeneralSettings>(string.Empty);
|
|
|
|
settings.run_elevated = true;
|
|
|
|
OutGoingGeneralSettings outsettings = new OutGoingGeneralSettings(settings);
|
|
|
|
|
2020-03-30 17:02:25 +08:00
|
|
|
if (ShellPage.Default_SndMSG_Callback != null)
|
2020-03-25 10:55:02 +08:00
|
|
|
{
|
2020-03-30 17:02:25 +08:00
|
|
|
ShellPage.Default_SndMSG_Callback(outsettings.ToString());
|
2020-03-25 10:55:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Theme_Changed(object sender, RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
RadioButton rb = sender as RadioButton;
|
|
|
|
|
2020-04-02 21:08:56 +08:00
|
|
|
if (rb != null)
|
|
|
|
{
|
|
|
|
string themeName = rb.Tag.ToString();
|
|
|
|
this.ReLoadTheme(themeName);
|
2020-03-25 10:55:02 +08:00
|
|
|
|
2020-04-02 21:08:56 +08:00
|
|
|
// update and save settings to file.
|
|
|
|
GeneralSettings settings = SettingsUtils.GetSettings<GeneralSettings>(string.Empty);
|
|
|
|
settings.theme = themeName;
|
|
|
|
SettingsUtils.SaveSettings(settings.ToJsonString(), string.Empty);
|
|
|
|
}
|
2020-03-31 20:32:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private async void CheckForUpdates_Click(object sender, RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
await Launcher.LaunchUriAsync(new Uri("https://github.com/microsoft/PowerToys/releases"));
|
2020-03-25 10:55:02 +08:00
|
|
|
}
|
2020-03-12 14:25:24 +08:00
|
|
|
}
|
2020-04-02 21:08:56 +08:00
|
|
|
}
|