diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index ae30de0c..28738cc2 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -42,7 +42,7 @@ jobs: # Get package version - name: Get Package Version run: | - $version = [system.diagnostics.fileversioninfo]::getversioninfo("ContextMenuManager\bin\Release\net10.0-windows10.0.19041.0\ContextMenuManager.dll").fileversion + $version = [system.diagnostics.fileversioninfo]::getversioninfo("ContextMenuManager\bin\Release\ContextMenuManager.dll").fileversion echo "release_version=$version" | out-file -filepath $env:github_env -encoding utf-8 -append # Publish the project diff --git a/ContextMenuManager/App.xaml b/ContextMenuManager/App.xaml index 0c16b386..15b2fec4 100644 --- a/ContextMenuManager/App.xaml +++ b/ContextMenuManager/App.xaml @@ -1,4 +1,4 @@ - @@ -93,6 +115,9 @@ protected virtual void Dispose(bool disposing) _disposed = true; } + // 取消注册系统主题变化监听器 + SystemEvents.UserPreferenceChanged -= SystemEvents_UserPreferenceChanged; + AppConfig.CleanDirectory(); } @@ -108,5 +133,29 @@ public void OnSecondAppStarted() Current?.MainWindow.Show(); Current?.MainWindow.Focus(); } + + /// + /// 检测系统是否启用深色模式 + /// + 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; // 默认浅色模式 + } } } diff --git a/ContextMenuManager/ContextMenuManager.csproj b/ContextMenuManager/ContextMenuManager.csproj index ec9dcc53..c36e374f 100644 --- a/ContextMenuManager/ContextMenuManager.csproj +++ b/ContextMenuManager/ContextMenuManager.csproj @@ -1,6 +1,6 @@  - net10.0-windows10.0.19041.0 + net10.0-windows WinExe true true @@ -11,6 +11,7 @@ $(NoWarn);WFO1000;CA1416 true false + false @@ -55,7 +56,7 @@ @@ -77,4 +78,4 @@ - + \ No newline at end of file diff --git a/ContextMenuManager/Properties/PublishProfiles/Net10.0-Win64.pubxml b/ContextMenuManager/Properties/PublishProfiles/Net10.0-Win64.pubxml index 5b8dfadd..b1ac9576 100644 --- a/ContextMenuManager/Properties/PublishProfiles/Net10.0-Win64.pubxml +++ b/ContextMenuManager/Properties/PublishProfiles/Net10.0-Win64.pubxml @@ -7,7 +7,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121. FileSystem Release Any CPU - net10.0-windows10.0.19041.0 + net10.0-windows bin\Publish\ win-x64 false