|
@@ -0,0 +1,145 @@
|
|
|
+using System;
|
|
|
+using System.IO;
|
|
|
+using Avalonia;
|
|
|
+using Avalonia.Controls;
|
|
|
+using Avalonia.Markup.Xaml;
|
|
|
+using fis.Mac;
|
|
|
+using fis.Win;
|
|
|
+using Xilium.CefGlue.Avalonia;
|
|
|
+using System.Globalization;
|
|
|
+using System.Reflection;
|
|
|
+using System.Threading;
|
|
|
+using System.Runtime.InteropServices;
|
|
|
+using System.Collections.Generic;
|
|
|
+using Xilium.CefGlue.Common.Handlers;
|
|
|
+
|
|
|
+namespace fis
|
|
|
+{
|
|
|
+ public partial class SlaveWindow : Window
|
|
|
+ {
|
|
|
+ public static SynchronizationContext? MainThreadSyncContext;
|
|
|
+ private TextBlock? _title;
|
|
|
+ private AvaloniaCefBrowser? _browser;
|
|
|
+ private string _host;
|
|
|
+ private Dictionary<string, string> _parameters;
|
|
|
+
|
|
|
+ public SlaveWindow()
|
|
|
+ {
|
|
|
+ ExtendClientAreaToDecorationsHint = true;
|
|
|
+ ExtendClientAreaChromeHints = Avalonia.Platform.ExtendClientAreaChromeHints.NoChrome;
|
|
|
+ ExtendClientAreaTitleBarHeightHint = -1;
|
|
|
+ MainThreadSyncContext = SynchronizationContext.Current;
|
|
|
+#if DEBUG
|
|
|
+ this.AttachDevTools();
|
|
|
+#endif
|
|
|
+ }
|
|
|
+
|
|
|
+ public void init(string host, Dictionary<string, string> dictionary)
|
|
|
+ {
|
|
|
+ _parameters = dictionary;
|
|
|
+ _host = host;
|
|
|
+ InitializeComponent();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void InitializeComponent()
|
|
|
+ {
|
|
|
+ AvaloniaXamlLoader.Load(this);
|
|
|
+ var browserContainer = this.FindControl<Border>("BrowserBorder");
|
|
|
+
|
|
|
+ IPlatformService platformService;
|
|
|
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
|
+ {
|
|
|
+ this.FindControl<MacosTitleBar>("MacTitleBar").IsVisible = false;
|
|
|
+ _title = this.FindControl<WindowsTitleBar>("WinTitleBar").FindControl<TextBlock>("WindowsTitle");
|
|
|
+ platformService = new WinService();
|
|
|
+ }
|
|
|
+ else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
|
|
+ {
|
|
|
+ this.FindControl<WindowsTitleBar>("WinTitleBar").IsVisible = false;
|
|
|
+ _title = this.FindControl<MacosTitleBar>("MacTitleBar").FindControl<TextBlock>("MacosTitle");
|
|
|
+ platformService = new MacService();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ throw new NotSupportedException($"Platform {Environment.OSVersion.Platform} is not suppoorted.");
|
|
|
+ }
|
|
|
+ if (_host.Contains(ShellConfig.Instance.DistHost))
|
|
|
+ {
|
|
|
+ var appHandler = new FileSystemHostHandler(ShellConfig.Instance.DistHost, ShellConfig.Instance.DistResourcePath);
|
|
|
+ var handler = new HostRequestHandler();
|
|
|
+ handler.RegisterHostHandler(appHandler);
|
|
|
+ _browser = new AvaloniaCefBrowser
|
|
|
+ {
|
|
|
+ RequestHandler = handler
|
|
|
+ };
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ _browser = new AvaloniaCefBrowser();
|
|
|
+ }
|
|
|
+
|
|
|
+ var parameter = "";
|
|
|
+ var index = 0;
|
|
|
+ foreach (var p in _parameters)
|
|
|
+ {
|
|
|
+
|
|
|
+ parameter += p.Key + "=" + p.Value;
|
|
|
+ if (index < _parameters.Count - 1) {
|
|
|
+ parameter += "&";
|
|
|
+ }
|
|
|
+ index++;
|
|
|
+ }
|
|
|
+ //Make cross domain work.
|
|
|
+ if (parameter.Length > 0)
|
|
|
+ {
|
|
|
+ _browser.Address = _host + "?" + parameter;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ _browser.Address = _host;
|
|
|
+ }
|
|
|
+ _browser.BrowserInitialized += () =>
|
|
|
+ {
|
|
|
+#if DEBUG
|
|
|
+ _browser!.ShowDeveloperTools();
|
|
|
+#endif
|
|
|
+ };
|
|
|
+ browserContainer.Child = _browser;
|
|
|
+ WindowStartupLocation = WindowStartupLocation.Manual;
|
|
|
+ Position = new PixelPoint();
|
|
|
+ WindowState = WindowState.Maximized;
|
|
|
+ MinWidth = 1366;
|
|
|
+ MinHeight = 768;
|
|
|
+ var language = CultureInfo.CurrentCulture.Name;
|
|
|
+ if (_title != null)
|
|
|
+ {
|
|
|
+ if (language == "zh-CN")
|
|
|
+ {
|
|
|
+ _title.Text = "杏聆荟";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ _title.Text = "FLYINSONO";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var assembly = Assembly.GetExecutingAssembly();
|
|
|
+ Stream? resourceStream = null;
|
|
|
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
|
+ {
|
|
|
+ resourceStream = assembly.GetManifestResourceStream("fis.Win.flyinsono.ico");
|
|
|
+ }
|
|
|
+ else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
|
|
+ {
|
|
|
+ resourceStream = assembly.GetManifestResourceStream("fis.Mac.flyinsono.ico");
|
|
|
+ }
|
|
|
+ if (resourceStream != null)
|
|
|
+ {
|
|
|
+ Icon = new WindowIcon(resourceStream);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|