Exemple #1
0
        private async void AutoPlayOnStartup(AutoPlayAction autoPlayAction)
        {
            await Task.Delay(TimeSpan.FromSeconds(1));

            logger.Info("AutoPlay " + autoPlayAction);
            await WebViewHelper.AutoPlay(autoPlayAction);
        }
Exemple #2
0
        /// <summary>
        /// Register the given WebExtension to the given runtime instance of a GeckoView
        /// This method is used to forward event based on WebExtension id to the right GeckoView instance
        /// The WebExtension id will be generated by this method
        /// </summary>
        internal static void RegisterWebExtension(BlazorGeckoView blazorGeckoView, GeckoRuntime runtime, string webExtensionLocation)
        {
            if (blazorGeckoView == null)
            {
                throw new ArgumentNullException(nameof(blazorGeckoView));
            }

            if (runtime == null)
            {
                throw new ArgumentNullException(nameof(runtime));
            }

            //We do a preliminary check if a same runtime on another GeckoView is used. We must not register a WebExtension twice if it is already present on a runtime. We assume that we are using our BlazorWebview as a solo-instance behavior
            if (RuntimeHasWebExtension(runtime, webExtensionLocation))
            {
                //Already registered. Ignore registration
                return;
            }

            //Get an unique identity
            int identity = GenerateWebExtensionIdentity();

            WebExtension webExtension = new WebExtension(webExtensionLocation, identity.ToString());

            //Register the given WebExtension to the runtime
            runtime.RegisterWebExtension(webExtension);

            //Register the WebExtension registration in our dictionnary
            AddRuntimeWebExtensionReference(runtime, webExtension);

            //Register the Webview with this identity attached to retrieve it later by WebExtension identity
            WebViewHelper.RegisterWebView(blazorGeckoView, identity);
        }
Exemple #3
0
        private async void WebViewCheckTimer_Tick(object sender, object e)
        {
            // Ignore if not logged in
            if (!TokenHelper.HasTokens())
            {
                return;
            }

            try
            {
                var currentPlaying = await WebViewHelper.GetCurrentPlaying();

                if (currentPlaying != prevCurrentPlaying)
                {
                    prevCurrentPlaying = currentPlaying;
                    logger.Info($"CurrentPlaying text extracted from web page changed to '{currentPlaying}'.");

                    await PlayStatusTracker.RefreshPlayStatus();
                }
            }
            catch (Exception ex)
            {
                logger.Warn("checkCurrentPlaying failed: " + ex.ToString());
            }

            try
            {
                webViewBackEnabled = await WebViewHelper.IsBackPossible();
            }
            catch (Exception ex)
            {
                logger.Warn("checkBackButtonEnable failed: " + ex.ToString());
            }
        }
Exemple #4
0
        public async Task <HtmlDocument> GetForumFrontPageHtml()
        {
            StorageFile file;
            string      forumHtml      = string.Format(Constants.HTML_FILE, "forum");
            bool        htmlFileExists = await WebViewHelper.HtmlExists(forumHtml);

            if (htmlFileExists)
            {
                file = await ApplicationData.Current.LocalFolder.GetFileAsync(forumHtml);

                string html = await FileIO.ReadTextAsync(file);

                var document = new HtmlDocument();
                document.LoadHtml(html);
                return(document);
            }

            file =
                await
                ApplicationData.Current.LocalFolder.CreateFileAsync(forumHtml,
                                                                    CreationCollisionOption.ReplaceExisting);

            HtmlDocument doc = (await _webManager.GetData(Constants.BASE_URL)).Document;

            using (var memoryStream = new MemoryStream())
            {
                doc.Save(memoryStream);
                memoryStream.Seek(0, SeekOrigin.Begin);
                await FileIO.WriteBytesAsync(file, memoryStream.ToArray());
            }
            return(doc);
        }
