summaryrefslogtreecommitdiffstats
path: root/win/CS
diff options
context:
space:
mode:
authorsr55 <[email protected]>2021-01-23 21:24:37 +0000
committersr55 <[email protected]>2021-01-23 21:24:37 +0000
commit781749e9634b7fd4468d1c456c0059f80c06a404 (patch)
tree9310617f88b0d076b129f8b5e3d2f2ca1e63a218 /win/CS
parenta97930bcc92ff088c38c438802f902063b5b9cfd (diff)
WinGui: Extend the dark theme option to be able to honour OS "AppsUseLightTheme" setting. #3369
Diffstat (limited to 'win/CS')
-rw-r--r--win/CS/HandBrakeWPF/App.xaml.cs24
-rw-r--r--win/CS/HandBrakeWPF/Converters/Options/ThemeSettingConverter.cs19
-rw-r--r--win/CS/HandBrakeWPF/Converters/ResourceConverterBase.cs4
-rw-r--r--win/CS/HandBrakeWPF/Converters/ThemeImageConverter.cs16
-rw-r--r--win/CS/HandBrakeWPF/Model/DarkThemeMode.cs24
-rw-r--r--win/CS/HandBrakeWPF/Properties/Resources.Designer.cs45
-rw-r--r--win/CS/HandBrakeWPF/Properties/Resources.resx15
-rw-r--r--win/CS/HandBrakeWPF/Services/UserSettingService.cs3
-rw-r--r--win/CS/HandBrakeWPF/UserSettingConstants.cs2
-rw-r--r--win/CS/HandBrakeWPF/Utilities/SystemInfo.cs11
-rw-r--r--win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs18
-rw-r--r--win/CS/HandBrakeWPF/Views/OptionsView.xaml9
12 files changed, 164 insertions, 26 deletions
diff --git a/win/CS/HandBrakeWPF/App.xaml.cs b/win/CS/HandBrakeWPF/App.xaml.cs
index a7c0fad9a..bbca2024e 100644
--- a/win/CS/HandBrakeWPF/App.xaml.cs
+++ b/win/CS/HandBrakeWPF/App.xaml.cs
@@ -30,6 +30,8 @@ namespace HandBrakeWPF
using HandBrakeWPF.ViewModels;
using HandBrakeWPF.ViewModels.Interfaces;
+ using Microsoft.Win32;
+
using GeneralApplicationException = Exceptions.GeneralApplicationException;
/// <summary>
@@ -119,12 +121,26 @@ namespace HandBrakeWPF
}
}
- bool useDarkTheme = userSettingService.GetUserSetting<bool>(UserSettingConstants.UseDarkTheme);
- if (useDarkTheme && SystemInfo.IsWindows10())
+ DarkThemeMode useDarkTheme = (DarkThemeMode)userSettingService.GetUserSetting<int>(UserSettingConstants.DarkThemeMode);
+ if (SystemInfo.IsWindows10())
{
ResourceDictionary darkTheme = new ResourceDictionary();
- darkTheme.Source = new Uri("Themes/Dark.xaml", UriKind.Relative);
- Application.Current.Resources.MergedDictionaries.Add(darkTheme);
+ switch (useDarkTheme)
+ {
+ case DarkThemeMode.System:
+ if (SystemInfo.IsAppsUsingDarkTheme())
+ {
+ darkTheme.Source = new Uri("Themes/Dark.xaml", UriKind.Relative);
+ Application.Current.Resources.MergedDictionaries.Add(darkTheme);
+ }
+ break;
+ case DarkThemeMode.Dark:
+ darkTheme.Source = new Uri("Themes/Dark.xaml", UriKind.Relative);
+ Application.Current.Resources.MergedDictionaries.Add(darkTheme);
+ break;
+ default:
+ break;
+ }
}
// NO-Hardware Mode
diff --git a/win/CS/HandBrakeWPF/Converters/Options/ThemeSettingConverter.cs b/win/CS/HandBrakeWPF/Converters/Options/ThemeSettingConverter.cs
new file mode 100644
index 000000000..53c44e958
--- /dev/null
+++ b/win/CS/HandBrakeWPF/Converters/Options/ThemeSettingConverter.cs
@@ -0,0 +1,19 @@
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="ThemeSettingConverter.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// Defines the ThemeSettingConverter type.
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Converters.Options
+{
+ using System.Windows.Data;
+
+ using HandBrakeWPF.Model;
+
+ public class ThemeSettingConverter : ResourceConverterBase<DarkThemeMode>, IValueConverter
+ {
+ }
+}
diff --git a/win/CS/HandBrakeWPF/Converters/ResourceConverterBase.cs b/win/CS/HandBrakeWPF/Converters/ResourceConverterBase.cs
index 7f1a1b433..50cfb7640 100644
--- a/win/CS/HandBrakeWPF/Converters/ResourceConverterBase.cs
+++ b/win/CS/HandBrakeWPF/Converters/ResourceConverterBase.cs
@@ -10,14 +10,10 @@
namespace HandBrakeWPF.Converters
{
using System;
- using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using HandBrakeWPF.Model.Options;
using HandBrakeWPF.Utilities;
public class ResourceConverterBase<T>
diff --git a/win/CS/HandBrakeWPF/Converters/ThemeImageConverter.cs b/win/CS/HandBrakeWPF/Converters/ThemeImageConverter.cs
index 78b06c622..cc25401c6 100644
--- a/win/CS/HandBrakeWPF/Converters/ThemeImageConverter.cs
+++ b/win/CS/HandBrakeWPF/Converters/ThemeImageConverter.cs
@@ -12,11 +12,11 @@ namespace HandBrakeWPF.Converters
using System;
using System.Globalization;
using System.Linq;
- using System.Threading;
using System.Windows.Data;
using Caliburn.Micro;
+ using HandBrakeWPF.Model;
using HandBrakeWPF.Services.Interfaces;
public class ThemeImageConverter : IValueConverter
@@ -28,7 +28,12 @@ namespace HandBrakeWPF.Converters
public ThemeImageConverter()
{
this.userSettingService = IoC.Get<IUserSettingService>();
- this.isDarkTheme = this.userSettingService.GetUserSetting<bool>(UserSettingConstants.UseDarkTheme);
+ DarkThemeMode mode = (DarkThemeMode)this.userSettingService.GetUserSetting<int>(UserSettingConstants.DarkThemeMode);
+
+ if (mode == DarkThemeMode.Dark || (mode == DarkThemeMode.System && Utilities.SystemInfo.IsAppsUsingDarkTheme()))
+ {
+ this.isDarkTheme = true;
+ }
}
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
@@ -36,7 +41,6 @@ namespace HandBrakeWPF.Converters
string image = parameter as string;
if (!string.IsNullOrEmpty(image))
{
-
string direcotry = "Images/";
if (image.Contains("/"))
{
@@ -50,10 +54,8 @@ namespace HandBrakeWPF.Converters
{
return direcotry + "Dark/" + image;
}
- else
- {
- return direcotry + "Light/" + image;
- }
+
+ return direcotry + "Light/" + image;
}
return null;
diff --git a/win/CS/HandBrakeWPF/Model/DarkThemeMode.cs b/win/CS/HandBrakeWPF/Model/DarkThemeMode.cs
new file mode 100644
index 000000000..da5a50a23
--- /dev/null
+++ b/win/CS/HandBrakeWPF/Model/DarkThemeMode.cs
@@ -0,0 +1,24 @@
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="DarkThemeMode.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Model
+{
+ using HandBrake.Interop.Attributes;
+
+ using HandBrakeWPF.Properties;
+
+ public enum DarkThemeMode
+ {
+ [DisplayName(typeof(Resources), "DarkTheme_light")]
+ Light,
+
+ [DisplayName(typeof(Resources), "DarkTheme_dark")]
+ Dark,
+
+ [DisplayName(typeof(Resources), "DarkTheme_system")]
+ System,
+ }
+} \ No newline at end of file
diff --git a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs
index ec98e4386..601dabd99 100644
--- a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs
+++ b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs
@@ -853,6 +853,33 @@ namespace HandBrakeWPF.Properties {
}
/// <summary>
+ /// Looks up a localized string similar to Use Dark.
+ /// </summary>
+ public static string DarkTheme_dark {
+ get {
+ return ResourceManager.GetString("DarkTheme_dark", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Use Light.
+ /// </summary>
+ public static string DarkTheme_light {
+ get {
+ return ResourceManager.GetString("DarkTheme_light", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Match System.
+ /// </summary>
+ public static string DarkTheme_system {
+ get {
+ return ResourceManager.GetString("DarkTheme_system", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to Create Folder?.
/// </summary>
public static string DirectoryUtils_CreateFolder {
@@ -3529,6 +3556,15 @@ namespace HandBrakeWPF.Properties {
}
/// <summary>
+ /// Looks up a localized string similar to Theme:.
+ /// </summary>
+ public static string OptionsView_DarkThemeMode {
+ get {
+ return ResourceManager.GetString("OptionsView_DarkThemeMode", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to Downloading....
/// </summary>
public static string OptionsView_Downloading {
@@ -3757,6 +3793,15 @@ namespace HandBrakeWPF.Properties {
}
/// <summary>
+ /// Looks up a localized string similar to (Requires Restart).
+ /// </summary>
+ public static string OptionsView_RequiresRestart {
+ get {
+ return ResourceManager.GetString("OptionsView_RequiresRestart", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to Please select a folder..
/// </summary>
public static string OptionsView_SelectFolder {
diff --git a/win/CS/HandBrakeWPF/Properties/Resources.resx b/win/CS/HandBrakeWPF/Properties/Resources.resx
index d4432a4b1..34943b9e6 100644
--- a/win/CS/HandBrakeWPF/Properties/Resources.resx
+++ b/win/CS/HandBrakeWPF/Properties/Resources.resx
@@ -2402,4 +2402,19 @@ Fields are limited to:
<data name="StaticPreviewView_ShowPictureSettingsAdjustment" xml:space="preserve">
<value>Show crop adjustment controls.</value>
</data>
+ <data name="DarkTheme_dark" xml:space="preserve">
+ <value>Use Dark</value>
+ </data>
+ <data name="DarkTheme_light" xml:space="preserve">
+ <value>Use Light</value>
+ </data>
+ <data name="DarkTheme_system" xml:space="preserve">
+ <value>Match System</value>
+ </data>
+ <data name="OptionsView_DarkThemeMode" xml:space="preserve">
+ <value>Theme:</value>
+ </data>
+ <data name="OptionsView_RequiresRestart" xml:space="preserve">
+ <value>(Requires Restart)</value>
+ </data>
</root> \ No newline at end of file
diff --git a/win/CS/HandBrakeWPF/Services/UserSettingService.cs b/win/CS/HandBrakeWPF/Services/UserSettingService.cs
index 7d121bdf6..c12a5713d 100644
--- a/win/CS/HandBrakeWPF/Services/UserSettingService.cs
+++ b/win/CS/HandBrakeWPF/Services/UserSettingService.cs
@@ -19,6 +19,7 @@ namespace HandBrakeWPF.Services
using HandBrake.Interop.Utilities;
using HandBrakeWPF.Extensions;
+ using HandBrakeWPF.Model;
using HandBrakeWPF.Properties;
using HandBrakeWPF.Services.Interfaces;
using HandBrakeWPF.Utilities;
@@ -269,7 +270,7 @@ namespace HandBrakeWPF.Services
defaults.Add(UserSettingConstants.UpdateStatus, true);
defaults.Add(UserSettingConstants.LastUpdateCheckDate, DateTime.Now.Date.AddDays(-30));
defaults.Add(UserSettingConstants.DaysBetweenUpdateCheck, 1);
- defaults.Add(UserSettingConstants.UseDarkTheme, false);
+ defaults.Add(UserSettingConstants.DarkThemeMode, DarkThemeMode.Light);
defaults.Add(UserSettingConstants.ShowPreviewOnSummaryTab, true);
defaults.Add(UserSettingConstants.MainWindowMinimize, false);
defaults.Add(UserSettingConstants.ClearCompletedFromQueue, false);
diff --git a/win/CS/HandBrakeWPF/UserSettingConstants.cs b/win/CS/HandBrakeWPF/UserSettingConstants.cs
index 8ecb34ee6..2869be6c3 100644
--- a/win/CS/HandBrakeWPF/UserSettingConstants.cs
+++ b/win/CS/HandBrakeWPF/UserSettingConstants.cs
@@ -70,7 +70,7 @@ namespace HandBrakeWPF
public const string AutonameFileCollisionBehaviour = "AutonameFileCollisionBehaviour";
public const string AutonameFilePrePostString = "AutonameFilePrePostString";
public const string WhenDonePerformActionImmediately = "WhenDonePerformActionImmediately";
- public const string UseDarkTheme = "UseDarkTheme";
+ public const string DarkThemeMode = "DarkThemeMode";
public const string PreviewRotationFlip = "PreviewRotationFlip";
public const string AlwaysUseDefaultPath = "AlwaysUseDefaultPath";
public const string PauseEncodingOnLowBattery = "PauseEncodingOnLowBattery";
diff --git a/win/CS/HandBrakeWPF/Utilities/SystemInfo.cs b/win/CS/HandBrakeWPF/Utilities/SystemInfo.cs
index e1452910a..ece1bdd34 100644
--- a/win/CS/HandBrakeWPF/Utilities/SystemInfo.cs
+++ b/win/CS/HandBrakeWPF/Utilities/SystemInfo.cs
@@ -149,5 +149,16 @@ namespace HandBrakeWPF.Utilities
return false;
}
+
+ public static bool IsAppsUsingDarkTheme()
+ {
+ object value = Registry.GetValue("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", "AppsUseLightTheme", null);
+ if (value != null)
+ {
+ return (int)value != 1;
+ }
+
+ return false;
+ }
}
}
diff --git a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs
index acd3a2b0a..e62c45546 100644
--- a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs
+++ b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs
@@ -102,7 +102,7 @@ namespace HandBrakeWPF.ViewModels
private string prePostFilenameText;
private bool showPrePostFilenameBox;
private bool whenDonePerformActionImmediately;
- private bool useDarkTheme;
+ private DarkThemeMode darkThemeMode;
private bool alwaysUseDefaultPath;
private bool pauseOnLowBattery;
private int lowBatteryLevel;
@@ -344,14 +344,16 @@ namespace HandBrakeWPF.ViewModels
}
}
- public bool UseDarkTheme
+ public BindingList<DarkThemeMode> DarkThemeModes { get; } = new BindingList<DarkThemeMode>(EnumHelper<DarkThemeMode>.GetEnumList().ToList());
+
+ public DarkThemeMode DarkThemeMode
{
- get => this.useDarkTheme;
+ get => this.darkThemeMode;
set
{
- if (value == this.useDarkTheme) return;
- this.useDarkTheme = value;
- this.NotifyOfPropertyChange(() => this.UseDarkTheme);
+ if (value == this.darkThemeMode) return;
+ this.darkThemeMode = value;
+ this.NotifyOfPropertyChange(() => this.DarkThemeMode);
}
}
@@ -1104,7 +1106,7 @@ namespace HandBrakeWPF.ViewModels
this.ShowPreviewOnSummaryTab = this.userSettingService.GetUserSetting<bool>(UserSettingConstants.ShowPreviewOnSummaryTab);
this.ShowAddAllToQueue = this.userSettingService.GetUserSetting<bool>(UserSettingConstants.ShowAddAllToQueue);
this.ShowAddSelectionToQueue = this.userSettingService.GetUserSetting<bool>(UserSettingConstants.ShowAddSelectionToQueue);
- this.UseDarkTheme = this.userSettingService.GetUserSetting<bool>(UserSettingConstants.UseDarkTheme);
+ this.DarkThemeMode = (DarkThemeMode)this.userSettingService.GetUserSetting<int>(UserSettingConstants.DarkThemeMode);
// #############################
// When Done
@@ -1304,7 +1306,7 @@ namespace HandBrakeWPF.ViewModels
this.userSettingService.SetUserSetting(UserSettingConstants.SendFileToArgs, this.Arguments);
this.userSettingService.SetUserSetting(UserSettingConstants.ShowStatusInTitleBar, this.ShowStatusInTitleBar);
this.userSettingService.SetUserSetting(UserSettingConstants.ShowPreviewOnSummaryTab, this.ShowPreviewOnSummaryTab);
- this.userSettingService.SetUserSetting(UserSettingConstants.UseDarkTheme, this.UseDarkTheme);
+ this.userSettingService.SetUserSetting(UserSettingConstants.DarkThemeMode, this.DarkThemeMode);
this.userSettingService.SetUserSetting(UserSettingConstants.UiLanguage, this.SelectedLanguage?.Culture);
this.userSettingService.SetUserSetting(UserSettingConstants.ShowAddAllToQueue, this.ShowAddAllToQueue);
this.userSettingService.SetUserSetting(UserSettingConstants.ShowAddSelectionToQueue, this.ShowAddSelectionToQueue);
diff --git a/win/CS/HandBrakeWPF/Views/OptionsView.xaml b/win/CS/HandBrakeWPF/Views/OptionsView.xaml
index 837484f2c..dc7a7ab46 100644
--- a/win/CS/HandBrakeWPF/Views/OptionsView.xaml
+++ b/win/CS/HandBrakeWPF/Views/OptionsView.xaml
@@ -41,6 +41,7 @@
<Options:ProcessPriorityConverter x:Key="ProcessPriorityConverter" />
<Options:Mp4BehaviourConverter x:Key="Mp4BehaviourConverter" />
<Options:UpdateCheckConverter x:Key="UpdateCheckConverter" />
+ <Options:ThemeSettingConverter x:Key="ThemeSettingConverter" />
<Converters:BooleanToVisibilityConverter x:Key="boolToVisConverter" />
@@ -137,8 +138,14 @@
<ComboBox DisplayMemberPath="Name" ItemsSource="{Binding InterfaceLanguages}" SelectedItem="{Binding SelectedLanguage}" Margin="5,0,0,0" HorizontalAlignment="Left" Width="245" />
</StackPanel>
+ <StackPanel Orientation="Horizontal" Margin="20,0,0,5">
+ <TextBlock Text="{x:Static Properties:Resources.OptionsView_DarkThemeMode}" Margin="0,0,0,0" VerticalAlignment="Center"/>
+ <ComboBox ItemsSource="{Binding DarkThemeModes, Converter={StaticResource ThemeSettingConverter}}" SelectedItem="{Binding DarkThemeMode, Converter={StaticResource ThemeSettingConverter}}"
+ IsEnabled="{Binding IsWindows10}" Margin="5,0,0,0" HorizontalAlignment="Left" Width="150" />
+ <TextBlock Text="{x:Static Properties:Resources.OptionsView_RequiresRestart}" Margin="5,0,0,0" />
+ </StackPanel>
+
<StackPanel Orientation="Vertical" Margin="20,5,0,0">
- <CheckBox Content="{x:Static Properties:Resources.Options_DarkTheme}" IsEnabled="{Binding IsWindows10}" IsChecked="{Binding UseDarkTheme}" />
<CheckBox Content="{x:Static Properties:Resources.Options_MinimiseTray}" IsChecked="{Binding MinimiseToTray}" />
<CheckBox Content="{x:Static Properties:Resources.Options_ClearCompleted}" IsChecked="{Binding ClearQueueOnEncodeCompleted}" />
<CheckBox Content="{x:Static Properties:Resources.OptionsView_ShowStatusInTitleBar}" IsChecked="{Binding ShowStatusInTitleBar}" />