private async void AutoPlayOnStartup(AutoPlayAction autoPlayAction) { await Task.Delay(TimeSpan.FromSeconds(1)); logger.Info("AutoPlay " + autoPlayAction); await WebViewHelper.AutoPlay(autoPlayAction); }
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}"); } }
internal async Task AutoPlay(AutoPlayAction action) { string script; if (action == AutoPlayAction.Track) { script = "window.XpotifyScript.Common.Action.autoPlayTrack();"; } else { script = "window.XpotifyScript.Common.Action.autoPlayPlaylist();"; } var currentPlaying = await mainWebView.InvokeScriptAsync("eval", new string[] { script }); }
private string GetTargetUrl(NavigationEventArgs e) { var destinationUrl = "https://open.spotify.com"; var parameter = e.Parameter as string; if (!string.IsNullOrEmpty(parameter)) { try { // Launched from a secondary tile var urlDecoder = new WwwFormUrlDecoder(parameter); var pageUrl = urlDecoder.GetFirstValueByName("pageUrl"); var autoplayEntry = urlDecoder.FirstOrDefault(x => x.Name == "autoplay"); if (autoplayEntry != null) { autoPlayAction = autoplayEntry.Value == "track" ? AutoPlayAction.Track : AutoPlayAction.Playlist; } else { autoPlayAction = AutoPlayAction.None; } var sourceEntry = urlDecoder.FirstOrDefault(x => x.Name == "source"); if (sourceEntry != null && sourceEntry.Value == "cortana" && LocalConfiguration.OpenInMiniViewByCortana) { OpenCompactOverlayForAutoPlay(); } destinationUrl = pageUrl; } catch (Exception ex) { logger.Info($"Parsing input parameter {e.Parameter.ToString()} failed. {ex}"); } } return("https://open.spotify.com/static/offline.html?redirectUrl=" + System.Net.WebUtility.UrlEncode(destinationUrl)); }
private async void MainWebView_LoadCompleted(object sender, NavigationEventArgs e) { if (e.Uri.ToString().StartsWith(Authorization.SpotifyLoginUri) && LocalConfiguration.IsLoggedInByFacebook) { if (await WebViewHelper.TryPushingFacebookLoginButton()) { logger.Info("Pushed the facebook login button."); return; } } if (e.Uri.ToString().StartsWith("https://open.spotify.com/static/offline.html?redirectUrl=")) { var url = e.Uri.ToString(); logger.Info("Clearing local storage and redirecting..."); var result = await WebViewHelper.ClearPlaybackLocalStorage(); try { if (result.Length > 0) { initialPlaybackState = JsonConvert.DeserializeObject <LocalStoragePlayback>(result); logger.Info("initial playback volume = " + initialPlaybackState.volume); } else { logger.Info("localStorage.playback was undefined."); } } catch { logger.Warn("Decoding localStorage.playback failed."); logger.Info("localStorage.playback content was: " + result); } var urlDecoder = new WwwFormUrlDecoder(url.Substring(url.IndexOf('?') + 1)); WebViewHelper.Navigate(new Uri(urlDecoder.GetFirstValueByName("redirectUrl"))); return; } if (e.Uri.ToString().ToLower().Contains(WebViewHelper.SpotifyPwaUrlBeginsWith.ToLower())) { var justInjected = await WebViewHelper.InjectInitScript(ThemeHelper.GetCurrentTheme() == Theme.Light); if (justInjected) { SetInitialPlaybackState(); } if (autoPlayAction != AutoPlayAction.None) { AutoPlayOnStartup(autoPlayAction); autoPlayAction = AutoPlayAction.None; } } var currentStateName = VisualStateManager.GetVisualStateGroups(mainGrid).FirstOrDefault().CurrentState.Name; if (currentStateName == "SplashScreen" || currentStateName == "LoadFailedScreen") { if (e.Uri.ToString().ToLower().Contains(WebViewHelper.SpotifyPwaUrlBeginsWith.ToLower())) { VisualStateManager.GoToState(this, "MainScreen", false); } else { VisualStateManager.GoToState(this, "MainScreenQuick", false); } if (shouldShowWhatsNew) { OpenWhatsNew(); } else if (developerMessage != null) { // Don't show developer message now if what's new is being shown. // It'll be shown after user closes the what's new flyout. OpenDeveloperMessage(developerMessage); developerMessage = null; } } if (e.Uri.ToString().StartsWith(Authorization.RedirectUri)) { FinalizeAuthorization(e.Uri.ToString()); } if (!await WebViewHelper.CheckLoggedIn()) { Authorize("https://accounts.spotify.com/login?continue=https%3A%2F%2Fopen.spotify.com%2F", clearExisting: true); AnalyticsHelper.Log("mainEvent", "notLoggedIn"); } }
internal static async Task AutoPlay(AutoPlayAction action) { var script = await AssetManager.LoadAssetString(action == AutoPlayAction.Track? "autoplayTrack.js" : "autoplayPlaylist.js"); var currentPlaying = await mainWebView.InvokeScriptAsync("eval", new string[] { script }); }