Exemple #5
0
        public async void NavigateWithConfig(string parameter)
        {
            try
            {
                var urlDecoder = new WwwFormUrlDecoder(parameter);
                var pageUrl    = urlDecoder.GetFirstValueByName("pageUrl");

                await WebViewHelper.NavigateToSpotifyUrl(pageUrl);

                var            autoplayEntry = urlDecoder.FirstOrDefault(x => x.Name == "autoplay");
                AutoPlayAction action        = AutoPlayAction.None;
                if (autoplayEntry != null)
                {
                    action = autoplayEntry.Value == "track" ? AutoPlayAction.Track : AutoPlayAction.Playlist;
                }

                if (action != AutoPlayAction.None)
                {
                    await WebViewHelper.AutoPlay(action);
                }

                return;
            }
            catch (Exception ex)
            {
                logger.Info($"Parsing input parameter {parameter} failed. {ex}");
            }
        }
Exemple #6
0
        public BlazorGeckoView()
        {
            WebApplicationFactory.BlazorAppNeedReload             += ReloadBlazorAppEvent;
            WebApplicationFactory.EnsureBlazorAppLaunchedOrReload += EnsureBlazorAppLaunchedOrReload;

            _identity = WebViewHelper.GenerateWebViewIdentity();
        }
        public ElectronBlazorWebView()
        {
            _identity = WebViewHelper.GenerateWebViewIdentity();

            webAppPlaftorm = DependencyService.Get <IWebApplicationPlatform>();

            WebViewHelper.RegisterWebView(this);
        }
Exemple #8
0
        private async void OpenLinkFromClipboard_Click(object sender, RoutedEventArgs e)
        {
            var uri = await ClipboardHelper.GetSpotifyUri();

            if (!string.IsNullOrWhiteSpace(uri))
            {
                await WebViewHelper.NavigateToSpotifyUrl(uri);
            }
        }
        public ElectronBlazorWebView()
        {
            WebApplicationFactory.BlazorAppNeedReload += ReloadBlazorAppEvent;

            _identity = WebViewHelper.GenerateWebViewIdentity();

            webAppPlaftorm = DependencyService.Get <IWebApplicationPlatform>();

            WebViewHelper.RegisterWebView(this);
        }
Exemple #10
0
        private async void App_BackRequested(object sender, BackRequestedEventArgs e)
        {
            if (webViewBackEnabled)
            {
                e.Handled = true;

                var result = await WebViewHelper.GoBackIfPossible();

                logger.Info($"GoBackIfPossible() result = {result}");
            }
        }
 public void CallJSInvokableMethod(string assembly, string method, params object[] args)
 {
     if (ContextHelper.IsUsingWASM())
     {
         WebViewHelper.CallJSInvokableMethod(assembly, method, args);
     }
     else
     {
         BlazorMobileService.SendMessageToJSInvokableMethod(assembly, method, args);
     }
 }
 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 #13
0
        private async Task PinPageToStart()
        {
            VisualStateManager.GoToState(this, "MainScreenWaiting", false);

            var pageUrl = await WebViewHelper.GetPageUrl();

            var pageTitle = await WebViewHelper.GetPageTitle();

            await TileHelper.PinPageToStart(pageUrl, pageTitle);

            VisualStateManager.GoToState(this, "MainScreen", false);
        }
