mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
* Suppress warnings for read-only collection properties (see code comments) * Call ConfigureAwait on tasks * Add CultureInfo and StringComparison policy for certain string operations * Add checks and exceptions for null arguments to public methods * Rename RaisePropertyChanged to NotifyPropertyChanged * Suppress CA1000 warning on SettingsRepository class * Implement Disposable pattern in HotkeySettingsControlHook * Modify null argument handling in KeyboardManagerViewModel::CombineShortcutLists
99 lines
3.4 KiB
C#
99 lines
3.4 KiB
C#
// 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.
|
|
|
|
using System;
|
|
using Microsoft.PowerToys.Settings.UI.Lib;
|
|
using Microsoft.PowerToys.Settings.UI.Lib.Utilities;
|
|
using Microsoft.PowerToys.Settings.UI.Lib.ViewModels;
|
|
using Windows.ApplicationModel.Resources;
|
|
using Windows.Data.Json;
|
|
using Windows.UI.Xaml;
|
|
using Windows.UI.Xaml.Controls;
|
|
|
|
namespace Microsoft.PowerToys.Settings.UI.Views
|
|
{
|
|
/// <summary>
|
|
/// General Settings Page.
|
|
/// </summary>
|
|
public sealed partial class GeneralPage : Page
|
|
{
|
|
/// <summary>
|
|
/// Gets or sets view model.
|
|
/// </summary>
|
|
public GeneralViewModel ViewModel { get; set; }
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="GeneralPage"/> class.
|
|
/// General Settings page constructor.
|
|
/// </summary>
|
|
public GeneralPage()
|
|
{
|
|
InitializeComponent();
|
|
|
|
// Load string resources
|
|
ResourceLoader loader = ResourceLoader.GetForViewIndependentUse();
|
|
var settingsUtils = new SettingsUtils(new SystemIOProvider());
|
|
|
|
ViewModel = new GeneralViewModel(
|
|
SettingsRepository<GeneralSettings>.GetInstance(settingsUtils),
|
|
loader.GetString("GeneralSettings_RunningAsAdminText"),
|
|
loader.GetString("GeneralSettings_RunningAsUserText"),
|
|
ShellPage.IsElevated,
|
|
ShellPage.IsUserAnAdmin,
|
|
UpdateUIThemeMethod,
|
|
ShellPage.SendDefaultIPCMessage,
|
|
ShellPage.SendRestartAdminIPCMessage,
|
|
ShellPage.SendCheckForUpdatesIPCMessage);
|
|
|
|
ShellPage.ShellHandler.IPCResponseHandleList.Add((JsonObject json) =>
|
|
{
|
|
try
|
|
{
|
|
string version = json.GetNamedString("version");
|
|
bool isLatest = json.GetNamedBoolean("isVersionLatest");
|
|
|
|
var str = string.Empty;
|
|
if (isLatest)
|
|
{
|
|
str = ResourceLoader.GetForCurrentView().GetString("GeneralSettings_VersionIsLatest");
|
|
}
|
|
else if (version != string.Empty)
|
|
{
|
|
str = ResourceLoader.GetForCurrentView().GetString("GeneralSettings_NewVersionIsAvailable");
|
|
if (str != string.Empty)
|
|
{
|
|
str += ": " + version;
|
|
}
|
|
}
|
|
|
|
ViewModel.LatestAvailableVersion = string.Format(str);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
});
|
|
|
|
DataContext = ViewModel;
|
|
}
|
|
|
|
public int UpdateUIThemeMethod(string themeName)
|
|
{
|
|
switch (themeName.ToUpperInvariant())
|
|
{
|
|
case "LIGHT":
|
|
ShellPage.ShellHandler.RequestedTheme = ElementTheme.Light;
|
|
break;
|
|
case "DARK":
|
|
ShellPage.ShellHandler.RequestedTheme = ElementTheme.Dark;
|
|
break;
|
|
case "SYSTEM":
|
|
ShellPage.ShellHandler.RequestedTheme = ElementTheme.Default;
|
|
break;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
}
|
|
}
|