detect/detect.gui/VWS/MainWindow.axaml.cs

90 lines
2.5 KiB
C#
Raw Normal View History

2024-11-26 11:24:25 +08:00
using System;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using Avalonia.Platform;
2024-11-27 15:20:42 +08:00
using detect.gui.Services;
using detect.gui.Views;
2024-11-26 11:24:25 +08:00
using detect.gui.VWMS;
2024-11-27 15:20:42 +08:00
using Serilog;
2024-11-26 11:24:25 +08:00
using Splat;
2024-11-26 15:44:31 +08:00
using WebViewControl;
2024-11-26 11:24:25 +08:00
namespace detect.gui.VWS;
public partial class MainWindow : Window
{
private static MainWindow? _instance;
public static MainWindow Instance()
{
return _instance ??= new MainWindow();
}
2024-11-27 15:20:42 +08:00
2024-11-26 11:24:25 +08:00
public MainWindow()
{
InitializeComponent();
2024-11-27 15:20:42 +08:00
2024-11-26 11:24:25 +08:00
Icon = new WindowIcon(AssetLoader.Open(new Uri("avares://detect.gui/Assets/logo.ico")));
Title = "AI智能视频分析平台";
ExtendClientAreaToDecorationsHint = true;
ExtendClientAreaChromeHints = ExtendClientAreaChromeHints.NoChrome;
ExtendClientAreaTitleBarHeightHint = -1;
SystemDecorations = SystemDecorations.None;
Topmost = false;
CanResize = false;
2024-11-27 15:20:42 +08:00
2024-11-26 11:24:25 +08:00
if (Screens.Primary == null) return;
Width = Screens.Primary.Bounds.Width / Screens.Primary.Scaling;
Height = Screens.Primary.Bounds.Height / Screens.Primary.Scaling;
Position = new PixelPoint(0, 0);
DataContext = Locator.Current.GetService<MainWindowModel>();
2024-11-27 15:20:42 +08:00
var webview = this.Get<WebView>("WebView");
var service = Locator.Current.GetService<DeviceClientService>();
webview.RegisterJavascriptObject("DeviceClientService", service);
webview.RegisterJavascriptObject("WebViewService", new WebViewService(this));
Log.Information("WebView Initialized.");
2024-11-26 11:24:25 +08:00
}
2024-11-27 15:20:42 +08:00
2024-11-26 11:24:25 +08:00
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
2025-01-08 13:49:31 +08:00
// #if DEBUG
// this.AttachDevTools();
// #endif
2024-11-26 11:24:25 +08:00
}
2024-11-27 15:20:42 +08:00
// protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
// {
// base.OnApplyTemplate(e);
// NotificationService.SetHostWindow(this);
// }
2024-11-26 11:24:25 +08:00
private void MinClick(object? sender, RoutedEventArgs e)
{
WindowState = WindowState.Minimized;
}
private void MaxClick(object? sender, RoutedEventArgs e)
{
WindowState = WindowState.Maximized;
}
private void RestoreClick(object? sender, RoutedEventArgs e)
{
WindowState = WindowState.Normal;
}
2025-01-08 13:49:31 +08:00
private void CloseClick(object? sender, RoutedEventArgs e)
2024-11-26 11:24:25 +08:00
{
Close();
}
2024-11-27 15:20:42 +08:00
private void OnClosing(object? sender, WindowClosingEventArgs e)
2024-11-26 15:44:31 +08:00
{
this.Get<WebView>("WebView").Dispose();
2024-11-27 15:20:42 +08:00
Locator.Current.GetService<NotificationWindow>()!.Close();
2024-11-26 15:44:31 +08:00
}
2024-11-26 11:24:25 +08:00
}