|
@@ -2,7 +2,6 @@ using System;
|
|
|
using System.IO;
|
|
|
using Avalonia;
|
|
|
using Avalonia.Controls;
|
|
|
-using Avalonia.Input;
|
|
|
using Avalonia.Markup.Xaml;
|
|
|
using fis.Mac;
|
|
|
using fis.Win;
|
|
@@ -13,17 +12,22 @@ using Xilium.CefGlue.Common.Handlers;
|
|
|
using System.Globalization;
|
|
|
using System.Reflection;
|
|
|
using System.Threading;
|
|
|
+using System.Runtime.InteropServices;
|
|
|
|
|
|
namespace fis
|
|
|
{
|
|
|
public partial class MainWindow : Window
|
|
|
{
|
|
|
public static SynchronizationContext? MainThreadSyncContext;
|
|
|
+ private TextBlock? _title;
|
|
|
private AvaloniaCefBrowser? _browser;
|
|
|
|
|
|
public MainWindow()
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
+ ExtendClientAreaToDecorationsHint = true;
|
|
|
+ ExtendClientAreaChromeHints = Avalonia.Platform.ExtendClientAreaChromeHints.NoChrome;
|
|
|
+ ExtendClientAreaTitleBarHeightHint = -1;
|
|
|
MainThreadSyncContext = SynchronizationContext.Current;
|
|
|
#if DEBUG
|
|
|
this.AttachDevTools();
|
|
@@ -37,12 +41,16 @@ namespace fis
|
|
|
var appHandler = new FileSystemHostHandler(ShellConfig.Instance.AppHost, ShellConfig.Instance.AppResourcePath);
|
|
|
var resourceHandler = new FileSystemHostHandler(ShellConfig.Instance.LocalResourceHost, ShellConfig.Instance.LocalResourcePath);
|
|
|
IPlatformService platformService;
|
|
|
- if (Environment.OSVersion.Platform == PlatformID.Win32NT)
|
|
|
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
|
{
|
|
|
+ this.FindControl<MacosTitleBar>("MacTitleBar").IsVisible = false;
|
|
|
+ _title = this.FindControl<WindowsTitleBar>("WinTitleBar").FindControl<TextBlock>("WindowsTitle");
|
|
|
platformService = new WinService();
|
|
|
}
|
|
|
- else if (Environment.OSVersion.Platform == PlatformID.MacOSX)
|
|
|
+ else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
|
|
{
|
|
|
+ this.FindControl<WindowsTitleBar>("WinTitleBar").IsVisible = false;
|
|
|
+ _title = this.FindControl<MacosTitleBar>("MacTitleBar").FindControl<TextBlock>("MacosTitle");
|
|
|
platformService = new MacService();
|
|
|
}
|
|
|
else
|
|
@@ -54,41 +62,45 @@ namespace fis
|
|
|
handler.RegisterHostHandler(appHandler);
|
|
|
handler.RegisterHostHandler(resourceHandler);
|
|
|
handler.RegisterHostHandler(platformHandler);
|
|
|
- _browser = new AvaloniaCefBrowser();
|
|
|
- _browser.RequestHandler = handler;
|
|
|
+ _browser = new AvaloniaCefBrowser
|
|
|
+ {
|
|
|
+ RequestHandler = handler
|
|
|
+ };
|
|
|
//Make cross domain work.
|
|
|
_browser.Settings.WebSecurity = CefState.Disabled;
|
|
|
_browser.Address = "http://" + ShellConfig.Instance.AppHost + "/index.html";
|
|
|
_browser.ContextMenuHandler = new TextContextMenuHandler(_browser);
|
|
|
_browser.BrowserInitialized += () =>
|
|
|
{
|
|
|
- var scriptObj = new FisBrowserScriptObject(this, platformService);
|
|
|
+ var scriptObj = new FisBrowserScriptObject(_title, platformService);
|
|
|
_browser.RegisterJavascriptObject(scriptObj, "FisShellApi");
|
|
|
};
|
|
|
browserContainer.Child = _browser;
|
|
|
|
|
|
WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
|
|
- WindowState = WindowState.Maximized;
|
|
|
+ //WindowState = WindowState.Maximized;
|
|
|
MinWidth = 1366;
|
|
|
MinHeight = 768;
|
|
|
var language = CultureInfo.CurrentCulture.Name;
|
|
|
- if (language == "zh-CN")
|
|
|
- {
|
|
|
- Title = "杏聆荟";
|
|
|
- }
|
|
|
- else
|
|
|
+ if (_title != null)
|
|
|
{
|
|
|
- Title = "FLYINSONO";
|
|
|
+ if (language == "zh-CN")
|
|
|
+ {
|
|
|
+ _title.Text = "杏聆荟";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ _title.Text = "FLYINSONO";
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
var assembly = Assembly.GetExecutingAssembly();
|
|
|
|
|
|
Stream? resourceStream = null;
|
|
|
- if (Environment.OSVersion.Platform == PlatformID.Win32NT)
|
|
|
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
|
{
|
|
|
resourceStream = assembly.GetManifestResourceStream("fis.Win.flyinsono.ico");
|
|
|
}
|
|
|
- else if (Environment.OSVersion.Platform == PlatformID.Unix)
|
|
|
+ else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
|
|
{
|
|
|
resourceStream = assembly.GetManifestResourceStream("fis.Mac.flyinsono.ico");
|
|
|
}
|
|
@@ -101,7 +113,7 @@ namespace fis
|
|
|
#if DEBUG
|
|
|
System.Threading.Tasks.Task.Run(() =>
|
|
|
{
|
|
|
- System.Threading.Thread.Sleep(1000);
|
|
|
+ Thread.Sleep(1000);
|
|
|
_browser.ShowDeveloperTools();
|
|
|
});
|
|
|
#endif
|
|
@@ -111,10 +123,10 @@ namespace fis
|
|
|
internal class FisBrowserScriptObject
|
|
|
{
|
|
|
IPlatformService _platformService;
|
|
|
- Window _window;
|
|
|
- internal FisBrowserScriptObject(Window window, IPlatformService platformService)
|
|
|
+ TextBlock _title;
|
|
|
+ internal FisBrowserScriptObject(TextBlock title, IPlatformService platformService)
|
|
|
{
|
|
|
- _window = window;
|
|
|
+ _title = title;
|
|
|
_platformService = platformService;
|
|
|
}
|
|
|
|
|
@@ -139,7 +151,10 @@ namespace fis
|
|
|
{
|
|
|
MainWindow.MainThreadSyncContext?.Send(new SendOrPostCallback((args) =>
|
|
|
{
|
|
|
- _window.Title = title;
|
|
|
+ if(_title != null)
|
|
|
+ {
|
|
|
+ _title.Text = title;
|
|
|
+ }
|
|
|
}), this);
|
|
|
}
|
|
|
|