Esempio n. 1
0
 internal static void InternalLaunchBlazorApp(IBlazorWebView webview)
 {
     webview.Source = new UrlWebViewSource()
     {
         Url = WebApplicationFactory.GetBaseURL()
     };
 }
Esempio n. 2
0
        protected override void OnElementChanged(ElementChangedEventArgs <BlazorWebView> e)
        {
            base.OnElementChanged(e);

            if (Control == null && e.NewElement != null)
            {
                userController = new WKUserContentController();
                //var script = new WKUserScript(new NSString(ContextBridgeHelper.GetInjectableJavascript(false)), WKUserScriptInjectionTime.AtDocumentEnd, false);
                //userController.AddUserScript(script);
                userController.AddScriptMessageHandler(this, "invokeAction");

                var config = new WKWebViewConfiguration {
                    UserContentController = userController, Preferences = new WKPreferences()
                    {
                        JavaScriptCanOpenWindowsAutomatically = false,
                        JavaScriptEnabled = true
                    }
                };
                var webView = new WKWebView(Frame, config);
                webView.NavigationDelegate = new WebNavigationDelegate(this);
                SetNativeControl(webView);
            }

            if (e.OldElement != null)
            {
                userController.RemoveAllUserScripts();
                userController.RemoveScriptMessageHandler("invokeAction");
            }
            if (e.NewElement != null)
            {
                Control.LoadRequest(new NSUrlRequest(new NSUrl(WebApplicationFactory.GetBaseURL())));
            }
        }
Esempio n. 3
0
 public bool ShouldManageUrl(string url)
 {
     if (string.IsNullOrEmpty(url) || !url.StartsWith(WebApplicationFactory.GetBaseURL()))
     {
         return(false);
     }
     return(true);
 }
Esempio n. 4
0
 public void LaunchBlazorApp()
 {
     switch (Device.RuntimePlatform)
     {
     default:
         Source = new UrlWebViewSource()
         {
             Url = WebApplicationFactory.GetBaseURL()
         };
         blazorAppLaunched = true;
         break;
     }
 }
Esempio n. 5
0
 public void ClearCookies()
 {
     try
     {
         HttpBaseProtocolFilter baseFilter = new HttpBaseProtocolFilter();
         foreach (var cookie in baseFilter.CookieManager.GetCookies(new Uri(WebApplicationFactory.GetBaseURL())))
         {
             baseFilter.CookieManager.DeleteCookie(cookie);
         }
     }
     catch (Exception ex)
     {
         ConsoleHelper.WriteException(ex);
     }
 }
Esempio n. 6
0
        internal static void InternalLaunchBlazorApp(IBlazorWebView webview, bool isReload)
        {
            webview.Source = new UrlWebViewSource()
            {
                Url = WebApplicationFactory.GetBaseURL()
            };

            if (isReload)
            {
                var webIdentity = webview as IWebViewIdentity;
                if (webIdentity != null)
                {
                    webIdentity.BlazorAppLaunched = false;
                }

                webview.Reload();
            }
        }
Esempio n. 7
0
        internal static void InternalLaunchBlazorApp(IBlazorWebView webview, bool isReload)
        {
            webview.Source = new UrlWebViewSource()
            {
                Url = WebApplicationFactory.GetBaseURL()
            };

            if (isReload)
            {
                var webIdentity = webview as IWebViewIdentity;
                if (webIdentity != null)
                {
                    webIdentity.BlazorAppLaunched = false;
                }

                //May cause some strange behavior if we force Reload, as it can try to reload the current WebView URI instead of the one we just affected here
                //webview.Reload();
            }
        }
Esempio n. 8
0
        public static void OnBlazorWebViewNavigating(object sender, WebNavigatingEventArgs e)
        {
            var applicationBaseURL = WebApplicationFactory.GetBaseURL() + "/";

            if (e.Url.Equals(applicationBaseURL, StringComparison.OrdinalIgnoreCase))
            {
                //This is our application base URI. We should do nothing and continue navigating to the app
                e.Cancel = false;
            }
            else if (e.Url.StartsWith(WebApplicationFactory.GetBaseURL(), StringComparison.OrdinalIgnoreCase))
            {
                //Here, our application is loading an URI
                //You may add a custom logic, like opening a new view, changing the URI parameters then opening a view...

                e.Cancel = true;

                switch (BlazorDevice.RuntimePlatform)
                {
                default:
                    Device.OpenUri(new Uri(WebUtility.UrlDecode(e.Url)));
                    break;
                }
            }
            else
            {
                //If here this is not our application loading an URI
                //You may add a custom logic, like opening a new view, changing the URI parameters then opening a view...

                e.Cancel = true;

                switch (BlazorDevice.RuntimePlatform)
                {
                default:
                    Device.OpenUri(new Uri(WebUtility.UrlDecode(e.Url)));
                    break;
                }
            }
        }
 public static string GetServiceURI()
 {
     return(WebApplicationFactory.GetBaseURL() + MetadataConsts.ElectronBlazorMobileRequestValidationPath);
 }
        private async Task <BrowserWindow> CreateMainBrowserWindow()
        {
            //This must be registered before window creation
            ((IWebViewIdentity)(this)).OnBlazorAppLaunched += ElectronBlazorWebView_OnBlazorAppLaunched;

            if (ContextHelper.IsUsingWASM())
            {
                //If using WASM, we must inherit from the BlazorMobile URI behavior
                _browserWindow = await Electron.WindowManager.CreateWindowAsync(Forms.GetDefaultBrowserWindowOptions(), WebApplicationFactory.GetBaseURL());
            }
            else
            {
                _browserWindow = await Electron.WindowManager.CreateWindowAsync(Forms.GetDefaultBrowserWindowOptions());
            }

            return(_browserWindow);
        }
Esempio n. 11
0
 public static string GetServiceURI()
 {
     return(WebApplicationFactory.GetBaseURL() + "/BlazorMobileRequest/Index");
 }