2026-10-01 16:57:12 +08:00
|
|
|
using System.Linq;
|
2026-09-29 20:16:52 +08:00
|
|
|
using Avalonia;
|
|
|
|
|
using Avalonia.Controls.ApplicationLifetimes;
|
|
|
|
|
using Avalonia.Data.Core;
|
|
|
|
|
using Avalonia.Data.Core.Plugins;
|
|
|
|
|
using Avalonia.Markup.Xaml;
|
2026-10-02 14:29:42 +08:00
|
|
|
using Avalonia.Threading;
|
|
|
|
|
using YKanBan.Ipc;
|
2026-09-29 20:16:52 +08:00
|
|
|
using YKanBan.ViewModels;
|
|
|
|
|
using YKanBan.Views;
|
|
|
|
|
|
|
|
|
|
namespace YKanBan;
|
|
|
|
|
|
|
|
|
|
public partial class App : Application
|
|
|
|
|
{
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
AvaloniaXamlLoader.Load(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnFrameworkInitializationCompleted()
|
|
|
|
|
{
|
|
|
|
|
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
|
|
|
|
{
|
|
|
|
|
DisableAvaloniaDataAnnotationValidation();
|
|
|
|
|
desktop.MainWindow = new MainWindow
|
|
|
|
|
{
|
|
|
|
|
DataContext = new MainWindowViewModel(),
|
|
|
|
|
};
|
2026-10-02 14:29:42 +08:00
|
|
|
|
|
|
|
|
// Primary instance: serve launch commands forwarded by secondary instances.
|
|
|
|
|
Program.SingleInstance?.StartServer(command => HandleLaunchCommand(desktop, command));
|
2026-09-29 20:16:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base.OnFrameworkInitializationCompleted();
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-02 14:29:42 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// Brings the main window to front for a forwarded launch command. Both
|
|
|
|
|
/// ShowMain and OpenWorkspace activate the window; switching to the
|
|
|
|
|
/// requested workspace lands together with the workspace UI.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private static void HandleLaunchCommand(IClassicDesktopStyleApplicationLifetime desktop, LaunchCommand command)
|
|
|
|
|
{
|
|
|
|
|
// IPC delivery happens on a background thread; window access must hop to the UI thread.
|
|
|
|
|
Dispatcher.UIThread.Post(() =>
|
|
|
|
|
{
|
|
|
|
|
if (desktop.MainWindow is { } window)
|
|
|
|
|
{
|
|
|
|
|
window.Show();
|
|
|
|
|
window.Activate();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void DisableAvaloniaDataAnnotationValidation()
|
2026-09-29 20:16:52 +08:00
|
|
|
{
|
|
|
|
|
var dataValidationPluginsToRemove =
|
|
|
|
|
BindingPlugins.DataValidators.OfType<DataAnnotationsValidationPlugin>().ToArray();
|
|
|
|
|
|
|
|
|
|
foreach (var plugin in dataValidationPluginsToRemove)
|
|
|
|
|
{
|
|
|
|
|
BindingPlugins.DataValidators.Remove(plugin);
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-10-01 16:57:12 +08:00
|
|
|
}
|