Browse Source

支持PC端使用不同platformHost初始化实例

loki.wu 2 years ago
parent
commit
34104a4cc1
5 changed files with 89 additions and 24 deletions
  1. 2 2
      fis/App.axaml.cs
  2. 2 3
      fis/MainWindow.axaml.cs
  3. 1 1
      fis/Managers/SecondaryScreenManager.cs
  4. 10 0
      fis/ShellConfig.cs
  5. 74 18
      fis/SlaveWindow.axaml.cs

+ 2 - 2
fis/App.axaml.cs

@@ -36,9 +36,9 @@ namespace fis
             try
             {
                 var manager = AppManager.Get<ISecondaryScreenManager>();
-                await manager.ShowWindowByTypeAsync(WindowType.Measure, "http://" + ShellConfig.Instance.AppHost+ "/index.html?page=measure", new System.Collections.Generic.Dictionary<string, string>(),false);
+                await manager.ShowWindowByTypeAsync(WindowType.Measure, "http://" + ShellConfig.Instance.AppHost+ "/index.html?page=measure&platformHost="+ ShellConfig.Instance.MeasureApiHost, new System.Collections.Generic.Dictionary<string, string>(),false);
    
-                await manager.ShowWindowByTypeAsync(WindowType.ReportEdit, "http://" + ShellConfig.Instance.AppHost+ "/index.html?page=report", new System.Collections.Generic.Dictionary<string, string>(),false);
+                await manager.ShowWindowByTypeAsync(WindowType.ReportEdit, "http://" + ShellConfig.Instance.AppHost+ "/index.html?page=report&platformHost=" + ShellConfig.Instance.ReportApiHost, new System.Collections.Generic.Dictionary<string, string>(),false);
             }
             catch (Exception ex) {
                 

+ 2 - 3
fis/MainWindow.axaml.cs

@@ -35,8 +35,7 @@ namespace fis
             ExtendClientAreaTitleBarHeightHint = -1;
             MainThreadSyncContext = SynchronizationContext.Current;
 #if DEBUG
-           // this.AttachDevTools();
-         
+          //  this.AttachDevTools();
 #endif
         }
 
@@ -70,7 +69,7 @@ namespace fis
             _browser.BrowserInitialized += () =>
             {
 #if DEBUG
-            //    _browser!.ShowDeveloperTools();
+              // _browser!.ShowDeveloperTools();
 #endif
             };
             browserContainer.Child = _browser;

+ 1 - 1
fis/Managers/SecondaryScreenManager.cs

