2020-04-08 01:19:14 +08:00
|
|
|
// Copyright (c) Microsoft Corporation
|
|
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
|
2020-09-04 16:56:52 +08:00
|
|
|
using System;
|
2020-10-30 05:24:16 +08:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2020-10-23 00:45:48 +08:00
|
|
|
using Microsoft.PowerToys.Settings.UI.Library;
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Library.ViewModels;
|
2022-04-20 04:00:28 +08:00
|
|
|
using Microsoft.UI.Xaml;
|
|
|
|
using Microsoft.UI.Xaml.Controls;
|
2020-08-14 06:02:05 +08:00
|
|
|
using Windows.ApplicationModel.Resources;
|
2021-05-21 18:32:34 +08:00
|
|
|
using Windows.UI.Core;
|
2020-03-12 14:25:24 +08:00
|
|
|
|
|
|
|
namespace Microsoft.PowerToys.Settings.UI.Views
|
|
|
|
{
|
2020-03-25 10:55:02 +08:00
|
|
|
/// <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>
|
2020-04-18 06:25:08 +08:00
|
|
|
/// Gets or sets view model.
|
2020-03-25 10:55:02 +08:00
|
|
|
/// </summary>
|
2020-04-18 06:25:08 +08:00
|
|
|
public GeneralViewModel ViewModel { get; set; }
|
2020-03-12 14:25:24 +08:00
|
|
|
|
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()
|
|
|
|
{
|
2020-08-20 06:59:10 +08:00
|
|
|
InitializeComponent();
|
2020-03-25 10:55:02 +08:00
|
|
|
|
2020-08-14 06:02:05 +08:00
|
|
|
// Load string resources
|
|
|
|
ResourceLoader loader = ResourceLoader.GetForViewIndependentUse();
|
2020-11-03 01:33:43 +08:00
|
|
|
var settingsUtils = new SettingsUtils();
|
2020-08-14 06:02:05 +08:00
|
|
|
|
2022-04-20 04:00:28 +08:00
|
|
|
Action stateUpdatingAction = () =>
|
2021-05-21 18:32:34 +08:00
|
|
|
{
|
2022-04-20 04:00:28 +08:00
|
|
|
this.DispatcherQueue.TryEnqueue(() =>
|
|
|
|
{
|
|
|
|
ViewModel.RefreshUpdatingState();
|
|
|
|
});
|
2021-05-21 18:32:34 +08:00
|
|
|
};
|
|
|
|
|
2020-08-20 06:59:10 +08:00
|
|
|
ViewModel = new GeneralViewModel(
|
2020-09-24 04:20:32 +08:00
|
|
|
SettingsRepository<GeneralSettings>.GetInstance(settingsUtils),
|
2020-08-14 06:02:05 +08:00
|
|
|
loader.GetString("GeneralSettings_RunningAsAdminText"),
|
|
|
|
loader.GetString("GeneralSettings_RunningAsUserText"),
|
|
|
|
ShellPage.IsElevated,
|
|
|
|
ShellPage.IsUserAnAdmin,
|
|
|
|
UpdateUIThemeMethod,
|
|
|
|
ShellPage.SendDefaultIPCMessage,
|
|
|
|
ShellPage.SendRestartAdminIPCMessage,
|
2021-05-21 18:32:34 +08:00
|
|
|
ShellPage.SendCheckForUpdatesIPCMessage,
|
|
|
|
string.Empty,
|
|
|
|
stateUpdatingAction);
|
2020-09-04 16:56:52 +08:00
|
|
|
|
2020-08-14 06:02:05 +08:00
|
|
|
DataContext = ViewModel;
|
|
|
|
}
|
|
|
|
|
2020-10-30 05:24:16 +08:00
|
|
|
public static int UpdateUIThemeMethod(string themeName)
|
2020-08-14 06:02:05 +08:00
|
|
|
{
|
2020-10-30 05:24:16 +08:00
|
|
|
switch (themeName?.ToUpperInvariant())
|
2020-08-14 06:02:05 +08:00
|
|
|
{
|
2020-10-20 04:32:05 +08:00
|
|
|
case "LIGHT":
|
2020-08-14 06:02:05 +08:00
|
|
|
ShellPage.ShellHandler.RequestedTheme = ElementTheme.Light;
|
|
|
|
break;
|
2020-10-20 04:32:05 +08:00
|
|
|
case "DARK":
|
2020-08-14 06:02:05 +08:00
|
|
|
ShellPage.ShellHandler.RequestedTheme = ElementTheme.Dark;
|
|
|
|
break;
|
2020-10-20 04:32:05 +08:00
|
|
|
case "SYSTEM":
|
2020-08-14 06:02:05 +08:00
|
|
|
ShellPage.ShellHandler.RequestedTheme = ElementTheme.Default;
|
|
|
|
break;
|
2020-10-30 05:24:16 +08:00
|
|
|
default:
|
|
|
|
Logger.LogError($"Unexpected theme name: {themeName}");
|
|
|
|
break;
|
2020-08-14 06:02:05 +08:00
|
|
|
}
|
|
|
|
|
2022-07-01 17:52:48 +08:00
|
|
|
App.HandleThemeChange();
|
2020-08-14 06:02:05 +08:00
|
|
|
return 0;
|
2020-03-25 10:55:02 +08:00
|
|
|
}
|
2021-02-09 19:11:51 +08:00
|
|
|
|
|
|
|
private void OpenColorsSettings_Click(object sender, RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
Helpers.StartProcessHelper.Start(Helpers.StartProcessHelper.ColorsSettings);
|
|
|
|
}
|
2020-03-12 14:25:24 +08:00
|
|
|
}
|
2020-04-02 21:08:56 +08:00
|
|
|
}
|