40 lines
1.7 KiB
C#
40 lines
1.7 KiB
C#
using Microsoft.Win32;
|
|
|
|
namespace VideoDownloader.App.Services;
|
|
|
|
/// <summary>
|
|
/// UC-T13 시스템 테마 판별 — Windows 개인 설정(AppsUseLightTheme) 레지스트리를 읽어
|
|
/// dark/light 를 판정하고, 설정값(dark/light/system/highcontrast/파일경로)을 실제 적용할
|
|
/// 테마로 해석한다. 레지스트리 기반이라 WPF 스레드 없이도 단위 테스트가 가능하다.
|
|
/// </summary>
|
|
public static class ThemeResolver
|
|
{
|
|
/// <summary>설정 테마 값 → (테마 사전 이름, 사용자 정의 .xaml 경로|null).</summary>
|
|
public static (string Theme, string? CustomPath) Resolve(string setting, string? customThemePath = null)
|
|
{
|
|
var s = (setting ?? "dark").Trim().ToLowerInvariant();
|
|
return s switch
|
|
{
|
|
"system" => (IsSystemLight() ? "light" : "dark", null),
|
|
"highcontrast" => ("highcontrast", null),
|
|
"light" => ("light", null),
|
|
"dark" => ("dark", null),
|
|
// 커스텀 테마 파일 경로가 설정에 있으면 우선
|
|
_ when !string.IsNullOrWhiteSpace(customThemePath) && File.Exists(customThemePath) => ("custom", customThemePath),
|
|
_ => ("dark", null),
|
|
};
|
|
}
|
|
|
|
/// <summary>Windows 앱 모드가 라이트면 true(레지스트리 접근 실패 시 다크 취급).</summary>
|
|
public static bool IsSystemLight()
|
|
{
|
|
try
|
|
{
|
|
using var key = Registry.CurrentUser.OpenSubKey(
|
|
@"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize");
|
|
if (key?.GetValue("AppsUseLightTheme") is int v) return v == 1;
|
|
}
|
|
catch { }
|
|
return false;
|
|
}
|
|
}
|