|
@@ -1,5 +1,4 @@
|
|
|
-using Avalonia.Controls;
|
|
|
-using fis.Mac;
|
|
|
+using fis.Mac;
|
|
|
using fis.Win;
|
|
|
using System;
|
|
|
using System.Runtime.InteropServices;
|
|
@@ -56,52 +55,99 @@ namespace fis.Managers
|
|
|
|
|
|
internal class BrowserManager
|
|
|
{
|
|
|
+ private static HostRequestHandler _requestHandler;
|
|
|
+
|
|
|
+ private static IPlatformService _platformService;
|
|
|
+
|
|
|
private static FisBrowser? _mainBrowser;
|
|
|
|
|
|
+ private static FisBrowser? _slaveBrowser;
|
|
|
+
|
|
|
+ static BrowserManager()
|
|
|
+ {
|
|
|
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
|
+ {
|
|
|
+ _platformService = new WinService();
|
|
|
+ }
|
|
|
+ else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
|
|
+ {
|
|
|
+ _platformService = new MacService();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ throw new NotSupportedException($"Platform {Environment.OSVersion.Platform} is not suppoorted.");
|
|
|
+ }
|
|
|
+ _requestHandler = new HostRequestHandler();
|
|
|
+ var appHandler = new FileSystemHostHandler(ShellConfig.Instance.AppHost, ShellConfig.Instance.AppResourcePath);
|
|
|
+ var resourceHandler = new FileSystemHostHandler(ShellConfig.Instance.LocalResourceHost, ShellConfig.Instance.LocalResourcePath);
|
|
|
+ var platformHandler = new JsonRpcHandler<IPlatformService>(ShellConfig.Instance.LocalApiHost, _platformService);
|
|
|
+ _requestHandler.RegisterHostHandler(appHandler);
|
|
|
+ _requestHandler.RegisterHostHandler(resourceHandler);
|
|
|
+ _requestHandler.RegisterHostHandler(platformHandler);
|
|
|
+ }
|
|
|
+
|
|
|
public static FisBrowser MainBrowser
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
if (_mainBrowser == null)
|
|
|
{
|
|
|
- var handler = new HostRequestHandler();
|
|
|
- var appHandler = new FileSystemHostHandler(ShellConfig.Instance.AppHost, ShellConfig.Instance.AppResourcePath);
|
|
|
- var resourceHandler = new FileSystemHostHandler(ShellConfig.Instance.LocalResourceHost, ShellConfig.Instance.LocalResourcePath);
|
|
|
-
|
|
|
- handler.RegisterHostHandler(appHandler);
|
|
|
- handler.RegisterHostHandler(resourceHandler);
|
|
|
- IPlatformService platformService;
|
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
|
{
|
|
|
- platformService = new WinService();
|
|
|
- _mainBrowser = new WinFisBrowser(platformService)
|
|
|
+ _mainBrowser = new WinFisBrowser(_platformService)
|
|
|
{
|
|
|
- RequestHandler = handler
|
|
|
+ RequestHandler = _requestHandler
|
|
|
};
|
|
|
}
|
|
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
|
|
{
|
|
|
- platformService = new MacService();
|
|
|
_mainBrowser = new MacFisBrowser
|
|
|
{
|
|
|
- RequestHandler = handler
|
|
|
+ RequestHandler = _requestHandler
|
|
|
};
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
throw new NotSupportedException($"Platform {Environment.OSVersion.Platform} is not suppoorted.");
|
|
|
}
|
|
|
-
|
|
|
- var platformHandler = new JsonRpcHandler<IPlatformService>(ShellConfig.Instance.LocalApiHost, platformService);
|
|
|
- handler.RegisterHostHandler(platformHandler);
|
|
|
_mainBrowser.Settings.WebSecurity = CefState.Disabled;
|
|
|
}
|
|
|
return _mainBrowser;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static AvaloniaCefBrowser MeasureWindowBrowser { get; set; }
|
|
|
+ public static FisBrowser SlaveBrowser
|
|
|
+ {
|
|
|
+ get
|
|
|
+ {
|
|
|
+ if (_slaveBrowser == null)
|
|
|
+ {
|
|
|
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
|
+ {
|
|
|
+ _slaveBrowser = new WinFisBrowser(_platformService)
|
|
|
+ {
|
|
|
+ RequestHandler = _requestHandler
|
|
|
+ };
|
|
|
+ }
|
|
|
+ else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
|
|
+ {
|
|
|
+ _slaveBrowser = new MacFisBrowser
|
|
|
+ {
|
|
|
+ RequestHandler = _requestHandler
|
|
|
+ };
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ throw new NotSupportedException($"Platform {Environment.OSVersion.Platform} is not suppoorted.");
|
|
|
+ }
|
|
|
+ _slaveBrowser.Settings.WebSecurity = CefState.Disabled;
|
|
|
+ }
|
|
|
+ return _slaveBrowser;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static AvaloniaCefBrowser? MeasureWindowBrowser { get; set; }
|
|
|
|
|
|
- public static AvaloniaCefBrowser ReportWindowBrowser { get; set; }
|
|
|
+ public static AvaloniaCefBrowser? ReportWindowBrowser { get; set; }
|
|
|
}
|
|
|
}
|