123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- using Avalonia;
- using Avalonia.Controls;
- using Avalonia.Markup.Xaml;
- using Avalonia.Threading;
- using fis.Mac;
- using fis.Managers;
- using fis.Utilities;
- using fis.Win;
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.IO;
- using System.Reflection;
- using System.Runtime.InteropServices;
- using System.Threading;
- using System.Threading.Tasks;
- using Xilium.CefGlue.Avalonia;
- namespace fis
- {
- public partial class SlaveWindow : Window
- {
- public static SynchronizationContext? MainThreadSyncContext;
- private TextBlock? _title;
- private AvaloniaCefBrowser _browser;
- private string _host;
- private WindowType _windowType;
- private Dictionary<string, string> _parameters;
- public bool ForceClose { get; set; } = false;
- public SlaveWindow()
- {
- ExtendClientAreaToDecorationsHint = true;
- ExtendClientAreaChromeHints = Avalonia.Platform.ExtendClientAreaChromeHints.NoChrome;
- ExtendClientAreaTitleBarHeightHint = -1;
- MainThreadSyncContext = SynchronizationContext.Current;
- _browser = BrowserManager.SlaveBrowser;
- #if DEBUG
- this.AttachDevTools();
- #endif
- Closing += SlaveWindow_Closing;
- }
-
-
-
-
-
- public void init(string host, Dictionary<string, string> dictionary, WindowType windowType)
- {
- _windowType = windowType;
- _parameters = dictionary;
- _host = host;
- InitializeComponent();
- }
-
-
-
-
-
- internal async Task ChangeContentViewAsync(string host, Dictionary<string, string> keyValuePairs, WindowType windowType)
- {
- TargetMethodName targetMethodName;
- if (windowType == WindowType.TemplateDesigner) {
-
-
- }
- _host = host;
- _parameters = keyValuePairs;
- var arguments = new List<string>();
- foreach (var p in _parameters)
- {
- arguments.Add(p.Value);
- }
- await Dispatcher.UIThread.InvokeAsync(() =>
- {
- if (WindowState == WindowState.Minimized)
- {
- WindowState = WindowState.Maximized;
- }
- if (!ShowInTaskbar)
- {
- ShowInTaskbar = true;
- ShowActivated = true;
- }
- Show();
- });
- Thread.Sleep(600);
- if (windowType == WindowType.TemplateDesigner) {
- targetMethodName = TargetMethodName.OpenReportDesignerPage;
- }
- else if (windowType == WindowType.Measure)
- {
- targetMethodName = TargetMethodName.OpenMeasurePage;
- }
- else {
- if (arguments.Count == 3) {
- targetMethodName = TargetMethodName.OpenReportPreviewPage;
- }
- else
- {
- targetMethodName = TargetMethodName.OpenReportEditPage;
- }
- }
- BrowserManager.ExecuteJS(BrowserManager.NotificationName, targetMethodName, arguments, false);
- }
- private void SlaveWindow_Closing(object? sender, System.ComponentModel.CancelEventArgs e)
- {
- if (!ForceClose)
- {
- e.Cancel = true;
- Dispatcher.UIThread.InvokeAsync(() =>
- {
- ShowActivated = false;
- Hide();
- });
- 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++;
- }
-
- 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);
- }
- if (_windowType == WindowType.Measure)
- {
- BrowserManager.MeasureWindowBrowser = _browser;
- }
- if (_windowType == WindowType.ReportEdit)
- {
- BrowserManager.ReportWindowBrowser = _browser;
- }
- }
- }
- }
|