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-10-29 14:24:16 -07:00
using System.Diagnostics.CodeAnalysis ;
using System.Globalization ;
2020-10-22 09:45:48 -07:00
using Microsoft.PowerToys.Settings.UI.Library ;
using Microsoft.PowerToys.Settings.UI.Library.Utilities ;
using Microsoft.PowerToys.Settings.UI.Library.ViewModels ;
2020-08-13 15:02:05 -07:00
using Windows.ApplicationModel.Resources ;
2020-09-04 11:56:52 +03:00
using Windows.Data.Json ;
2021-05-21 13:32:34 +03:00
using Windows.UI.Core ;
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-10-29 14:24:16 -07:00
[SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Exceptions from the IPC response handler should be caught and logged.")]
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-11-02 18:33:43 +01:00
var settingsUtils = new SettingsUtils ( ) ;
2020-08-13 15:02:05 -07:00
2021-05-21 13:32:34 +03:00
Action stateUpdatingAction = async ( ) = >
{
await Dispatcher . RunAsync ( CoreDispatcherPriority . Normal , ViewModel . RefreshUpdatingState ) ;
} ;
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 ,
2021-05-21 13:32:34 +03:00
ShellPage . SendCheckForUpdatesIPCMessage ,
string . Empty ,
stateUpdatingAction ) ;
2020-09-04 11:56:52 +03:00
2020-08-13 15:02:05 -07:00
DataContext = ViewModel ;
}
2020-10-29 14:24:16 -07:00
public static int UpdateUIThemeMethod ( string themeName )
2020-08-13 15:02:05 -07:00
{
2020-10-29 14:24:16 -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 ;
2020-10-29 14:24:16 -07:00
default :
Logger . LogError ( $"Unexpected theme name: {themeName}" ) ;
break ;
2020-08-13 15:02:05 -07:00
}
return 0 ;
2020-03-24 19:55:02 -07:00
}
2021-02-09 14:11:51 +03:00
private void OpenColorsSettings_Click ( object sender , RoutedEventArgs e )
{
Helpers . StartProcessHelper . Start ( Helpers . StartProcessHelper . ColorsSettings ) ;
}
2020-03-12 07:25:24 +01:00
}
2020-04-02 06:08:56 -07:00
}