|
@@ -6,6 +6,7 @@ using fis.Mac;
|
|
|
using fis.Managers;
|
|
|
using fis.Utilities;
|
|
|
using fis.Win;
|
|
|
+using fis.Win.Utilities;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Globalization;
|
|
@@ -18,28 +19,25 @@ using Xilium.CefGlue.Avalonia;
|
|
|
|
|
|
namespace fis
|
|
|
{
|
|
|
- public partial class SlaveWindow : Window
|
|
|
+ public partial class SlaveWindow : BaseWindow
|
|
|
{
|
|
|
- public static SynchronizationContext? MainThreadSyncContext;
|
|
|
- private TextBlock? _title;
|
|
|
+
|
|
|
private AvaloniaCefBrowser _browser;
|
|
|
- private string _host;
|
|
|
- private WindowType _windowType;
|
|
|
+ private string _host = "";
|
|
|
|
|
|
- private Dictionary<string, string> _parameters;
|
|
|
+ private Dictionary<string, string> _parameters = new Dictionary<string, string>();
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 副窗口是否强制关闭,false则是点击关闭时隐藏,true则是窗口直接关闭
|
|
|
+ /// </summary>
|
|
|
public bool ForceClose { get; set; } = false;
|
|
|
|
|
|
public SlaveWindow()
|
|
|
{
|
|
|
- ExtendClientAreaToDecorationsHint = true;
|
|
|
- ExtendClientAreaChromeHints = Avalonia.Platform.ExtendClientAreaChromeHints.NoChrome;
|
|
|
- ExtendClientAreaTitleBarHeightHint = -1;
|
|
|
- MainThreadSyncContext = SynchronizationContext.Current;
|
|
|
+ IsMainWindow = false;
|
|
|
+ AvaloniaXamlLoader.Load(this);
|
|
|
+ InitializeComponent();
|
|
|
_browser = BrowserManager.SlaveBrowser;
|
|
|
-#if DEBUG
|
|
|
- this.AttachDevTools();
|
|
|
-#endif
|
|
|
Closing += SlaveWindow_Closing;
|
|
|
}
|
|
|
|
|
@@ -48,12 +46,34 @@ namespace fis
|
|
|
/// </summary>
|
|
|
/// <param name="host"></param>
|
|
|
/// <param name="dictionary"></param>
|
|
|
- public void init(string host, Dictionary<string, string> dictionary, WindowType windowType)
|
|
|
+ public void init(string host, Dictionary<string, string> dictionary)
|
|
|
{
|
|
|
- _windowType = windowType;
|
|
|
_parameters = dictionary;
|
|
|
_host = host;
|
|
|
- InitializeComponent();
|
|
|
+ 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)
|
|
|
+ {
|
|
|
+ var url = "http://" + ShellConfig.Instance.AppHost + "/index.html?page=measure&" + parameter;
|
|
|
+ _browser.Address = url;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ _browser.Address = _host;
|
|
|
+ }
|
|
|
+ WindowStartupLocation = WindowStartupLocation.Manual;
|
|
|
+ Position = new PixelPoint();
|
|
|
+ WindowState = WindowState.Maximized;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -84,6 +104,7 @@ namespace fis
|
|
|
}
|
|
|
Show();
|
|
|
});
|
|
|
+ ///窗口在hidden变成show的时候容易卡死,加个Sleep能缓解这种情况
|
|
|
Thread.Sleep(600);
|
|
|
if (windowType == WindowType.TemplateDesigner) {
|
|
|
targetMethodName = TargetMethodName.OpenReportDesignerPage;
|
|
@@ -106,6 +127,8 @@ namespace fis
|
|
|
|
|
|
private void SlaveWindow_Closing(object? sender, System.ComponentModel.CancelEventArgs e)
|
|
|
{
|
|
|
+ ///若非强制关闭副窗口,则隐藏副窗口
|
|
|
+ ///用于保持Flutter在内存中不被销毁
|
|
|
if (!ForceClose)
|
|
|
{
|
|
|
e.Cancel = true;
|
|
@@ -117,90 +140,5 @@ namespace fis
|
|
|
GC.Collect();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- 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.");
|
|
|
- }
|
|
|
- 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)
|
|
|
- {
|
|
|
- var url = "http://" + ShellConfig.Instance.AppHost + "/index.html?page=measure&" + parameter;
|
|
|
- _browser.Address = url;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- _browser.Address = _host;
|
|
|
- }
|
|
|
- _browser.BrowserInitialized += () =>
|
|
|
- {
|
|
|
-#if DEBUG
|
|
|
- _browser!.ShowDeveloperTools();
|
|
|
-#endif
|
|
|
- };
|
|
|
- var language = CultureInfo.CurrentCulture.Name;
|
|
|
- if (_title != null)
|
|
|
- {
|
|
|
- if (language == "zh-CN")
|
|
|
- {
|
|
|
- _title.Text = "杏聆荟";
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- _title.Text = "FLYINSONO";
|
|
|
- }
|
|
|
- var scriptObj = new FisBrowserScriptObject(_title, platformService);
|
|
|
- _browser.RegisterJavascriptObject(scriptObj, "FisShellApi");
|
|
|
- }
|
|
|
- browserContainer.Child = _browser;
|
|
|
- WindowStartupLocation = WindowStartupLocation.Manual;
|
|
|
- Position = new PixelPoint();
|
|
|
- WindowState = WindowState.Maximized;
|
|
|
- MinWidth = 1366;
|
|
|
- MinHeight = 768;
|
|
|
- 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);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
}
|
|
|
}
|