Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ContextMenuManager/App.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Application
<Application
x:Class="ContextMenuManager.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Expand Down
32 changes: 31 additions & 1 deletion ContextMenuManager/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using ContextMenuManager.Methods;
using ContextMenuManager.Methods;
using iNKORE.UI.WPF.Modern;
using iNKORE.UI.WPF.Modern.Common;
using Microsoft.Win32;
using System;
using System.Diagnostics;
using System.Text;
Expand All @@ -25,6 +27,10 @@ protected override void OnStartup(StartupEventArgs e)
{
Current.ShutdownMode = ShutdownMode.OnMainWindowClose;

// 初始化主题管理器,根据系统主题设置应用主题
var isDarkMode = IsSystemDarkModeEnabled();
ThemeManager.Current.ApplicationTheme = isDarkMode ? ApplicationTheme.Dark : ApplicationTheme.Light;

RegisterAppDomainExceptions();
RegisterDispatcherUnhandledException();

Expand Down Expand Up @@ -108,5 +114,29 @@ public void OnSecondAppStarted()
Current?.MainWindow.Show();
Current?.MainWindow.Focus();
}

/// <summary>
/// 检测系统是否启用深色模式
/// </summary>
private static bool IsSystemDarkModeEnabled()
{
try
{
using var key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize");
if (key != null)
{
var value = key.GetValue("AppsUseLightTheme");
if (value is int intValue)
{
return intValue == 0; // 0 = Dark mode, 1 = Light mode
}
}
}
catch
{
// 如果读取注册表失败,默认使用浅色模式
}
return false; // 默认浅色模式
}
}
}
10 changes: 3 additions & 7 deletions ContextMenuManager/ContextMenuManager.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0-windows10.0.19041.0</TargetFramework>
<TargetFramework>net10.0-windows</TargetFramework>
<OutputType>WinExe</OutputType>
<UseWPF>true</UseWPF>
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
Expand Down Expand Up @@ -55,16 +55,12 @@

<Copy
SourceFiles="$(ProjectDir)Properties\Resources\Texts\AppLanguageDic.ini"
DestinationFiles="$(SolutionDir)Languages\zh-CN.ini"
DestinationFiles="$(TargetDir)Config\Languages\zh-CN.ini"
OverwriteReadOnlyFiles="true" />

<ItemGroup>
<LanguageFiles Include="$(SolutionDir)Languages\*.*" />
<LanguageFiles Include="$(TargetDir)Config\Languages\*.*" />
</ItemGroup>
<Copy
SourceFiles="@(LanguageFiles)"
DestinationFolder="$(TargetDir)Config\Languages"
OverwriteReadOnlyFiles="true" />

<ItemGroup>
<WebDictFiles Include="$(ProjectDir)Properties\Resources\Texts\*.*" />
Expand Down