add dark mode

This commit is contained in:
Jakob 2023-07-14 12:37:00 +02:00
parent 6b745618e6
commit 6d281e4e44
4 changed files with 36 additions and 10 deletions

View file

@ -7,7 +7,6 @@
<Application.Resources> <Application.Resources>
<ResourceDictionary> <ResourceDictionary>
<ResourceDictionary.MergedDictionaries> <ResourceDictionary.MergedDictionaries>
<ui:ThemesDictionary Theme="Light"/>
<ui:ControlsDictionary /> <ui:ControlsDictionary />
</ResourceDictionary.MergedDictionaries> </ResourceDictionary.MergedDictionaries>
</ResourceDictionary> </ResourceDictionary>

View file

@ -8,6 +8,7 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using Windows.Foundation.Collections; using Windows.Foundation.Collections;
using Wpf.Ui.Markup;
namespace EnvyUpdate namespace EnvyUpdate
{ {
@ -18,6 +19,14 @@ namespace EnvyUpdate
{ {
protected override void OnStartup(StartupEventArgs e) protected override void OnStartup(StartupEventArgs e)
{ {
Wpf.Ui.Appearance.Accent.ApplySystemAccent();
ThemesDictionary themedict = new ThemesDictionary();
if (Util.IsDarkTheme())
themedict.Theme = Wpf.Ui.Appearance.ThemeType.Dark;
else
themedict.Theme = Wpf.Ui.Appearance.ThemeType.Light;
Application.Current.Resources.MergedDictionaries.Add(themedict);
// Listen to notification activation // Listen to notification activation
ToastNotificationManagerCompat.OnActivated += toastArgs => ToastNotificationManagerCompat.OnActivated += toastArgs =>
{ {

View file

@ -24,6 +24,8 @@ namespace EnvyUpdate
public MainWindow() public MainWindow()
{ {
InitializeComponent();
// Try to get command line arguments // Try to get command line arguments
try try
{ {
@ -83,11 +85,6 @@ namespace EnvyUpdate
GlobalVars.isMobile = Util.IsMobile(); GlobalVars.isMobile = Util.IsMobile();
Debug.LogToFile("INFO Mobile: " + GlobalVars.isMobile); Debug.LogToFile("INFO Mobile: " + GlobalVars.isMobile);
InitializeComponent();
Wpf.Ui.Appearance.Accent.ApplySystemAccent();
} }
private void Window_StateChanged(object sender, EventArgs e) private void Window_StateChanged(object sender, EventArgs e)
{ {

View file

@ -6,13 +6,9 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Management; using System.Management;
using System.Net; using System.Net;
using System.Security.Cryptography;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Xml.Linq; using System.Xml.Linq;
using Windows.Devices.Radios;
using Windows.UI.Xaml.Input;
namespace EnvyUpdate namespace EnvyUpdate
{ {
@ -552,6 +548,31 @@ namespace EnvyUpdate
} }
} }
public static bool IsDarkTheme()
{
try
{
Debug.LogToFile("INFO Trying to get app theme...");
int res = (int)Registry.GetValue("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", "AppsUseLightTheme", -1);
switch (res)
{
case 0:
Debug.LogToFile("INFO Using dark theme.");
return true;
case 1:
Debug.LogToFile("INFO Using light theme.");
return false;
default:
throw new IndexOutOfRangeException();
}
}
catch (Exception)
{
Debug.LogToFile("WARN Could not determine theme. Setting light theme.");
return false;
}
}
public static void DownloadFile(string fileURL, string savePath) public static void DownloadFile(string fileURL, string savePath)
{ {
//TODO Implement downloading //TODO Implement downloading