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
@@ -1,4 +1,12 @@
|
||||
<Application x:Class="Titano.App.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
ShutdownMode="OnMainWindowClose">
|
||||
<Application.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="Shell/SectionTemplates.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</Application.Resources>
|
||||
</Application>
|
||||
@@ -1,7 +1,97 @@
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Threading;
|
||||
using Titano.App.Infrastructure;
|
||||
using Titano.App.Shell;
|
||||
using Titano.Core.Diagnostics;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Ui.Mvvm;
|
||||
using Titano.Ui.Theming;
|
||||
|
||||
namespace Titano.App;
|
||||
|
||||
public partial class App : Application
|
||||
{
|
||||
private FileLogSink? _log;
|
||||
|
||||
public AppEnvironment Environment { get; private set; } = null!;
|
||||
public AppSettings Settings { get; private set; } = null!;
|
||||
|
||||
public static new App Current => (App)Application.Current;
|
||||
|
||||
protected override void OnStartup(StartupEventArgs e)
|
||||
{
|
||||
base.OnStartup(e);
|
||||
Environment = AppEnvironment.Detect();
|
||||
_log = new FileLogSink(Environment.LogDirectory, "titano");
|
||||
Log.SetSink(_log);
|
||||
Log.Info("app", $"Titano {typeof(App).Assembly.GetName().Version} starting; data at {Environment.DataDirectory}");
|
||||
|
||||
Settings = AppSettings.Load(Environment.SettingsPath);
|
||||
ApplyLanguage(Settings.Language);
|
||||
ThemeManager.Initialize(this, Settings.Theme);
|
||||
|
||||
DispatcherUnhandledException += OnUnhandledException;
|
||||
AppDomain.CurrentDomain.UnhandledException += (_, args) => Log.Error("app", "Unhandled exception", args.ExceptionObject as Exception);
|
||||
TaskScheduler.UnobservedTaskException += (_, args) =>
|
||||
{
|
||||
Log.Error("app", "Unobserved task exception", args.Exception);
|
||||
args.SetObserved();
|
||||
};
|
||||
|
||||
var shell = new ShellViewModel(Settings);
|
||||
AsyncRelayCommand.Failed += ex => shell.ReportError(ex);
|
||||
var window = new MainWindow(shell);
|
||||
MainWindow = window;
|
||||
|
||||
var captureIndex = Array.IndexOf(e.Args, "--capture");
|
||||
if (captureIndex >= 0)
|
||||
{
|
||||
var dir = captureIndex + 1 < e.Args.Length ? e.Args[captureIndex + 1] : "screenshots";
|
||||
ScreenCapture.Run(window, shell, dir);
|
||||
return;
|
||||
}
|
||||
window.Show();
|
||||
}
|
||||
|
||||
/// <summary>Switches the UI language at run time (BRIEF §16) and remembers the choice.</summary>
|
||||
public void ApplyLanguage(string? code)
|
||||
{
|
||||
var culture = Languages.BestMatch(code is null ? CultureInfo.CurrentUICulture : CultureInfo.GetCultureInfo(code));
|
||||
CultureInfo.DefaultThreadCurrentUICulture = culture;
|
||||
CultureInfo.CurrentUICulture = culture;
|
||||
Loc.SetCulture(culture);
|
||||
foreach (Window w in Windows)
|
||||
w.FlowDirection = Loc.IsRightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
|
||||
}
|
||||
|
||||
public void SaveSettings()
|
||||
{
|
||||
try
|
||||
{
|
||||
Settings.Save(Environment.SettingsPath);
|
||||
}
|
||||
catch (System.IO.IOException ex)
|
||||
{
|
||||
Log.Warning("app", "Settings not saved", ex);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnExit(ExitEventArgs e)
|
||||
{
|
||||
SaveSettings();
|
||||
Log.Info("app", "Titano exiting");
|
||||
_log?.Dispose();
|
||||
base.OnExit(e);
|
||||
}
|
||||
|
||||
private void OnUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
|
||||
{
|
||||
Log.Error("app", "Unhandled UI exception", e.Exception);
|
||||
if (MainWindow?.DataContext is ShellViewModel shell)
|
||||
{
|
||||
shell.ReportError(e.Exception);
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using System.IO;
|
||||
|
||||
namespace Titano.App.Infrastructure;
|
||||
|
||||
/// <summary>
|
||||
/// Where the client keeps its data (BRIEF §6.2): <c>%LOCALAPPDATA%\Titano</c>, or <c>.\data</c> next to the
|
||||
/// executable when <c>portable.txt</c> exists. Never inside Documents/OneDrive (SQLite corrupts in synced folders).
|
||||
/// </summary>
|
||||
public sealed class AppEnvironment
|
||||
{
|
||||
private AppEnvironment(string dataDirectory, bool portable)
|
||||
{
|
||||
DataDirectory = dataDirectory;
|
||||
IsPortable = portable;
|
||||
Directory.CreateDirectory(DataDirectory);
|
||||
Directory.CreateDirectory(LogDirectory);
|
||||
Directory.CreateDirectory(CacheDirectory);
|
||||
}
|
||||
|
||||
public string DataDirectory { get; }
|
||||
public bool IsPortable { get; }
|
||||
public string LogDirectory => Path.Combine(DataDirectory, "logs");
|
||||
public string CacheDirectory => Path.Combine(DataDirectory, "cache");
|
||||
public string DatabasePath => Path.Combine(DataDirectory, "titano.db");
|
||||
public string SettingsPath => Path.Combine(DataDirectory, "settings.json");
|
||||
|
||||
public static AppEnvironment Detect()
|
||||
{
|
||||
var exeDir = AppContext.BaseDirectory;
|
||||
if (File.Exists(Path.Combine(exeDir, "portable.txt")))
|
||||
return new AppEnvironment(Path.Combine(exeDir, "data"), portable: true);
|
||||
var local = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
||||
return new AppEnvironment(Path.Combine(local, "Titano"), portable: false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Titano.Core.IO;
|
||||
using Titano.Ui.Theming;
|
||||
|
||||
namespace Titano.App.Infrastructure;
|
||||
|
||||
/// <summary>Per-user preferences needed before the database opens (language, theme, window layout).</summary>
|
||||
public sealed class AppSettings
|
||||
{
|
||||
public string? Language { get; set; }
|
||||
public AppTheme Theme { get; set; } = AppTheme.Dark;
|
||||
public bool RailCollapsed { get; set; }
|
||||
public bool CheckForUpdates { get; set; } = true;
|
||||
public bool AnonymousUsageCounts { get; set; }
|
||||
public string? LastArchivePath { get; set; }
|
||||
public WindowPlacement? Window { get; set; }
|
||||
|
||||
public sealed class WindowPlacement
|
||||
{
|
||||
public double Left { get; set; }
|
||||
public double Top { get; set; }
|
||||
public double Width { get; set; }
|
||||
public double Height { get; set; }
|
||||
public bool Maximized { get; set; }
|
||||
}
|
||||
|
||||
public static AppSettings Load(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (File.Exists(path))
|
||||
return JsonSerializer.Deserialize(File.ReadAllText(path), AppSettingsJson.Default.AppSettings) ?? new AppSettings();
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
// A corrupt settings file must never block startup; defaults apply.
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
}
|
||||
return new AppSettings();
|
||||
}
|
||||
|
||||
public void Save(string path) => AtomicFile.WriteAllText(path, JsonSerializer.Serialize(this, AppSettingsJson.Default.AppSettings));
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true, UseStringEnumConverter = true)]
|
||||
[JsonSerializable(typeof(AppSettings))]
|
||||
internal sealed partial class AppSettingsJson : JsonSerializerContext;
|
||||
@@ -0,0 +1,34 @@
|
||||
using Titano.Core.Localization;
|
||||
|
||||
namespace Titano.App.Infrastructure;
|
||||
|
||||
/// <summary>Culture-aware number, size and duration formatting for the UI.</summary>
|
||||
public static class Formatting
|
||||
{
|
||||
private static readonly string[] ByteUnits = ["B", "KB", "MB", "GB", "TB", "PB"];
|
||||
|
||||
/// <summary>1,536 → "1.5 KB" (decimal units, as Explorer shows for drives).</summary>
|
||||
public static string Bytes(long bytes)
|
||||
{
|
||||
double value = bytes;
|
||||
var unit = 0;
|
||||
while (value >= 1000 && unit < ByteUnits.Length - 1)
|
||||
{
|
||||
value /= 1000;
|
||||
unit++;
|
||||
}
|
||||
var format = unit == 0 || value >= 100 ? "0" : "0.#";
|
||||
return value.ToString(format, Loc.Culture) + " " + ByteUnits[unit];
|
||||
}
|
||||
|
||||
public static string Count(long n) => n.ToString("N0", Loc.Culture);
|
||||
|
||||
/// <summary>Compact duration: "2 h 00 m", "5 min", "40 s".</summary>
|
||||
public static string Duration(TimeSpan t)
|
||||
{
|
||||
if (t.TotalHours >= 24) return Loc.L("Common.Duration.Days", (int)t.TotalDays, t.Hours);
|
||||
if (t.TotalHours >= 1) return Loc.L("Common.Duration.Hours", (int)t.TotalHours, t.Minutes.ToString("00", Loc.Culture));
|
||||
if (t.TotalMinutes >= 1) return Loc.L("Common.Duration.Minutes", (int)Math.Round(t.TotalMinutes));
|
||||
return Loc.L("Common.Duration.Seconds", (int)Math.Round(t.TotalSeconds));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace Titano.App.Infrastructure;
|
||||
|
||||
/// <summary>Public links (BRIEF §19.4). Overridable at build time via the TitanoReleasesRepo property.</summary>
|
||||
public static class ProductLinks
|
||||
{
|
||||
public static string ReleasesRepository { get; } =
|
||||
typeof(ProductLinks).Assembly.GetCustomAttributes(typeof(System.Reflection.AssemblyMetadataAttribute), false)
|
||||
.OfType<System.Reflection.AssemblyMetadataAttribute>()
|
||||
.FirstOrDefault(a => a.Key == "TitanoReleasesRepo")?.Value ?? "alby96/titano-releases";
|
||||
|
||||
public static string Releases => $"https://github.com/{ReleasesRepository}/releases";
|
||||
|
||||
public static string LatestReleaseApi => $"https://api.github.com/repos/{ReleasesRepository}/releases/latest";
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace Titano.App.Infrastructure;
|
||||
|
||||
/// <summary>The only shell launches the product performs (BRIEF §8.6): open a URL, reveal a folder.</summary>
|
||||
public static class ShellActions
|
||||
{
|
||||
public static void OpenUrl(string url)
|
||||
{
|
||||
if (!Uri.TryCreate(url, UriKind.Absolute, out var uri) || uri.Scheme is not ("https" or "http" or "ms-windows-store")) return;
|
||||
Process.Start(new ProcessStartInfo(uri.AbsoluteUri) { UseShellExecute = true });
|
||||
}
|
||||
|
||||
public static void OpenFolder(string path)
|
||||
{
|
||||
if (!Directory.Exists(path)) return;
|
||||
Process.Start(new ProcessStartInfo(path) { UseShellExecute = true, Verb = "explore" });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<UserControl x:Class="Titano.App.Sections.AboutView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="clr-namespace:Titano.Ui.Controls;assembly=Titano.Ui"
|
||||
xmlns:l="clr-namespace:Titano.Ui.Localization;assembly=Titano.Ui">
|
||||
<Grid Margin="20,16,20,20">
|
||||
<Border Style="{StaticResource Border.Panel}" Padding="28,24" HorizontalAlignment="Left" VerticalAlignment="Top" MinWidth="560">
|
||||
<StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,0,0,20">
|
||||
<ui:BrandMarkIcon Width="56" Height="56" ShowPlate="True" />
|
||||
<StackPanel Margin="16,0,0,0" VerticalAlignment="Center">
|
||||
<TextBlock Text="{l:Loc Shell.AppName}" Style="{StaticResource Text.PageTitle}" FontSize="22" />
|
||||
<TextBlock Text="{Binding Version}" Style="{StaticResource Text.Secondary}" Margin="0,2,0,0" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="140" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="28" />
|
||||
<RowDefinition Height="28" />
|
||||
<RowDefinition Height="28" />
|
||||
<RowDefinition Height="28" />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Text="{l:Loc About.Runtime}" Foreground="{DynamicResource Brush.TextMuted}" />
|
||||
<TextBlock Grid.Column="1" Text="{Binding Runtime}" />
|
||||
<TextBlock Grid.Row="1" Text="{l:Loc About.System}" Foreground="{DynamicResource Brush.TextMuted}" />
|
||||
<TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding OperatingSystem}" />
|
||||
<TextBlock Grid.Row="2" Text="{l:Loc About.ThirdParty}" Foreground="{DynamicResource Brush.TextMuted}" />
|
||||
<TextBlock Grid.Row="2" Grid.Column="1" Text="{l:Loc About.ThirdPartyNone}" />
|
||||
<TextBlock Grid.Row="3" Text="{l:Loc About.Data}" Foreground="{DynamicResource Brush.TextMuted}" />
|
||||
<TextBlock Grid.Row="3" Grid.Column="1" Text="{Binding DataFolder}" />
|
||||
</Grid>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,20,0,0">
|
||||
<Button Content="{l:Loc About.Releases}" Command="{Binding OpenReleasesCommand}" ToolTip="{l:Loc Tooltips.About.Releases}" Margin="0,0,8,0" ui:ButtonIcon.Glyph="{StaticResource Icon.ExternalLink}" />
|
||||
<Button Content="{l:Loc About.OpenData}" Command="{Binding OpenDataFolderCommand}" ToolTip="{l:Loc Tooltips.About.OpenData}" ui:ButtonIcon.Glyph="{StaticResource Icon.FolderOpen}" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,8 @@
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Titano.App.Sections;
|
||||
|
||||
public partial class AboutView : UserControl
|
||||
{
|
||||
public AboutView() => InitializeComponent();
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<UserControl x:Class="Titano.App.Sections.ArchiveView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="clr-namespace:Titano.Ui.Controls;assembly=Titano.Ui"
|
||||
xmlns:l="clr-namespace:Titano.Ui.Localization;assembly=Titano.Ui">
|
||||
<Grid Margin="20">
|
||||
<ui:EmptyState Message="{l:Loc Archive.Empty}" />
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,8 @@
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Titano.App.Sections;
|
||||
|
||||
public partial class ArchiveView : UserControl
|
||||
{
|
||||
public ArchiveView() => InitializeComponent();
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<UserControl x:Class="Titano.App.Sections.ImportView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="clr-namespace:Titano.Ui.Controls;assembly=Titano.Ui"
|
||||
xmlns:l="clr-namespace:Titano.Ui.Localization;assembly=Titano.Ui">
|
||||
<Grid Margin="20">
|
||||
<ui:EmptyState Message="{l:Loc Import.Empty}" />
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,8 @@
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Titano.App.Sections;
|
||||
|
||||
public partial class ImportView : UserControl
|
||||
{
|
||||
public ImportView() => InitializeComponent();
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<UserControl x:Class="Titano.App.Sections.JobsView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="clr-namespace:Titano.Ui.Controls;assembly=Titano.Ui"
|
||||
xmlns:l="clr-namespace:Titano.Ui.Localization;assembly=Titano.Ui">
|
||||
<Grid Margin="20">
|
||||
<ui:EmptyState Message="{l:Loc Jobs.Empty}" />
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,8 @@
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Titano.App.Sections;
|
||||
|
||||
public partial class JobsView : UserControl
|
||||
{
|
||||
public JobsView() => InitializeComponent();
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<UserControl x:Class="Titano.App.Sections.LibraryView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="clr-namespace:Titano.Ui.Controls;assembly=Titano.Ui"
|
||||
xmlns:l="clr-namespace:Titano.Ui.Localization;assembly=Titano.Ui">
|
||||
<Grid Margin="20">
|
||||
<ui:EmptyState Message="{l:Loc Library.Empty}">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Button Style="{StaticResource Button.Primary}" Content="{l:Loc Library.Empty.ImportCard}" Command="{Binding ImportCardCommand}" ToolTip="{l:Loc Tooltips.Library.ImportCard}" Margin="0,0,8,0" />
|
||||
<Button Content="{l:Loc Library.Empty.OpenArchive}" Command="{Binding OpenArchiveCommand}" ToolTip="{l:Loc Tooltips.Library.OpenArchive}" Margin="0,0,8,0" />
|
||||
<Button Content="{l:Loc Library.Empty.Connect}" Command="{Binding ConnectCommand}" ToolTip="{l:Loc Tooltips.Library.Connect}" />
|
||||
</StackPanel>
|
||||
</ui:EmptyState>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,8 @@
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Titano.App.Sections;
|
||||
|
||||
public partial class LibraryView : UserControl
|
||||
{
|
||||
public LibraryView() => InitializeComponent();
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
using System.Reflection;
|
||||
using System.Windows.Input;
|
||||
using Titano.App.Infrastructure;
|
||||
using Titano.App.Shell;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Ui.Mvvm;
|
||||
using Titano.Ui.Theming;
|
||||
|
||||
namespace Titano.App.Sections;
|
||||
|
||||
/// <summary>Library (home): sequences of the archive (BRIEF §12.2).</summary>
|
||||
public sealed class LibraryViewModel(ShellViewModel shell) : SectionViewModel(SectionKey.Library, "Icon.Library")
|
||||
{
|
||||
public ShellViewModel Shell { get; } = shell;
|
||||
public ICommand ImportCardCommand => new RelayCommand(() => Shell.Navigate(SectionKey.Import));
|
||||
public ICommand OpenArchiveCommand => new RelayCommand(() => Shell.Navigate(SectionKey.Archive));
|
||||
public ICommand ConnectCommand => new RelayCommand(() => Shell.Navigate(SectionKey.Server));
|
||||
}
|
||||
|
||||
/// <summary>Card and folder import (BRIEF §12.4).</summary>
|
||||
public sealed class ImportViewModel(ShellViewModel shell) : SectionViewModel(SectionKey.Import, "Icon.Import")
|
||||
{
|
||||
public ShellViewModel Shell { get; } = shell;
|
||||
}
|
||||
|
||||
/// <summary>Sequence editor (BRIEF §12.3).</summary>
|
||||
public sealed class SequenceViewModel(ShellViewModel shell) : SectionViewModel(SectionKey.Sequence, "Icon.Sequence")
|
||||
{
|
||||
public ShellViewModel Shell { get; } = shell;
|
||||
public ICommand OpenLibraryCommand => new RelayCommand(() => Shell.Navigate(SectionKey.Library));
|
||||
}
|
||||
|
||||
/// <summary>Archive manager (BRIEF §12.5).</summary>
|
||||
public sealed class ArchiveViewModel(ShellViewModel shell) : SectionViewModel(SectionKey.Archive, "Icon.Archive")
|
||||
{
|
||||
public ShellViewModel Shell { get; } = shell;
|
||||
}
|
||||
|
||||
/// <summary>Job queue and history (BRIEF §12.6).</summary>
|
||||
public sealed class JobsViewModel(ShellViewModel shell) : SectionViewModel(SectionKey.Jobs, "Icon.Jobs")
|
||||
{
|
||||
public ShellViewModel Shell { get; } = shell;
|
||||
}
|
||||
|
||||
/// <summary>Server connection and sync (BRIEF §12.7).</summary>
|
||||
public sealed class ServerViewModel(ShellViewModel shell) : SectionViewModel(SectionKey.Server, "Icon.Server")
|
||||
{
|
||||
public ShellViewModel Shell { get; } = shell;
|
||||
}
|
||||
|
||||
public sealed record LanguageOption(string Code, string Name);
|
||||
|
||||
/// <summary>Settings (BRIEF §12.8): section list on the left, controls on the right, tooltips only.</summary>
|
||||
public sealed class SettingsViewModel : SectionViewModel
|
||||
{
|
||||
private readonly AppSettings _settings;
|
||||
private string _page = "General";
|
||||
|
||||
public SettingsViewModel(ShellViewModel shell, AppSettings settings)
|
||||
: base(SectionKey.Settings, "Icon.Settings")
|
||||
{
|
||||
Shell = shell;
|
||||
_settings = settings;
|
||||
Languages = Core.Localization.Languages.Shipped
|
||||
.Select(c => new LanguageOption(c, Core.Localization.Languages.NativeName(c)))
|
||||
.ToList();
|
||||
SelectPageCommand = new RelayCommand(p =>
|
||||
{
|
||||
if (p is string page) Page = page;
|
||||
});
|
||||
}
|
||||
|
||||
public ShellViewModel Shell { get; }
|
||||
|
||||
public IReadOnlyList<string> Pages { get; } = ["General", "Advanced"];
|
||||
|
||||
public ICommand SelectPageCommand { get; }
|
||||
|
||||
public string Page
|
||||
{
|
||||
get => _page;
|
||||
set => Set(ref _page, value);
|
||||
}
|
||||
|
||||
public IReadOnlyList<LanguageOption> Languages { get; }
|
||||
|
||||
public LanguageOption SelectedLanguage
|
||||
{
|
||||
get => Languages.FirstOrDefault(l => l.Code.Equals(Loc.Culture.Name, StringComparison.OrdinalIgnoreCase)) ?? Languages[0];
|
||||
set
|
||||
{
|
||||
if (value is null) return;
|
||||
_settings.Language = value.Code;
|
||||
App.Current.ApplyLanguage(value.Code);
|
||||
App.Current.SaveSettings();
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsDarkTheme
|
||||
{
|
||||
get => _settings.Theme == AppTheme.Dark;
|
||||
set
|
||||
{
|
||||
if (value) ApplyTheme(AppTheme.Dark);
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsLightTheme
|
||||
{
|
||||
get => _settings.Theme == AppTheme.Light;
|
||||
set
|
||||
{
|
||||
if (value) ApplyTheme(AppTheme.Light);
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsSystemTheme
|
||||
{
|
||||
get => _settings.Theme == AppTheme.System;
|
||||
set
|
||||
{
|
||||
if (value) ApplyTheme(AppTheme.System);
|
||||
}
|
||||
}
|
||||
|
||||
public bool CheckForUpdates
|
||||
{
|
||||
get => _settings.CheckForUpdates;
|
||||
set
|
||||
{
|
||||
_settings.CheckForUpdates = value;
|
||||
App.Current.SaveSettings();
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyTheme(AppTheme theme)
|
||||
{
|
||||
_settings.Theme = theme;
|
||||
ThemeManager.Apply(theme);
|
||||
App.Current.SaveSettings();
|
||||
OnPropertyChanged(nameof(IsDarkTheme));
|
||||
OnPropertyChanged(nameof(IsLightTheme));
|
||||
OnPropertyChanged(nameof(IsSystemTheme));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>About (BRIEF §12.9).</summary>
|
||||
public sealed class AboutViewModel(ShellViewModel shell) : SectionViewModel(SectionKey.About, "Icon.About")
|
||||
{
|
||||
public ShellViewModel Shell { get; } = shell;
|
||||
|
||||
public string Version => typeof(App).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion ?? "0.0.0";
|
||||
|
||||
public string Runtime => System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription;
|
||||
|
||||
public string OperatingSystem => System.Runtime.InteropServices.RuntimeInformation.OSDescription;
|
||||
|
||||
public string DataFolder => App.Current.Environment.DataDirectory;
|
||||
|
||||
public ICommand OpenDataFolderCommand => new RelayCommand(() => ShellActions.OpenFolder(DataFolder));
|
||||
|
||||
public ICommand OpenReleasesCommand => new RelayCommand(() => ShellActions.OpenUrl(ProductLinks.Releases));
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<UserControl x:Class="Titano.App.Sections.SequenceView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="clr-namespace:Titano.Ui.Controls;assembly=Titano.Ui"
|
||||
xmlns:l="clr-namespace:Titano.Ui.Localization;assembly=Titano.Ui">
|
||||
<Grid Margin="20">
|
||||
<ui:EmptyState Message="{l:Loc Editor.Empty}">
|
||||
<Button Style="{StaticResource Button.Primary}" Content="{l:Loc Shell.Nav.Library}" Command="{Binding OpenLibraryCommand}" ToolTip="{l:Loc Tooltips.Nav.Library}" />
|
||||
</ui:EmptyState>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,8 @@
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Titano.App.Sections;
|
||||
|
||||
public partial class SequenceView : UserControl
|
||||
{
|
||||
public SequenceView() => InitializeComponent();
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<UserControl x:Class="Titano.App.Sections.ServerView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="clr-namespace:Titano.Ui.Controls;assembly=Titano.Ui"
|
||||
xmlns:l="clr-namespace:Titano.Ui.Localization;assembly=Titano.Ui">
|
||||
<Grid Margin="20">
|
||||
<ui:EmptyState Message="{l:Loc Server.Empty}" />
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,8 @@
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Titano.App.Sections;
|
||||
|
||||
public partial class ServerView : UserControl
|
||||
{
|
||||
public ServerView() => InitializeComponent();
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<UserControl x:Class="Titano.App.Sections.SettingsView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="clr-namespace:Titano.Ui.Controls;assembly=Titano.Ui"
|
||||
xmlns:l="clr-namespace:Titano.Ui.Localization;assembly=Titano.Ui"
|
||||
xmlns:s="clr-namespace:Titano.App.Sections">
|
||||
<Grid Margin="20,16,20,20">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="200" />
|
||||
<ColumnDefinition Width="16" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- Section list -->
|
||||
<ListBox ItemsSource="{Binding Pages}" SelectedItem="{Binding Page}">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Converter={x:Static s:SettingsPageNameConverter.Instance}}" />
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
|
||||
<Border Grid.Column="2" Style="{StaticResource Border.Panel}" Padding="22,18">
|
||||
<Grid>
|
||||
<!-- General -->
|
||||
<StackPanel x:Name="General">
|
||||
<StackPanel.Style>
|
||||
<Style TargetType="StackPanel">
|
||||
<Setter Property="Visibility" Value="Collapsed" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding Page}" Value="General"><Setter Property="Visibility" Value="Visible" /></DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</StackPanel.Style>
|
||||
<TextBlock Text="{l:Loc Settings.Page.General}" Style="{StaticResource Text.PageTitle}" Margin="0,0,0,16" />
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="180" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="44" />
|
||||
<RowDefinition Height="44" />
|
||||
<RowDefinition Height="44" />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Text="{l:Loc Settings.General.Language}" Foreground="{DynamicResource Brush.TextMuted}" />
|
||||
<ComboBox Grid.Column="1" Width="240" HorizontalAlignment="Left" ItemsSource="{Binding Languages}" SelectedItem="{Binding SelectedLanguage}"
|
||||
DisplayMemberPath="Name" ToolTip="{l:Loc Tooltips.Settings.Language}" />
|
||||
<TextBlock Grid.Row="1" Text="{l:Loc Settings.General.Theme}" Foreground="{DynamicResource Brush.TextMuted}" />
|
||||
<StackPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<RadioButton GroupName="Theme" Content="{l:Loc Settings.General.Theme.Dark}" IsChecked="{Binding IsDarkTheme}" ToolTip="{l:Loc Tooltips.Settings.ThemeDark}" Margin="0,0,20,0" />
|
||||
<RadioButton GroupName="Theme" Content="{l:Loc Settings.General.Theme.Light}" IsChecked="{Binding IsLightTheme}" ToolTip="{l:Loc Tooltips.Settings.ThemeLight}" Margin="0,0,20,0" />
|
||||
<RadioButton GroupName="Theme" Content="{l:Loc Settings.General.Theme.System}" IsChecked="{Binding IsSystemTheme}" ToolTip="{l:Loc Tooltips.Settings.ThemeSystem}" />
|
||||
</StackPanel>
|
||||
<TextBlock Grid.Row="2" Text="{l:Loc Settings.General.Updates}" Foreground="{DynamicResource Brush.TextMuted}" />
|
||||
<CheckBox Grid.Row="2" Grid.Column="1" Content="{l:Loc Settings.General.CheckOnStart}" IsChecked="{Binding CheckForUpdates}" ToolTip="{l:Loc Tooltips.Settings.CheckForUpdates}" />
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
|
||||
<!-- Advanced -->
|
||||
<StackPanel>
|
||||
<StackPanel.Style>
|
||||
<Style TargetType="StackPanel">
|
||||
<Setter Property="Visibility" Value="Collapsed" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding Page}" Value="Advanced"><Setter Property="Visibility" Value="Visible" /></DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</StackPanel.Style>
|
||||
<TextBlock Text="{l:Loc Settings.Page.Advanced}" Style="{StaticResource Text.PageTitle}" Margin="0,0,0,16" />
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="180" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="44" />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Text="{l:Loc Settings.Advanced.DataFolder}" Foreground="{DynamicResource Brush.TextMuted}" />
|
||||
<TextBox Grid.Column="1" IsReadOnly="True" Text="{Binding Shell.About.DataFolder, Mode=OneWay}" ToolTip="{l:Loc Tooltips.Settings.DataFolder}" />
|
||||
<Button Grid.Column="2" Margin="8,0,0,0" Content="{l:Loc Common.Open}" Command="{Binding Shell.About.OpenDataFolderCommand}" ToolTip="{l:Loc Tooltips.Settings.OpenDataFolder}" />
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,22 @@
|
||||
using System.Globalization;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using Titano.Core.Localization;
|
||||
|
||||
namespace Titano.App.Sections;
|
||||
|
||||
public partial class SettingsView : UserControl
|
||||
{
|
||||
public SettingsView() => InitializeComponent();
|
||||
}
|
||||
|
||||
/// <summary>Settings page id → localized page name.</summary>
|
||||
public sealed class SettingsPageNameConverter : IValueConverter
|
||||
{
|
||||
public static SettingsPageNameConverter Instance { get; } = new();
|
||||
|
||||
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) =>
|
||||
value is string page ? Loc.L("Settings.Page." + page) : string.Empty;
|
||||
|
||||
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => throw new NotSupportedException();
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<ui:TitanoWindow x:Class="Titano.App.Shell.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="clr-namespace:Titano.Ui.Controls;assembly=Titano.Ui"
|
||||
xmlns:l="clr-namespace:Titano.Ui.Localization;assembly=Titano.Ui"
|
||||
xmlns:shell="clr-namespace:Titano.App.Shell"
|
||||
Title="{Binding WindowTitle}"
|
||||
Width="1440" Height="900" MinWidth="1200" MinHeight="760"
|
||||
WindowStartupLocation="CenterScreen">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- Navigation rail: full names, collapsible to icons (BRIEF §12.1). -->
|
||||
<Border x:Name="Rail" Background="{DynamicResource Brush.Chrome}" Width="128" ui:NavRail.IsCollapsed="{Binding IsRailCollapsed}">
|
||||
<DockPanel Margin="8,8,8,8" LastChildFill="False">
|
||||
<Button DockPanel.Dock="Top" Style="{StaticResource Button.IconSubtle}" HorizontalAlignment="Left" Margin="0,0,0,6"
|
||||
ui:ButtonIcon.Glyph="{StaticResource Icon.Menu}" Command="{Binding ToggleRailCommand}"
|
||||
ToolTip="{Binding RailToggleToolTip}" AutomationProperties.Name="{Binding RailToggleToolTip}" />
|
||||
<ItemsControl DockPanel.Dock="Top" ItemsSource="{Binding TopSections}" Focusable="False">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type shell:SectionViewModel}">
|
||||
<ui:NavRailButton GroupName="Rail" Glyph="{Binding Glyph}" Content="{Binding Label}" Badge="{Binding Badge}"
|
||||
IsChecked="{Binding IsSelected}" ToolTip="{Binding ToolTip}" AutomationProperties.Name="{Binding Label}"
|
||||
Command="{Binding DataContext.NavigateCommand, RelativeSource={RelativeSource AncestorType=ItemsControl}}" CommandParameter="{Binding}" />
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
<ItemsControl DockPanel.Dock="Bottom" ItemsSource="{Binding BottomSections}" Focusable="False">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type shell:SectionViewModel}">
|
||||
<ui:NavRailButton GroupName="Rail" Glyph="{Binding Glyph}" Content="{Binding Label}" Badge="{Binding Badge}"
|
||||
IsChecked="{Binding IsSelected}" ToolTip="{Binding ToolTip}" AutomationProperties.Name="{Binding Label}"
|
||||
Command="{Binding DataContext.NavigateCommand, RelativeSource={RelativeSource AncestorType=ItemsControl}}" CommandParameter="{Binding}" />
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</DockPanel>
|
||||
</Border>
|
||||
|
||||
<Grid Grid.Column="1">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<ui:JobBar Text="{Binding JobText}" Progress="{Binding JobProgress}" IsActive="{Binding IsJobActive}" IsIndeterminate="{Binding IsJobIndeterminate}"
|
||||
StopCommand="{Binding StopJobCommand}" StopToolTip="{l:Loc Tooltips.Shell.StopJob}" />
|
||||
|
||||
<ContentControl Grid.Row="1" Content="{Binding Current}" Focusable="False" />
|
||||
|
||||
<!-- Status strip -->
|
||||
<Border Grid.Row="2" Height="30" Background="{DynamicResource Brush.Chrome}" Padding="20,0">
|
||||
<StackPanel Orientation="Horizontal" TextElement.FontSize="12" TextElement.Foreground="{DynamicResource Brush.TextMuted}">
|
||||
<TextBlock Text="{Binding SequencesText}" Margin="0,0,18,0" />
|
||||
<TextBlock Text="{Binding PhotosText}" Margin="0,0,18,0" />
|
||||
<TextBlock Text="{Binding StorageText}" Margin="0,0,18,0" />
|
||||
<TextBlock x:Name="Connection" Text="{Binding ConnectionText}" Margin="0,0,18,0" />
|
||||
<TextBlock Text="{Binding JobsText}" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<ui:ToastHost x:Name="Toasts" Grid.Row="0" Grid.RowSpan="3" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</ui:TitanoWindow>
|
||||
@@ -0,0 +1,63 @@
|
||||
using System.Collections.Specialized;
|
||||
using System.Windows;
|
||||
using Titano.Ui.Controls;
|
||||
|
||||
namespace Titano.App.Shell;
|
||||
|
||||
public partial class MainWindow : TitanoWindow
|
||||
{
|
||||
private readonly ShellViewModel _shell;
|
||||
|
||||
public MainWindow(ShellViewModel shell)
|
||||
{
|
||||
_shell = shell;
|
||||
DataContext = shell;
|
||||
InitializeComponent();
|
||||
Rail.Width = shell.IsRailCollapsed ? 48 : 128;
|
||||
shell.PropertyChanged += (_, e) =>
|
||||
{
|
||||
if (e.PropertyName is nameof(ShellViewModel.IsRailCollapsed) or "")
|
||||
Rail.Width = shell.IsRailCollapsed ? 48 : 128;
|
||||
if (e.PropertyName is nameof(ShellViewModel.IsConnected) or "")
|
||||
Connection.Foreground = (System.Windows.Media.Brush)FindResource(shell.IsConnected ? "Brush.Accent" : "Brush.TextMuted");
|
||||
};
|
||||
shell.PendingToasts.CollectionChanged += OnToastRequested;
|
||||
RestorePlacement();
|
||||
Closing += (_, _) => SavePlacement();
|
||||
}
|
||||
|
||||
private void OnToastRequested(object? sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
if (e.Action != NotifyCollectionChangedAction.Add || e.NewItems is null) return;
|
||||
foreach (Toast t in e.NewItems) Toasts.Show(t);
|
||||
Dispatcher.BeginInvoke(() => _shell.PendingToasts.Clear());
|
||||
}
|
||||
|
||||
private void RestorePlacement()
|
||||
{
|
||||
var p = App.Current.Settings.Window;
|
||||
if (p is null || p.Width < MinWidth || p.Height < MinHeight) return;
|
||||
var virtualScreen = new Rect(SystemParameters.VirtualScreenLeft, SystemParameters.VirtualScreenTop, SystemParameters.VirtualScreenWidth, SystemParameters.VirtualScreenHeight);
|
||||
var rect = new Rect(p.Left, p.Top, p.Width, p.Height);
|
||||
if (!virtualScreen.IntersectsWith(rect)) return;
|
||||
WindowStartupLocation = WindowStartupLocation.Manual;
|
||||
Left = p.Left;
|
||||
Top = p.Top;
|
||||
Width = p.Width;
|
||||
Height = p.Height;
|
||||
if (p.Maximized) WindowState = WindowState.Maximized;
|
||||
}
|
||||
|
||||
private void SavePlacement()
|
||||
{
|
||||
var b = RestoreBounds;
|
||||
App.Current.Settings.Window = new Infrastructure.AppSettings.WindowPlacement
|
||||
{
|
||||
Left = b.Left,
|
||||
Top = b.Top,
|
||||
Width = b.Width,
|
||||
Height = b.Height,
|
||||
Maximized = WindowState == WindowState.Maximized,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Threading;
|
||||
using Titano.Core.Diagnostics;
|
||||
using Titano.Ui.Theming;
|
||||
|
||||
namespace Titano.App.Shell;
|
||||
|
||||
/// <summary>
|
||||
/// <c>Titano.exe --capture <dir></c>: renders every section at 1440×900 in dark and light themes to PNG for
|
||||
/// visual regression and phase reports (BRIEF §20.2), then exits.
|
||||
/// </summary>
|
||||
public static class ScreenCapture
|
||||
{
|
||||
public static void Run(MainWindow window, ShellViewModel shell, string directory)
|
||||
{
|
||||
Directory.CreateDirectory(directory);
|
||||
window.WindowStartupLocation = WindowStartupLocation.Manual;
|
||||
window.Left = -20000;
|
||||
window.Top = -20000;
|
||||
window.Width = 1440;
|
||||
window.Height = 900;
|
||||
window.ShowActivated = false;
|
||||
window.ShowInTaskbar = false;
|
||||
window.Show();
|
||||
|
||||
window.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (var theme in new[] { AppTheme.Dark, AppTheme.Light })
|
||||
{
|
||||
ThemeManager.Apply(theme);
|
||||
foreach (var section in shell.AllSections)
|
||||
{
|
||||
shell.Navigate(section.Key);
|
||||
Settle(window);
|
||||
Save(window, Path.Combine(directory, $"{section.Key}-{theme.ToString().ToLowerInvariant()}.png"));
|
||||
}
|
||||
}
|
||||
Log.Info("capture", $"Screenshots written to {Path.GetFullPath(directory)}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error("capture", "Capture failed", ex);
|
||||
Environment.ExitCode = 1;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Application.Current.Shutdown();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void Settle(Window window)
|
||||
{
|
||||
window.UpdateLayout();
|
||||
// Let bindings, templates and deferred renders complete.
|
||||
window.Dispatcher.Invoke(DispatcherPriority.ApplicationIdle, () => { });
|
||||
window.UpdateLayout();
|
||||
}
|
||||
|
||||
private static void Save(Window window, string path)
|
||||
{
|
||||
if (VisualTreeHelper.GetChildrenCount(window) == 0) return;
|
||||
var root = (FrameworkElement)VisualTreeHelper.GetChild(window, 0);
|
||||
var dpi = VisualTreeHelper.GetDpi(window);
|
||||
var width = (int)Math.Ceiling(root.ActualWidth * dpi.DpiScaleX);
|
||||
var height = (int)Math.Ceiling(root.ActualHeight * dpi.DpiScaleY);
|
||||
if (width <= 0 || height <= 0) return;
|
||||
var bitmap = new RenderTargetBitmap(width, height, dpi.PixelsPerInchX, dpi.PixelsPerInchY, PixelFormats.Pbgra32);
|
||||
bitmap.Render(root);
|
||||
var encoder = new PngBitmapEncoder();
|
||||
encoder.Frames.Add(BitmapFrame.Create(bitmap));
|
||||
using var stream = File.Create(path);
|
||||
encoder.Save(stream);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:s="clr-namespace:Titano.App.Sections">
|
||||
<!-- Section view model → view. -->
|
||||
<DataTemplate DataType="{x:Type s:LibraryViewModel}"><s:LibraryView /></DataTemplate>
|
||||
<DataTemplate DataType="{x:Type s:ImportViewModel}"><s:ImportView /></DataTemplate>
|
||||
<DataTemplate DataType="{x:Type s:SequenceViewModel}"><s:SequenceView /></DataTemplate>
|
||||
<DataTemplate DataType="{x:Type s:ArchiveViewModel}"><s:ArchiveView /></DataTemplate>
|
||||
<DataTemplate DataType="{x:Type s:JobsViewModel}"><s:JobsView /></DataTemplate>
|
||||
<DataTemplate DataType="{x:Type s:ServerViewModel}"><s:ServerView /></DataTemplate>
|
||||
<DataTemplate DataType="{x:Type s:SettingsViewModel}"><s:SettingsView /></DataTemplate>
|
||||
<DataTemplate DataType="{x:Type s:AboutViewModel}"><s:AboutView /></DataTemplate>
|
||||
</ResourceDictionary>
|
||||
@@ -0,0 +1,59 @@
|
||||
using Titano.Ui.Controls;
|
||||
using Titano.Ui.Mvvm;
|
||||
|
||||
namespace Titano.App.Shell;
|
||||
|
||||
public enum SectionKey
|
||||
{
|
||||
Library,
|
||||
Import,
|
||||
Sequence,
|
||||
Archive,
|
||||
Jobs,
|
||||
Server,
|
||||
Settings,
|
||||
About,
|
||||
}
|
||||
|
||||
/// <summary>A top-level destination of the navigation rail.</summary>
|
||||
public abstract class SectionViewModel(SectionKey key, string iconKey) : LocalizedViewModel
|
||||
{
|
||||
private bool _isSelected;
|
||||
private int _badge;
|
||||
|
||||
public SectionKey Key { get; } = key;
|
||||
|
||||
/// <summary>Resource key of the rail icon (e.g. "Icon.Library").</summary>
|
||||
public string IconKey { get; } = iconKey;
|
||||
|
||||
public IconData? Glyph => System.Windows.Application.Current?.TryFindResource(IconKey) as IconData;
|
||||
|
||||
/// <summary>Rail label ("Library").</summary>
|
||||
public string Label => Core.Localization.Loc.L("Shell.Nav." + Key);
|
||||
|
||||
/// <summary>Rail tooltip: what the section is for.</summary>
|
||||
public string ToolTip => Core.Localization.Loc.L("Tooltips.Nav." + Key);
|
||||
|
||||
/// <summary>Window title suffix ("Titano — Import").</summary>
|
||||
public virtual string Title => Label;
|
||||
|
||||
public bool IsSelected
|
||||
{
|
||||
get => _isSelected;
|
||||
set
|
||||
{
|
||||
if (Set(ref _isSelected, value) && value) OnActivated();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Count of items needing attention, shown as a rail badge.</summary>
|
||||
public int Badge
|
||||
{
|
||||
get => _badge;
|
||||
protected set => Set(ref _badge, value);
|
||||
}
|
||||
|
||||
protected virtual void OnActivated()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows.Input;
|
||||
using Titano.App.Infrastructure;
|
||||
using Titano.App.Sections;
|
||||
using Titano.Core.Diagnostics;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Ui.Controls;
|
||||
using Titano.Ui.Mvvm;
|
||||
|
||||
namespace Titano.App.Shell;
|
||||
|
||||
/// <summary>State of the main window: rail, current section, job bar and status strip (BRIEF §12.1).</summary>
|
||||
public sealed class ShellViewModel : LocalizedViewModel
|
||||
{
|
||||
private readonly AppSettings _settings;
|
||||
private SectionViewModel _current;
|
||||
private bool _isRailCollapsed;
|
||||
private string? _jobText;
|
||||
private double _jobProgress;
|
||||
private bool _jobActive;
|
||||
private bool _jobIndeterminate;
|
||||
private long _sequenceCount;
|
||||
private long _photoCount;
|
||||
private long _totalBytes;
|
||||
private string? _serverName;
|
||||
private int _jobCount;
|
||||
|
||||
public ShellViewModel(AppSettings settings)
|
||||
{
|
||||
_settings = settings;
|
||||
_isRailCollapsed = settings.RailCollapsed;
|
||||
Library = new LibraryViewModel(this);
|
||||
Import = new ImportViewModel(this);
|
||||
Sequence = new SequenceViewModel(this);
|
||||
Archive = new ArchiveViewModel(this);
|
||||
Jobs = new JobsViewModel(this);
|
||||
Server = new ServerViewModel(this);
|
||||
Settings = new SettingsViewModel(this, settings);
|
||||
About = new AboutViewModel(this);
|
||||
TopSections = [Library, Import, Sequence, Archive, Jobs, Server];
|
||||
BottomSections = [Settings, About];
|
||||
_current = Library;
|
||||
Library.IsSelected = true;
|
||||
|
||||
NavigateCommand = new RelayCommand(p =>
|
||||
{
|
||||
if (p is SectionViewModel s) Navigate(s.Key);
|
||||
else if (p is SectionKey k) Navigate(k);
|
||||
else if (p is string name && Enum.TryParse<SectionKey>(name, out var key)) Navigate(key);
|
||||
});
|
||||
ToggleRailCommand = new RelayCommand(() => IsRailCollapsed = !IsRailCollapsed);
|
||||
}
|
||||
|
||||
public LibraryViewModel Library { get; }
|
||||
public ImportViewModel Import { get; }
|
||||
public SequenceViewModel Sequence { get; }
|
||||
public ArchiveViewModel Archive { get; }
|
||||
public JobsViewModel Jobs { get; }
|
||||
public ServerViewModel Server { get; }
|
||||
public SettingsViewModel Settings { get; }
|
||||
public AboutViewModel About { get; }
|
||||
|
||||
public IReadOnlyList<SectionViewModel> TopSections { get; }
|
||||
public IReadOnlyList<SectionViewModel> BottomSections { get; }
|
||||
public IEnumerable<SectionViewModel> AllSections => TopSections.Concat(BottomSections);
|
||||
|
||||
public ICommand NavigateCommand { get; }
|
||||
public ICommand ToggleRailCommand { get; }
|
||||
|
||||
/// <summary>In-window notifications; the window binds its <see cref="ToastHost"/> here.</summary>
|
||||
public ObservableCollection<Toast> PendingToasts { get; } = [];
|
||||
|
||||
public SectionViewModel Current
|
||||
{
|
||||
get => _current;
|
||||
private set
|
||||
{
|
||||
if (Set(ref _current, value)) OnPropertyChanged(nameof(WindowTitle));
|
||||
}
|
||||
}
|
||||
|
||||
public string WindowTitle => Current == Library ? "Titano" : "Titano — " + Current.Title;
|
||||
|
||||
public bool IsRailCollapsed
|
||||
{
|
||||
get => _isRailCollapsed;
|
||||
set
|
||||
{
|
||||
if (!Set(ref _isRailCollapsed, value)) return;
|
||||
_settings.RailCollapsed = value;
|
||||
OnPropertyChanged(nameof(RailToggleToolTip));
|
||||
}
|
||||
}
|
||||
|
||||
public string RailToggleToolTip => Loc.L(IsRailCollapsed ? "Tooltips.Shell.ExpandRail" : "Tooltips.Shell.CollapseRail");
|
||||
|
||||
// ---- Job bar ----
|
||||
public string JobText => _jobActive && _jobText is not null ? _jobText : Loc.L("Shell.JobBar.Ready", _jobCount);
|
||||
public double JobProgress { get => _jobProgress; private set => Set(ref _jobProgress, value); }
|
||||
public bool IsJobActive { get => _jobActive; private set => Set(ref _jobActive, value); }
|
||||
public bool IsJobIndeterminate { get => _jobIndeterminate; private set => Set(ref _jobIndeterminate, value); }
|
||||
public ICommand? StopJobCommand { get; set; }
|
||||
|
||||
/// <summary>Updates the global job bar (and the taskbar progress through the window).</summary>
|
||||
public void SetJob(string? text, double progress, bool indeterminate = false)
|
||||
{
|
||||
_jobText = text;
|
||||
IsJobActive = text is not null;
|
||||
JobProgress = progress;
|
||||
IsJobIndeterminate = indeterminate;
|
||||
OnPropertyChanged(nameof(JobText));
|
||||
}
|
||||
|
||||
// ---- Status strip ----
|
||||
public string SequencesText => Loc.Plural("Shell.Status.Sequences", _sequenceCount);
|
||||
public string PhotosText => Loc.Plural("Shell.Status.Photos", _photoCount);
|
||||
public string StorageText => Formatting.Bytes(_totalBytes);
|
||||
public string ConnectionText => _serverName is null ? Loc.L("Shell.Status.NotConnected") : Loc.L("Shell.Status.Connected", _serverName);
|
||||
public bool IsConnected => _serverName is not null;
|
||||
public string JobsText => Loc.Plural("Shell.Status.Jobs", _jobCount);
|
||||
|
||||
public void SetLibraryTotals(long sequences, long photos, long bytes)
|
||||
{
|
||||
_sequenceCount = sequences;
|
||||
_photoCount = photos;
|
||||
_totalBytes = bytes;
|
||||
OnPropertyChanged(nameof(SequencesText));
|
||||
OnPropertyChanged(nameof(PhotosText));
|
||||
OnPropertyChanged(nameof(StorageText));
|
||||
}
|
||||
|
||||
public void SetConnection(string? serverName)
|
||||
{
|
||||
_serverName = serverName;
|
||||
OnPropertyChanged(nameof(ConnectionText));
|
||||
OnPropertyChanged(nameof(IsConnected));
|
||||
}
|
||||
|
||||
public void SetJobCount(int count)
|
||||
{
|
||||
_jobCount = count;
|
||||
OnPropertyChanged(nameof(JobsText));
|
||||
OnPropertyChanged(nameof(JobText));
|
||||
}
|
||||
|
||||
public void Navigate(SectionKey key)
|
||||
{
|
||||
var target = AllSections.First(s => s.Key == key);
|
||||
foreach (var s in AllSections) s.IsSelected = ReferenceEquals(s, target);
|
||||
Current = target;
|
||||
}
|
||||
|
||||
public void ShowToast(Toast toast) => PendingToasts.Add(toast);
|
||||
|
||||
/// <summary>Errors are one sentence saying what happened plus one action (BRIEF §0.2 rule 6).</summary>
|
||||
public void ReportError(Exception ex)
|
||||
{
|
||||
Log.Error("ui", "Operation failed", ex);
|
||||
ShowToast(new Toast
|
||||
{
|
||||
Title = Loc.L("Errors.Unexpected"),
|
||||
Message = ex.Message,
|
||||
ActionText = Loc.L("Common.OpenLogs"),
|
||||
ActionToolTip = Loc.L("Tooltips.Common.OpenLogs"),
|
||||
ActionCommand = new RelayCommand(() => ShellActions.OpenFolder(App.Current.Environment.LogDirectory)),
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user