2020-04-07 10:19:14 -07: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 11:56:52 +03:00
|
|
|
using System;
|
2020-09-21 10:14:44 -07:00
|
|
|
using Microsoft.PowerToys.Settings.UI.Lib;
|
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Lib.Utilities;
|
2020-08-13 15:02:05 -07:00
|
|
|
using Microsoft.PowerToys.Settings.UI.Lib.ViewModels;
|
|
|
|
|
using Windows.ApplicationModel.Resources;
|
2020-09-04 11:56:52 +03:00
|
|
|
using Windows.Data.Json;
|
2020-08-13 15:02:05 -07:00
|
|
|
using Windows.UI.Xaml;
|
2020-04-07 10:19:14 -07:00
|
|
|
using Windows.UI.Xaml.Controls;
|
2020-03-12 07:25:24 +01:00
|
|
|
|
|
|
|
|
namespace Microsoft.PowerToys.Settings.UI.Views
|
|
|
|
|
{
|
2020-03-24 19:55:02 -07:00
|
|
|
/// <summary>
|
|
|
|
|
/// General Settings Page.
|
|
|
|
|
/// </summary>
|
2020-03-12 07:25:24 +01:00
|
|
|
public sealed partial class GeneralPage : Page
|
|
|
|
|
{
|
2020-03-24 19:55:02 -07:00
|
|
|
/// <summary>
|
2020-04-17 15:25:08 -07:00
|
|
|
/// Gets or sets view model.
|
2020-03-24 19:55:02 -07:00
|
|
|
/// </summary>
|
2020-04-17 15:25:08 -07:00
|
|
|
public GeneralViewModel ViewModel { get; set; }
|
2020-03-12 07:25:24 +01:00
|
|
|
|
2020-03-24 19:55:02 -07:00
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="GeneralPage"/> class.
|
|
|
|
|
/// General Settings page constructor.
|
|
|
|
|
/// </summary>
|
2020-03-12 07:25:24 +01:00
|
|
|
public GeneralPage()
|
|
|
|
|
{
|
2020-08-19 15:59:10 -07:00
|
|
|
InitializeComponent();
|
2020-03-24 19:55:02 -07:00
|
|
|
|
2020-08-13 15:02:05 -07:00
|
|
|
// Load string resources
|
|
|
|
|
ResourceLoader loader = ResourceLoader.GetForViewIndependentUse();
|
2020-09-21 10:14:44 -07:00
|
|
|
var settingsUtils = new SettingsUtils(new SystemIOProvider());
|
2020-08-13 15:02:05 -07:00
|
|
|
|
2020-08-19 15:59:10 -07:00
|
|
|
ViewModel = new GeneralViewModel(
|
2020-09-23 13:20:32 -07:00
|
|
|
SettingsRepository<GeneralSettings>.GetInstance(settingsUtils),
|
2020-08-13 15:02:05 -07:00
|
|
|
loader.GetString("GeneralSettings_RunningAsAdminText"),
|
|
|
|
|
loader.GetString("GeneralSettings_RunningAsUserText"),
|
|
|
|
|
ShellPage.IsElevated,
|
|
|
|
|
ShellPage.IsUserAnAdmin,
|
|
|
|
|
UpdateUIThemeMethod,
|
|
|
|
|
ShellPage.SendDefaultIPCMessage,
|
|
|
|
|
ShellPage.SendRestartAdminIPCMessage,
|
|
|
|
|
ShellPage.SendCheckForUpdatesIPCMessage);
|
|
|
|
|
|
2020-09-04 11:56:52 +03: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-13 15:02:05 -07:00
|
|
|
DataContext = ViewModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int UpdateUIThemeMethod(string themeName)
|
|
|
|
|
{
|
2020-10-19 13:32:05 -07:00
|
|
|
switch (themeName.ToUpperInvariant())
|
2020-08-13 15:02:05 -07:00
|
|
|
{
|
2020-10-19 13:32:05 -07:00
|
|
|
case "LIGHT":
|
2020-08-13 15:02:05 -07:00
|
|
|
ShellPage.ShellHandler.RequestedTheme = ElementTheme.Light;
|
|
|
|
|
break;
|
2020-10-19 13:32:05 -07:00
|
|
|
case "DARK":
|
2020-08-13 15:02:05 -07:00
|
|
|
ShellPage.ShellHandler.RequestedTheme = ElementTheme.Dark;
|
|
|
|
|
break;
|
2020-10-19 13:32:05 -07:00
|
|
|
case "SYSTEM":
|
2020-08-13 15:02:05 -07:00
|
|
|
ShellPage.ShellHandler.RequestedTheme = ElementTheme.Default;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
2020-03-24 19:55:02 -07:00
|
|
|
}
|
2020-03-12 07:25:24 +01:00
|
|
|
}
|
2020-04-02 06:08:56 -07:00
|
|
|
}
|