@@ -28,7 +28,7 @@ namespace fis.Win.Dev.Managers
                 else
                 {
                     window = new SlaveWindow();
-                    window.init(host, keyValuePairs);
+                    window.init(host, keyValuePairs, windowType);
                     if (window.Screens.ScreenCount > 1)
                     {
                         var screen = window.Screens.All.FirstOrDefault(x => x.Primary == false);

+ 10 - 0
fis/ShellConfig.cs

@@ -25,6 +25,16 @@ namespace fis
         //Gets or sets the api host for local call, usually provider platform apis.
         public string LocalApiHost { get; set; } = "platform.fis.plus";
 
+        /// <summary>
+        ///  Gets or sets the api host for local call, usually provider platform apis.
+        /// </summary>
+        public string MeasureApiHost { get; set; } = "platform2.fis.plus";
+
+        /// <summary>
+        /// Gets or sets the api host for local call, usually provider platform apis.
+        /// </summary>
+        public string ReportApiHost { get; set; } = "platform3.fis.plus";
+
         //Gets or sets the resource host for local application resources, eg. icons, images, audios and videos.
         public string LocalResourceHost { get; set; } = "resource.fis.plus";
 

+ 74 - 18
fis/SlaveWindow.axaml.cs

@@ -22,6 +22,8 @@ namespace fis
         private TextBlock? _title;
         private AvaloniaCefBrowser? _browser;
         private string _host;
+        private WindowType _windowType;
+
         private Dictionary<string, string> _parameters;
 
         public bool ForceClose { get; set; } = false;
@@ -33,7 +35,7 @@ namespace fis
             ExtendClientAreaTitleBarHeightHint = -1;
             MainThreadSyncContext = SynchronizationContext.Current;
 #if DEBUG
-            this.AttachDevTools();
+          //  this.AttachDevTools();
 #endif
             Closing += SlaveWindow_Closing;
         }
@@ -43,8 +45,9 @@ namespace fis
         /// </summary>
         /// <param name="host"></param>
         /// <param name="dictionary"></param>
-        public void init(string host, Dictionary<string, string> dictionary)
+        public void init(string host, Dictionary<string, string> dictionary, WindowType windowType)
         {
+            _windowType = windowType;
             _parameters = dictionary;
             _host = host;
             InitializeComponent();
@@ -55,7 +58,7 @@ namespace fis
         /// </summary>
         /// <param name="host"></param>
         /// <param name="keyValuePairs"></param>
-        internal void ChangeContentView(string host, Dictionary<string, string> keyValuePairs,WindowType windowType)
+        internal void ChangeContentView(string host, Dictionary<string, string> keyValuePairs, WindowType windowType)
         {
             _host = host;
             _parameters = keyValuePairs;
@@ -141,12 +144,12 @@ namespace fis
         {
             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();
             }
@@ -154,7 +157,7 @@ namespace fis
             {
                 this.FindControl<WindowsTitleBar>("WinTitleBar").IsVisible = false;
                 _title = this.FindControl<MacosTitleBar>("MacTitleBar").FindControl<TextBlock>("MacosTitle");
-                platformService = new MacService();
+               platformService = new MacService();
             }
             else
             {
@@ -162,32 +165,48 @@ namespace fis
             }
             if (_host.Contains(ShellConfig.Instance.DistHost))
             {
-                var appHandler = new FileSystemHostHandler(ShellConfig.Instance.DistHost , ShellConfig.Instance.DistResourcePath);
-             
+                var appHandler = new FileSystemHostHandler(ShellConfig.Instance.DistHost, ShellConfig.Instance.DistResourcePath);
+
                 var handler = new HostRequestHandler();
                 handler.RegisterHostHandler(appHandler);
-            
+
                 _browser = new AvaloniaCefBrowser
                 {
                     RequestHandler = handler
                 };
             }
-            else 
+            else
             {
                 var appHandler = new FileSystemHostHandler(ShellConfig.Instance.AppHost, ShellConfig.Instance.AppResourcePath);
-                var resourceHandler = new FileSystemHostHandler(ShellConfig.Instance.LocalResourceHost, ShellConfig.Instance.LocalResourcePath);
+                var localHost = "";
+                
+              
+                var resourceHandler = new FileSystemHostHandler(localHost, ShellConfig.Instance.LocalResourcePath);
                 var handler = new HostRequestHandler();
-                // handler.RegisterHostHandler(resourceHandler);
+                handler.RegisterHostHandler(resourceHandler);
+                if (_windowType == WindowType.Measure)
+                {
+                    localHost = ShellConfig.Instance.MeasureApiHost;
+                    var platformHandler = new JsonRpcHandler<IMeasureService>(localHost, new MeasureService());
+                    handler.RegisterHostHandler(platformHandler);
+                }
+                else
+                {
+                    localHost = ShellConfig.Instance.ReportApiHost;
+                    var platformHandler = new JsonRpcHandler<IReportService>(localHost, new ReportService());
+                    handler.RegisterHostHandler(platformHandler);
+                }
+             
                 handler.RegisterHostHandler(appHandler);
                 _browser = new AvaloniaCefBrowser
                 {
                     RequestHandler = handler
                 };
             }
-   
+
             var parameter = "";
             var index = 0;
-            foreach (var p in _parameters) 
+            foreach (var p in _parameters)
             {
                 parameter += p.Key + "=" + p.Value;
                 if (index < _parameters.Count - 1) {
@@ -208,7 +227,7 @@ namespace fis
             _browser.BrowserInitialized += () =>
             {
 #if DEBUG
-             _browser!.ShowDeveloperTools();
+            //    _browser!.ShowDeveloperTools();
 #endif
             };
             var language = CultureInfo.CurrentCulture.Name;
@@ -230,7 +249,7 @@ namespace fis
             }
             else {
                 var scriptObj = new FisBrowserScriptObject(_title, platformService);
-                _browser.RegisterJavascriptObject(scriptObj, "FisShellNotify");
+                _browser.RegisterJavascriptObject(scriptObj, "FisShellApi");
             }
             browserContainer.Child = _browser;
             WindowStartupLocation = WindowStartupLocation.Manual;
@@ -238,7 +257,7 @@ namespace fis
             WindowState = WindowState.Maximized;
             MinWidth = 1366;
             MinHeight = 768;
-         
+
             var assembly = Assembly.GetExecutingAssembly();
             Stream? resourceStream = null;
             if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
@@ -256,6 +275,43 @@ namespace fis
 
         }
     }
+    interface IMeasureService 
+    {
+    
+    }
 
-  
+    interface IReportService
+    {
+
+    }
+
+    public class MeasureService: PlatformService, IPlatformService, IMeasureService
+    {
+        public override string GetPlatformName() => "Win-X86";
+
+        public override Microphone[] GetMicrophones()
+        {
+            return new Microphone[] { };
+        }
+
+        public override Speaker[] GetSpeakers()
+        {
+            return new Speaker[] { };
+        }
+    }
+
+    public class ReportService: PlatformService, IPlatformService, IReportService
+    {
+        public override string GetPlatformName() => "Win-X86";
+
+        public override Microphone[] GetMicrophones()
+        {
+            return new Microphone[] { };
+        }
+
+        public override Speaker[] GetSpeakers()
+        {
+            return new Speaker[] { };
+        }
+    }
 }