// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (!useWASM)
            {
                app.UseResponseCompression();

                if (env.IsDevelopment())
                {
                    app.UseDeveloperExceptionPage();
                    app.UseBlazorDebugging();
                }
                else
                {
                    app.UseExceptionHandler("/Home/Error");
                }

                app.UseClientSideBlazorFiles <BlazorMobile.Sample.Blazor.Program>();

                app.UseStaticFiles();
                app.UseRouting();

                app.UseEndpoints(endpoints =>
                {
                    endpoints.MapBlazorHub();
                    endpoints.MapDefaultControllerRoute();
                    endpoints.MapBlazorMobileRequestValidator();
                    endpoints.MapFallbackToPage("/server_index");
                });

                //Initialize Blazor app from .NET Core / Server-side
                BlazorMobileService.Init((bool success) =>
                {
                    Console.WriteLine($"Initialization success: {success}");
                    Console.WriteLine("Device is: " + BlazorDevice.RuntimePlatform);
                });
            }

            app.UseBlazorMobileWithElectronNET <App>(useWASM);

            //Theses line must be registered after 'UseBlazorMobileWithElectronNET' as it internally call Xamarin.Forms.Init()
            if (useWASM)
            {
                BlazorWebViewService.Init();

                //Register our Blazor app package
                WebApplicationFactory.RegisterAppStreamResolver(AppPackageHelper.ResolveAppPackageStream);
            }

            Forms.ConfigureBrowserWindow(new BrowserWindowOptions()
            {
                //Configure the BrowserWindow that will be used for the Blazor application
            });

            //Launch the Blazor app
            Forms.LoadApplication(new App());

            // If your code already started your BlazorWebView.LaunchBlazorApp method, you should retrieve here the Electron main BrowserWindow used to create it.
            // Otherwise, return a null Task value
            var myBrowserWindow = Forms.GetBrowserWindow();
        }
Exemple #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            app.UseResponseCompression();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBlazorDebugging();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseClientSideBlazorFiles <BlazorMobile.Sample.Blazor.Program>();

            app.UseStaticFiles();
            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapBlazorHub();
                endpoints.MapDefaultControllerRoute();
                endpoints.MapFallbackToPage("/server_index");
            });

            BlazorMobileService.EnableClientToDeviceRemoteDebugging("127.0.0.1", 8888);
            BlazorMobileService.Init((bool success) =>
            {
                Console.WriteLine($"Initialization success: {success}");
                Console.WriteLine("Device is: " + BlazorDevice.RuntimePlatform);
            });
        }
 private void BlazorMobileService_OnBlazorMobileLoaded(object source, BlazorMobileOnFinishEventArgs args)
 {
     //BlazorMobile is ready. We should call StateHasChanged method in order to call BuildRenderTree again.
     //This time, it should load your app with base.BuildRenderTree() method call.
     BlazorMobileService.HideElementById("placeholder");
     StateHasChanged();
 }
Exemple #4
0
        public static async Task Main(string[] args)
        {
            var builder = WebAssemblyHostBuilder.CreateDefault(args);

            #region Services registration

            ServicesHelper.ConfigureCommonServices(builder.Services);

            #endregion

            #region DEBUG

            //Only if you want to test WebAssembly with remote debugging from a dev machine
            BlazorMobileService.EnableClientToDeviceRemoteDebugging("127.0.0.1", 8888);

            #endregion

            BlazorMobileService.Init((bool success) =>
            {
                Console.WriteLine($"Initialization success: {success}");
                Console.WriteLine("Device is: " + BlazorDevice.RuntimePlatform);
            });

            builder.RootComponents.Add <MobileApp>("app");

            await builder.Build().RunAsync();
        }
Exemple #5
0
        /// <summary>
        /// Call of this method will notify to BlazorMobile that the runtime is actually running under ElectronNET (server-side) and will also start your ElectronNET application.
        /// NOTE: Usage of blazor.server.js in your starting page is mandatory.
        /// If using BlazorMobile.Build on your Blazor base project, you should add a link reference to 'server_index.cshtml' in your server project from the base project, and register this file at app start.
        /// See BlazorMobile documentation for more info.
        /// <param name="useWASM">If 'useWASM' is set to true, the Electron app will fallback to a full WASM engine. This can be great if you need to use some BlazorMobile API that require to run in WASM mode, like side-loading other Blazor packages. However this option will disable full .NET Core / C# debug support during development time, as it will fallback to the WebAssembly debug current implementation</param>
        /// </summary>
        public static IApplicationBuilder UseBlazorMobileWithElectronNET <TFormsApplication>(this IApplicationBuilder app, bool useWASM) where TFormsApplication : BlazorApplication
        {
            if (!useWASM && !BlazorMobileService.IsInitCalled())
            {
                throw new InvalidOperationException($"BlazorMobileService.Init() method should be called before calling {nameof(UseBlazorMobileWithElectronNET)}");
            }

            ContextHelper.SetElectronNETUsage(true, useWASM);

            PlatformHelper.SetIsElectronActive(() => HybridSupport.IsElectronActive);

            if (!useWASM)
            {
                //Bridging Native receive method in memory on ElectronNET implementation
                ContextHelper.SetNativeReceive(ContextBridge.Receive);
            }

            BlazorWebViewFactory.SetInternalElectronBlazorWebView(typeof(ElectronBlazorWebView));

            app.UseStaticFiles();

            Forms.Init();

            DependencyService.Register <IApplicationStoreService, ApplicationStoreService>();

            return(app);
        }