Exemple #14
0
        private async Task <bool> ValidateRequestElectronWASM()
        {
            string uri      = this.Request.QueryString.Get("uri");
            string referrer = this.Request.QueryString.Get("referrer");

            IWebResponse response = new EmbedIOWebResponse(this.Request, this.Response);

            response.SetEncoding("UTF-8");
            response.AddResponseHeader("Cache-Control", "no-cache");
            response.SetReasonPhrase("OK");
            response.SetMimeType("text/plain");

            if (!string.IsNullOrEmpty(uri) && !string.IsNullOrEmpty(referrer))
            {
                var args = new WebNavigatingEventArgs(
                    WebNavigationEvent.NewPage,
                    new UrlWebViewSource()
                {
                    Url = referrer
                },
                    uri);

                //This is not entirely true as we would only compare the current BlazorWebview
                //but it must be only one executed btw
                foreach (var webIdentity in WebViewHelper.GetAllWebViewIdentities())
                {
                    var webview = webIdentity as IBlazorWebView;
                    webview.SendNavigating(args);

                    if (args.Cancel)
                    {
                        break;
                    }
                }

                if (args.Cancel)
                {
                    response.SetStatutCode(401);
                }
                else
                {
                    response.SetStatutCode(200);
                }
            }
            else
            {
                response.SetStatutCode(200);
            }

            await response.SetDataAsync(new MemoryStream(Encoding.UTF8.GetBytes("OK")));

            return(true);
        }
Exemple #15
0
        private void Authorize(string targetUrl, bool clearExisting)
        {
            if (clearExisting)
            {
                WebViewHelper.ClearCookies();
                TokenHelper.ClearTokens();
                LocalConfiguration.IsLoggedInByFacebook = false;
            }

            var authorizationUrl = Authorization.GetAuthorizationUrl(targetUrl);

            WebViewHelper.Navigate(new Uri(authorizationUrl));
        }
Exemple #16
0
        private async Task <bool> ValidateRequestAndroid(string webextensionId)
        {
            string cancel = "false";

            if (int.TryParse(webextensionId, out int runtimeId))
            {
                var webview = WebViewHelper.GetWebViewByRuntimeIdentity(runtimeId);
                if (webview != null)
                {
                    string uri      = this.Request.QueryString.Get("uri");
                    string referrer = this.Request.QueryString.Get("referrer");

                    if (ShouldExcludeFromNavigatingEvent(uri, out bool shouldCancel))
                    {
                        if (shouldCancel)
                        {
                            cancel = "true";
                        }
                    }
                    else
                    {
                        var args = new WebNavigatingEventArgs(
                            WebNavigationEvent.NewPage,
                            new UrlWebViewSource()
                        {
                            Url = referrer
                        },
                            uri);

                        webview.SendNavigating(args);

                        if (args.Cancel)
                        {
                            cancel = "true";
                        }
                    }
                }
            }

            IWebResponse response = new EmbedIOWebResponse(this.Request, this.Response);

            response.SetEncoding("UTF-8");
            response.AddResponseHeader("Cache-Control", "no-cache");
            response.SetStatutCode(200);
            response.SetReasonPhrase("OK");
            response.SetMimeType("text/plain");
            await response.SetDataAsync(new MemoryStream(Encoding.UTF8.GetBytes(cancel)));

            return(true);
        }
        /// <summary>
        /// This method is specific as it is also used as the Blazor app initialization validator.
        /// This method is always called once after a Blazor app boot
        /// </summary>
        /// <returns></returns>
        public Task <string> GetRuntimePlatform()
        {
            //HACK: This is more a hack than the cleanest implementation we would expect.
            //We cannot determine what is the current executing WebView calling this method,
            //as it's a service called remotely than a WebView callback. We are assuming here that
            //all eligible WebViews with IWebViewIdentity interface are the Blazor app to check.
            //The right fix would be to be able to pass the WebView identity to the Blazor app, and then
            //forward it here when the BlazorMobileComponent want to initialize
            foreach (IWebViewIdentity identity in WebViewHelper.GetAllWebViewIdentities())
            {
                identity.BlazorAppLaunched = true;
            }

            return(Task.FromResult(BlazorMobile.Common.BlazorDevice.RuntimePlatform));
        }
