mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 04:37:30 +02:00
common: refactor common library pt2 (#8588)
- remove common lib - split settings, remove common-md - move ipc interop/kb_layout to interop - rename core -> settings, settings -> old_settings - os-detect header-only; interop -> PowerToysInterop - split notifications, move single-use headers where they're used - winstore lib - rename com utils - rename Updating and Telemetry projects - rename core -> settings-ui and remove examples folder - rename settings-ui folder + consisent common/version include
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
// 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 System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.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>
|
||||
[SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Exceptions from the IPC response handler should be caught and logged.")]
|
||||
public GeneralPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
// Load string resources
|
||||
ResourceLoader loader = ResourceLoader.GetForViewIndependentUse();
|
||||
var settingsUtils = new SettingsUtils();
|
||||
|
||||
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 (!string.IsNullOrEmpty(version))
|
||||
{
|
||||
str = ResourceLoader.GetForCurrentView().GetString("GeneralSettings_NewVersionIsAvailable");
|
||||
if (!string.IsNullOrEmpty(str))
|
||||
{
|
||||
str += ": " + version;
|
||||
}
|
||||
}
|
||||
|
||||
// Using CurrentCulture since this is user-facing
|
||||
ViewModel.LatestAvailableVersion = string.Format(CultureInfo.CurrentCulture, str);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogError("Exception encountered when reading the version.", e);
|
||||
}
|
||||
});
|
||||
|
||||
DataContext = ViewModel;
|
||||
}
|
||||
|
||||
public static 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;
|
||||
default:
|
||||
Logger.LogError($"Unexpected theme name: {themeName}");
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user