using Microsoft.Win32; namespace VideoDownloader.App.Services; /// /// UC-T13 시스템 테마 판별 — Windows 개인 설정(AppsUseLightTheme) 레지스트리를 읽어 /// dark/light 를 판정하고, 설정값(dark/light/system/highcontrast/파일경로)을 실제 적용할 /// 테마로 해석한다. 레지스트리 기반이라 WPF 스레드 없이도 단위 테스트가 가능하다. /// public static class ThemeResolver { /// 설정 테마 값 → (테마 사전 이름, 사용자 정의 .xaml 경로|null). 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), }; } /// Windows 앱 모드가 라이트면 true(레지스트리 접근 실패 시 다크 취급). 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; } }