using System; using Avalonia.Controls; using Avalonia.Markup.Xaml; using Avalonia.Platform; using detect.gui.Services; using detect.gui.ViewModels; using Serilog; using Splat; namespace detect.gui.Views; public partial class WebBrowserWindow : Window { public UserControl? ParentContent { get; set; } public WebBrowserWindow() { InitializeComponent(); DataContext = new WebViewModel(); ExtendClientAreaToDecorationsHint = true; ExtendClientAreaChromeHints = ExtendClientAreaChromeHints.NoChrome; ExtendClientAreaTitleBarHeightHint = -1; SystemDecorations = SystemDecorations.None; ShowInTaskbar = false; Topmost = true; CanResize = false; } protected override void OnOpened(EventArgs e) { base.OnOpened(e); var service = Locator.Current.GetService(); if (WebView != null) { WebView.RegisterJavascriptObject("DeviceClientService", service); } else { Log.Warning("WebView is null!"); } } private void InitializeComponent() { AvaloniaXamlLoader.Load(this); } // public void InitUI(int? index = null) // { // if (ParentContent == null) return; // var timer = new Timer(_ => // { // Dispatcher.UIThread.InvokeAsync(() => // { // if (!ParentContent.IsAttachedToVisualTree()) return; // Width = ParentContent.Get("WebView").Bounds.Width; // Height = ParentContent.Get("WebView").Bounds.Height; // Position = ParentContent.Get("WebView").PointToScreen(new Point(0, 0)); // if (index != null) // SetAddress(index.Value); // if (!IsVisible) // Show(); // }); // }); // timer.Change(100, 0); // } public void SetAddress(int index) { (DataContext as WebViewModel)!.SetAddress(index); } }