From c0ad2ca12a23eacfb6aa03cdfbcb9dc59a6f58eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=86=8A=E7=8E=AE?= Date: Fri, 15 Nov 2024 14:49:29 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- detect.gui/App.axaml.cs | 2 +- detect.gui/Services/DeviceClientService.cs | 12 ++++++++++- detect.gui/Views/DeviceView.axaml.cs | 3 +-- detect.gui/Views/WebBrowserWindow.axaml.cs | 25 ++++++++++++++++------ detect.sln.DotSettings.user | 5 ++++- 5 files changed, 35 insertions(+), 12 deletions(-) diff --git a/detect.gui/App.axaml.cs b/detect.gui/App.axaml.cs index 4585c05..b64215b 100644 --- a/detect.gui/App.axaml.cs +++ b/detect.gui/App.axaml.cs @@ -38,7 +38,7 @@ public class App : Application Locator.CurrentMutable.Register(() => new DetectTaskProgressService(), typeof(DetectTaskProgressService)); Locator.CurrentMutable.Register(() => new DetectLogService(), typeof(DetectLogService)); - Locator.CurrentMutable.Register(() => new DeviceClientService(), typeof(DeviceClientService)); + Locator.CurrentMutable.Register(DeviceClientService.Instance, typeof(DeviceClientService)); Locator.Current.GetService(); new MainView { DataContext = Locator.Current.GetService() }.Show(); diff --git a/detect.gui/Services/DeviceClientService.cs b/detect.gui/Services/DeviceClientService.cs index cab47b6..f8e4cf7 100644 --- a/detect.gui/Services/DeviceClientService.cs +++ b/detect.gui/Services/DeviceClientService.cs @@ -19,7 +19,17 @@ public class DeviceClientService public DeviceClientService() { ConnectAllDevices(); - Log.Warning("DeviceClientService Initializing..."); + Log.Information("DeviceClientService Initialize Done."); + } + + private static DeviceClientService? _instance; + public static DeviceClientService Instance() + { + if (_instance == null) + { + _instance = new DeviceClientService(); + } + return _instance; } /// diff --git a/detect.gui/Views/DeviceView.axaml.cs b/detect.gui/Views/DeviceView.axaml.cs index 6673b00..b6e7625 100644 --- a/detect.gui/Views/DeviceView.axaml.cs +++ b/detect.gui/Views/DeviceView.axaml.cs @@ -1,5 +1,4 @@ -using Avalonia.Controls; -using Avalonia.Interactivity; +using Avalonia.Interactivity; using Avalonia.Markup.Xaml; using Avalonia.ReactiveUI; using detect.gui.Commons; diff --git a/detect.gui/Views/WebBrowserWindow.axaml.cs b/detect.gui/Views/WebBrowserWindow.axaml.cs index 93f4597..1839d9d 100644 --- a/detect.gui/Views/WebBrowserWindow.axaml.cs +++ b/detect.gui/Views/WebBrowserWindow.axaml.cs @@ -1,13 +1,10 @@ -using System.Threading; -using Avalonia; -using Avalonia.Controls; +using Avalonia.Controls; using Avalonia.Markup.Xaml; using Avalonia.Platform; -using Avalonia.ReactiveUI; -using Avalonia.Threading; -using Avalonia.VisualTree; +using detect.gui.Services; using detect.gui.ViewModels; -using ReactiveUI; +using Serilog; +using Splat; namespace detect.gui.Views; @@ -28,6 +25,20 @@ public partial class WebBrowserWindow : Window ShowInTaskbar = false; Topmost = true; CanResize = false; + + Opened += (sender, args) => + { + var service = Locator.Current.GetService(); + if (WebView != null) + { + WebView.RegisterJavascriptObject("DeviceClientService", service); + } + else + { + Log.Warning("WebView is null!"); + } + + }; } private void InitializeComponent() diff --git a/detect.sln.DotSettings.user b/detect.sln.DotSettings.user index 47e9f5a..89022d3 100644 --- a/detect.sln.DotSettings.user +++ b/detect.sln.DotSettings.user @@ -1,6 +1,9 @@  True + ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded - ForceIncluded \ No newline at end of file + ForceIncluded + ForceIncluded \ No newline at end of file