improve:PPT时间胶囊

改进主题
This commit is contained in:
2025-12-31 16:28:04 +08:00
parent bca2dde497
commit 4cc8af7ff0
+43 -31
View File
@@ -583,9 +583,37 @@ namespace Ink_Canvas.Windows
{ {
try try
{ {
// 检测系统主题 if (MainWindow.Settings != null)
bool isDarkTheme = IsDarkTheme(); {
ApplyTheme(MainWindow.Settings);
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"应用PPT时间胶囊主题失败: {ex.Message}", LogHelper.LogType.Error);
}
}
private void ApplyTheme(Settings settings)
{
try
{
bool isDarkTheme = false;
if (settings.Appearance.Theme == 0) // 浅色主题
{
isDarkTheme = false;
}
else if (settings.Appearance.Theme == 1) // 深色主题
{
isDarkTheme = true;
}
else // 跟随系统主题
{
bool isSystemLight = IsSystemThemeLight();
isDarkTheme = !isSystemLight;
}
if (isDarkTheme) if (isDarkTheme)
{ {
// 深色主题:使用80%不透明度的深色背景 // 深色主题:使用80%不透明度的深色背景
@@ -615,45 +643,29 @@ namespace Ink_Canvas.Windows
} }
} }
private bool IsDarkTheme() private bool IsSystemThemeLight()
{ {
var light = false;
try try
{ {
string settingsPath = Path.Combine(App.RootPath, "Configs", "Settings.json"); var registryKey = Microsoft.Win32.Registry.CurrentUser;
if (File.Exists(settingsPath)) var themeKey = registryKey.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize");
if (themeKey != null)
{ {
string jsonText = File.ReadAllText(settingsPath); var value = themeKey.GetValue("AppsUseLightTheme");
var settings = JsonConvert.DeserializeObject<Settings>(jsonText); if (value != null)
if (settings?.Appearance != null)
{ {
if (settings.Appearance.Theme == 1) light = (int)value == 1;
{
return true;
}
else if (settings.Appearance.Theme == 0)
{
return false;
}
else
{
int systemTheme = (int)Microsoft.Win32.Registry.GetValue(
@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize",
"AppsUseLightTheme", 1);
return systemTheme == 0;
}
} }
themeKey.Close();
} }
int fallbackTheme = (int)Microsoft.Win32.Registry.GetValue(
@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize",
"AppsUseLightTheme", 1);
return fallbackTheme == 0;
} }
catch catch
{ {
return false; // 如果读取注册表失败,默认为浅色主题
light = true;
} }
return light;
} }
/// <summary> /// <summary>