feat: Phase 0 shells, design system, server skeleton, Docker and CI
- Titano.Ui: DESIGN.md tokens (dark/light), generated 16-px icon set, styles for all standard controls, custom chrome window with snap layouts, rail, job bar, Auto/manual slider, chips, toasts. - Titano desktop shell with sections, Settings (language, theme), About and a --capture screenshot mode. - Titano Server skeleton: env/server.json configuration, self-signed TLS with fingerprint, /health, /server/info, i18n endpoint and the embedded admin panel; in-process server tests. - Docker image (multi-arch, PUID/PGID, health check), compose file, Unraid template; CI, release and nightly workflows; changelog tool. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
122 files changed
+6838
-22
No files matched your search
@@ -0,0 +1,112 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Interop;
|
||||
using System.Windows.Media;
|
||||
using Microsoft.Win32;
|
||||
using Titano.Ui.Interop;
|
||||
|
||||
namespace Titano.Ui.Theming;
|
||||
|
||||
public enum AppTheme
|
||||
{
|
||||
System,
|
||||
Dark,
|
||||
Light,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads the Titano design system into an application and switches between the dark and light token sets
|
||||
/// at run time (DESIGN.md §1: dark is the client default, light follows the OS when System is chosen).
|
||||
/// </summary>
|
||||
public static class ThemeManager
|
||||
{
|
||||
private const string Base = "pack://application:,,,/Titano.Ui;component/";
|
||||
private static ResourceDictionary? _tokens;
|
||||
private static Application? _app;
|
||||
private static bool _initialized;
|
||||
|
||||
public static AppTheme Requested { get; private set; } = AppTheme.Dark;
|
||||
|
||||
public static bool IsDark { get; private set; }
|
||||
|
||||
public static event EventHandler? Changed;
|
||||
|
||||
/// <summary>Merges typography, tokens, icons and control styles into <paramref name="app"/>.</summary>
|
||||
public static void Initialize(Application app, AppTheme theme)
|
||||
{
|
||||
_app = app;
|
||||
var merged = app.Resources.MergedDictionaries;
|
||||
// Controls.xaml merges Typography.xaml and Icons.xaml itself so its StaticResources resolve at load.
|
||||
_tokens = Load(TokensFor(Resolve(theme)));
|
||||
merged.Insert(0, _tokens);
|
||||
merged.Insert(1, Load("Themes/Controls.xaml"));
|
||||
|
||||
ToolTipService.InitialShowDelayProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(400));
|
||||
ToolTipService.BetweenShowDelayProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(100));
|
||||
ToolTipService.ShowDurationProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(20000));
|
||||
|
||||
SystemEvents.UserPreferenceChanged += (_, e) =>
|
||||
{
|
||||
if (e.Category == UserPreferenceCategory.General && Requested == AppTheme.System)
|
||||
app.Dispatcher.BeginInvoke(() => Apply(AppTheme.System));
|
||||
};
|
||||
Apply(theme);
|
||||
}
|
||||
|
||||
public static void Apply(AppTheme theme)
|
||||
{
|
||||
if (_app is null || _tokens is null) throw new InvalidOperationException("ThemeManager.Initialize first.");
|
||||
Requested = theme;
|
||||
var dark = Resolve(theme);
|
||||
if (dark != IsDark || !_initialized)
|
||||
{
|
||||
var merged = _app.Resources.MergedDictionaries;
|
||||
var index = merged.IndexOf(_tokens);
|
||||
_tokens = Load(TokensFor(dark));
|
||||
merged[index] = _tokens;
|
||||
IsDark = dark;
|
||||
_initialized = true;
|
||||
}
|
||||
foreach (Window w in _app.Windows) ApplyChrome(w);
|
||||
Changed?.Invoke(null, EventArgs.Empty);
|
||||
}
|
||||
|
||||
/// <summary>True when Windows apps are set to dark mode.</summary>
|
||||
public static bool SystemPrefersDark()
|
||||
{
|
||||
try
|
||||
{
|
||||
using var key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize");
|
||||
return key?.GetValue("AppsUseLightTheme") is not int light || light == 0;
|
||||
}
|
||||
catch (System.Security.SecurityException)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Colours the DWM frame (border/caption) to match the current tokens.</summary>
|
||||
public static void ApplyChrome(Window window)
|
||||
{
|
||||
var hwnd = new WindowInteropHelper(window).Handle;
|
||||
if (hwnd == IntPtr.Zero) return;
|
||||
NativeMethods.TrySetDwm(hwnd, NativeMethods.DWMWA_USE_IMMERSIVE_DARK_MODE, IsDark ? 1 : 0);
|
||||
NativeMethods.TrySetDwm(hwnd, NativeMethods.DWMWA_USE_IMMERSIVE_DARK_MODE_OLD, IsDark ? 1 : 0);
|
||||
NativeMethods.TrySetDwm(hwnd, NativeMethods.DWMWA_WINDOW_CORNER_PREFERENCE, 2);
|
||||
if (_app?.TryFindResource("Color.Chrome") is Color chrome)
|
||||
NativeMethods.TrySetDwm(hwnd, NativeMethods.DWMWA_CAPTION_COLOR, NativeMethods.ColorRef(chrome.R, chrome.G, chrome.B));
|
||||
if (_app?.TryFindResource("Color.Stroke") is Color stroke)
|
||||
NativeMethods.TrySetDwm(hwnd, NativeMethods.DWMWA_BORDER_COLOR, NativeMethods.ColorRef(stroke.R, stroke.G, stroke.B));
|
||||
}
|
||||
|
||||
private static bool Resolve(AppTheme theme) => theme switch
|
||||
{
|
||||
AppTheme.Dark => true,
|
||||
AppTheme.Light => false,
|
||||
_ => SystemPrefersDark(),
|
||||
};
|
||||
|
||||
private static string TokensFor(bool dark) => dark ? "Themes/Tokens.Dark.xaml" : "Themes/Tokens.Light.xaml";
|
||||
|
||||
private static ResourceDictionary Load(string path) => new() { Source = new Uri(Base + path, UriKind.Absolute) };
|
||||
}
|
||||
Reference in new issue
Block a user