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-09-22 01:14:44 +08:00
|
|
|
using Microsoft.PowerToys.Settings.UI.Lib;
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Lib.Utilities;
|
2020-08-14 06:02:05 +08:00
|
|
|
using Microsoft.PowerToys.Settings.UI.Lib.ViewModels;
|
|
|
|
using Windows.ApplicationModel.Resources;
|
2020-09-04 16:56:52 +08:00
|
|
|
using Windows.Data.Json;
|
2020-08-14 06:02:05 +08:00
|
|
|
using Windows.UI.Xaml;
|
2020-04-08 01:19:14 +08:00
|
|
|
using Windows.UI.Xaml.Controls;
|
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-09-22 01:14:44 +08:00
|
|
|
var settingsUtils = new SettingsUtils(new SystemIOProvider());
|
2020-08-14 06:02:05 +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,
|
|
|
|
ShellPage.SendCheckForUpdatesIPCMessage);
|
|
|
|
|
2020-09-04 16:56:52 +08:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-08-14 06:02:05 +08:00
|
|
|
DataContext = ViewModel;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int UpdateUIThemeMethod(string themeName)
|
|
|
|
{
|
2020-10-20 04:32:05 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2020-03-25 10:55:02 +08:00
|
|
|
}
|
2020-03-12 14:25:24 +08:00
|
|
|
}
|
2020-04-02 21:08:56 +08:00
|
|
|
}
|