Exemple #6
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            app.UseResponseCompression();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBlazorDebugging();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseClientSideBlazorFiles <InteropBlazorApp.Startup>();

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapBlazorHub();
                endpoints.MapFallbackToPage("/server_index");
            });

            BlazorMobileService.Init((bool success) =>
            {
                Console.WriteLine($"Initialization success: {success}");
                Console.WriteLine("Device is: " + BlazorDevice.RuntimePlatform);
            });

            app.UseBlazorMobileWithElectronNET <App>();
        }
Exemple #7
0
        public static async Task Main(string[] args)
        {
            var builder = WebAssemblyHostBuilder.CreateDefault(args);

            builder.Services.AddSingleton(new HttpClient {
                BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)
            });

            #region Services registration

            ServicesHelper.ConfigureCommonServices(builder.Services);

            #endregion

            #if DEBUG
            //Only if you want to test WebAssembly with remote debugging from a dev machine
            BlazorMobileService.EnableClientToDeviceRemoteDebugging("127.0.0.1", 8888);
            #endif

            BlazorMobileService.OnBlazorMobileLoaded += (object source, BlazorMobileOnFinishEventArgs eventArgs) =>
            {
                Console.WriteLine($"Initialization success: {eventArgs.Success}");
                Console.WriteLine("Device is: " + BlazorDevice.RuntimePlatform);
            };

            builder.RootComponents.Add <MobileApp>("app");

            await builder.Build().RunAsync();
        }
Exemple #8
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            app.UseResponseCompression();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseBlazorFrameworkFiles();

            app.UseStaticFiles();
            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapBlazorHub();
                endpoints.MapFallbackToPage("/server_index");
            });

            BlazorMobileService.EnableClientToDeviceRemoteDebugging("127.0.0.1", 8891);
            BlazorMobileService.OnBlazorMobileLoaded += (object source, BlazorMobileOnFinishEventArgs eventArgs) =>
            {
                Console.WriteLine($"Initialization success: {eventArgs.Success}");
                Console.WriteLine("Device is: " + BlazorDevice.RuntimePlatform);
            };
        }
 public void CallJSInvokableMethod(string assembly, string method, params object[] args)
 {
     if (ContextHelper.IsUsingWASM())
     {
         WebViewHelper.CallJSInvokableMethod(assembly, method, args);
     }
     else
     {
         BlazorMobileService.SendMessageToJSInvokableMethod(assembly, method, args);
     }
 }
Exemple #10
0
 private void BlazorMobileService_OnBlazorMobileLoaded(object source, BlazorMobileOnFinishEventArgs args)
 {
     //InvokeAsync is mainly needed for .NET Core implementation that need the renderer context
     InvokeAsync(() =>
     {
         //BlazorMobile is ready. We should call StateHasChanged method in order to call BuildRenderTree again.
         //This time, it should load your app with base.BuildRenderTree() method call.
         BlazorMobileService.HideElementById("placeholder");
         StateHasChanged();
     });
 }
 public void PostMessage <TArgs>(string messageName, TArgs args)
 {
     if (ContextHelper.IsUsingWASM())
     {
         WebViewHelper.PostMessage(messageName, typeof(TArgs), new object[] { args });
     }
     else
     {
         BlazorMobileService.SendMessageToSubscribers(messageName, typeof(TArgs), new object[] { args });
     }
 }
Exemple #12
0
        public void Configure(IComponentsApplicationBuilder app)
        {
            #region DEBUG

            //Only if you want to test WebAssembly with remote debugging from a dev machine
            BlazorMobileService.EnableClientToDeviceRemoteDebugging("127.0.0.1", 8888);

            #endregion

            BlazorMobileService.Init((bool success) =>
            {
                Console.WriteLine($"Initialization success: {success}");
                Console.WriteLine("Device is: " + BlazorDevice.RuntimePlatform);
            });

            app.AddComponent <MobileApp>("app");
        }
