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