Exemple #18
0
        private async void FinalizeAuthorization(string url)
        {
            try
            {
                var urlDecoder = new WwwFormUrlDecoder(url.Substring(url.IndexOf('?') + 1));
                await Authorization.RetrieveAndSaveTokensFromAuthCode(urlDecoder.GetFirstValueByName("code"));

                WebViewHelper.Navigate(new Uri(urlDecoder.GetFirstValueByName("state")));
            }
            catch (Exception ex)
            {
                logger.Info("Authorization failed. " + ex.ToString());

                Authorize("https://open.spotify.com/", clearExisting: false);
            }
        }
Exemple #19
0
        public MainPage()
        {
            ProxyHelper.ApplyProxySettings();
            this.InitializeComponent();

            silentMediaPlayer = new MediaPlayer
            {
                Source           = MediaSource.CreateFromUri(new Uri("ms-appx:///Assets/Media/silent.wav")),
                IsLoopingEnabled = true,
            };
            silentMediaPlayer.CommandManager.IsEnabled = false;

            WebViewHelper.Init(this.mainWebView);

            loadFailedAppVersionText.Text = PackageHelper.GetAppVersionString();
            VisualStateManager.GoToState(this, "SplashScreen", false);
        }
Exemple #20
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            var targetUrl = GetTargetUrl(e);

            if (TokenHelper.HasTokens())
            {
                if (LocalConfiguration.IsLoggedInByFacebook)
                {
                    // We need to open the login page and click on facebook button
                    logger.Info("Logging in via Facebook...");
                    var loginUrl = "https://accounts.spotify.com/login?continue=" + System.Net.WebUtility.UrlEncode(targetUrl);
                    WebViewHelper.Navigate(new Uri(loginUrl));
                }
                else
                {
                    WebViewHelper.Navigate(new Uri(targetUrl));
                }
            }
            else
            {
                Authorize(targetUrl, clearExisting: false);
            }
        }
        public IActionResult Index(string uri, string referrer)
        {
            bool cancel = false;

            if (!string.IsNullOrEmpty(uri) && !string.IsNullOrEmpty(referrer))
            {
                var args = new WebNavigatingEventArgs(
                    WebNavigationEvent.NewPage,
                    new UrlWebViewSource()
                {
                    Url = referrer
                },
                    uri);

                //This is not entirely true as we would only compare the current BlazorWebview
                //but it must be only one executed btw
                foreach (var webIdentity in WebViewHelper.GetAllWebViewIdentities())
                {
                    var webview = webIdentity as IBlazorWebView;
                    webview.SendNavigating(args);

                    if (args.Cancel)
                    {
                        cancel = true;
                        break;
                    }
                }
            }

            if (cancel)
            {
                return(StatusCode(401));
            }

            return(StatusCode(200));
        }
Exemple #22
0
 private void RetryConnectButton_Click(object sender, RoutedEventArgs e)
 {
     VisualStateManager.GoToState(this, "SplashScreen", false);
     WebViewHelper.Navigate(loadFailedUrl);
 }
Exemple #23
0
        //public bool ShowHistory { get; set; }

        public SummaryVM()
        {
            ViewHelper = new WebViewHelper(this);
        }
 public PermissionsListVM()
 {
     ViewHelper = new WebViewHelper(this);
 }
Exemple #25
0
 public PermissionListVM()
 {
     this.ViewHelper = new WebViewHelper(this);
     this.ListBase   = new ViewModelListBase();
 }
Exemple #26
0
 public ProviderTypeVM()
 {
     this.ViewHelper = new WebViewHelper(this);
 }
Exemple #27
0
 public CaseGeneralHoursListItemVM()
 {
     ViewHelper = new WebViewHelper(this);
 }
Exemple #28
0
 public AuthCreateVM()
 {
     ViewHelper = new WebViewHelper(this);
 }
 private void ReloadBlazorAppEvent(object sender, EventArgs e)
 {
     WebViewHelper.InternalLaunchBlazorApp(this, true);
 }
 public PatientsListVM(ListViewType listViewType)
 {
     ListViewType = listViewType;
     ListBase     = new ViewModelListBase();
     ViewHelper   = new WebViewHelper(this);
 }