Exemple #13
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            app.UseResponseCompression();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBlazorDebugging();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseClientSideBlazorFiles <InteropBlazorApp.Program>();

            app.UseStaticFiles();
            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapBlazorHub();
                endpoints.MapBlazorMobileRequestValidator();
                endpoints.MapFallbackToPage("/server_index");
            });

            BlazorMobileService.Init((bool success) =>
            {
                Console.WriteLine($"Initialization success: {success}");
                Console.WriteLine("Device is: " + BlazorDevice.RuntimePlatform);
            });

            app.UseBlazorMobileWithElectronNET <App>();

            Forms.ConfigureBrowserWindow(new BrowserWindowOptions()
            {
                //Configure the BrowserWindow that will be used for the Blazor application
            });

            //Launch the Blazor app
            Forms.LoadApplication(new App());

            // If your code already started your BlazorWebView.LaunchBlazorApp method, you should retrieve here the Electron main BrowserWindow used to create it.
            // Otherwise, return a null Task value
            var myBrowserWindow = Forms.GetBrowserWindow();
        }
Exemple #14
0
        /// <summary>
        /// Call of this method will notify to BlazorMobile that the runtime is actually running under ElectronNET (server-side) and will also start your ElectronNET application.
        /// NOTE: Usage of blazor.server.js in your starting page is mandatory.
        /// If using BlazorMobile.Build on your Blazor base project, you should add a link reference to 'server_index.cshtml' in your server project from the base project, and register this file at app start.
        /// See BlazorMobile documentation for more info.
        /// </summary>
        public static IApplicationBuilder UseBlazorMobileWithElectronNET <TFormsApplication>(this IApplicationBuilder app) where TFormsApplication : BlazorApplication
        {
            if (!BlazorMobileService.IsInitCalled())
            {
                throw new InvalidOperationException($"BlazorMobileService.Init() method should be called before calling {nameof(UseBlazorMobileWithElectronNET)}");
            }

            ContextHelper.SetElectronNETUsage(true);

            //Bridging Native receive method in memory on ElectronNET implementation
            ContextHelper.SetNativeReceive(ContextBridge.Receive);
            BlazorWebViewFactory.SetInternalElectronBlazorWebView(typeof(ElectronBlazorWebView));

            app.UseStaticFiles();

            Forms.Init();

            return(app);
        }
Exemple #15
0
 private async Task SetRemoteDebugEndpoint()
 {
     string uri = BlazorMobileService.GetContextBridgeURI();
     await Runtime.InvokeVoidAsync("BlazorXamarin.SetDebugRemoteEndpoint", uri);
 }
 internal void OnFinishEvent()
 {
     BlazorMobileService.SendOnBlazorMobileLoaded(this, BlazorMobileSuccess);
 }
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            //This component must be rendered once!
            //Even if the javascript script is not re-renderer if the component is called twice, it should be already available in the DOM
            if (_isInitialized)
            {
                return;
            }

            builder.OpenElement(0, "script");
            builder.AddAttribute(1, "type", "text/javascript");
            builder.AddMarkupContent(1,
                                     ContextBridgeHelper.GetBlazorXamarinJavascript()
                                     + ContextBridgeHelper.GetContextBridgeJavascript().Replace("%_contextBridgeURI%", BlazorMobileService.GetContextBridgeURI()));
            builder.CloseElement();

            _isInitialized = true;
        }
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            //This component must be rendered once!
            //If the component is disposed and then re-rendered, then something is wrong with the current project configuration
            if (_isInitialized)
            {
                return;
            }

            builder.OpenElement(0, "script");
            builder.AddAttribute(1, "type", "text/javascript");
            builder.AddContent(1,
                               ContextBridgeHelper.GetBlazorXamarinJavascript()
                               + ContextBridgeHelper.GetContextBridgeJavascript().Replace("%_contextBridgeURI%", BlazorMobileService.GetContextBridgeURI()));
            builder.CloseElement();

            _isInitialized = true;
        }
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            //This component must be rendered once!
            //If the component is disposed and then re-rendered, then something is wrong with the current project configuration
            if (_isInitialized)
            {
                return;
            }

            if (ContextHelper.IsBlazorMobile())
            {
                builder.OpenElement(0, "script");
                builder.AddContent(1, @"
                window.BlazorXamarinRuntimeCheck = function () {
	                if (window.contextBridge == null || window.contextBridge == undefined)
	                {
		                return false;
	                }

	                return true;
                };
");
                builder.CloseElement();

                //Add server side remote to client remote debugging
                builder.OpenElement(0, "script");
                builder.AddContent(1, ContextBridgeHelper.GetInjectableJavascript(false).Replace("%_contextBridgeURI%", BlazorMobileService.GetContextBridgeURI()));
                builder.CloseElement();
            }
            else if (ContextHelper.IsElectronNET())
            {
                //Add electronNET helpers
                builder.OpenElement(0, "script");
                builder.AddContent(1, ContextBridgeHelper.GetElectronNETJavascript());
                builder.CloseElement();
            }

            _isInitialized = true;
        }