public AlbumsPage() { this.InitializeComponent(); this.NavigationCacheMode = NavigationCacheMode.Enabled; MusicLibraryPage.AddAfterSongsSetListener(this); AlbumArtControl.ImageSavedListeners.Add(this); }
public static async void Save() { Settings.Save(); MusicLibraryPage.Save(); MediaHelper.Save(); AlbumsPage.Save(); RecentPage.Save(); UpdateHelper.Save(); await Helper.ClearBackups(10); }
public static async void CheckNewMusic(FolderTree tree, Action <FolderTree> afterTreeUpdated = null) { MainPage.Instance?.Loader.ShowIndeterminant("ProcessRequest"); var data = new TreeUpdateData(); if (!await tree.CheckNewFile(data)) { if (!string.IsNullOrEmpty(data.Message)) { MainPage.Instance.ShowNotification(data.Message); } MainPage.Instance?.Loader.Hide(); return; } if (data.More != 0 || data.Less != 0) { Settings.settings.Tree.FindTree(tree).CopyFrom(tree); MusicLibraryPage.SortAndSetAllSongs(Settings.settings.Tree.Flatten()); foreach (var listener in listeners) { listener.PathSet(tree.Path); } if (data.Less != 0) { MediaHelper.RemoveBadMusic(); } afterTreeUpdated?.Invoke(tree); App.Save(); } MainPage.Instance?.Loader.Hide(); string message; if (data.More == 0 && data.Less == 0) { message = Helper.LocalizeMessage("CheckNewMusicResultNoChange"); } else if (data.More == 0) { message = Helper.LocalizeMessage("CheckNewMusicResultRemoved", data.Less); } else if (data.Less == 0) { message = Helper.LocalizeMessage("CheckNewMusicResultAdded", data.More); } else { message = Helper.LocalizeMessage("CheckNewMusicResultChange", data.More, data.Less); } Helper.ShowNotificationWithoutLocalization(message); }
public static async Task <bool> UpdateMusicLibrary(StorageFolder folder, string message = null) { MainPage.Instance.Loader.ShowDeterminant(message ?? "LoadMusicLibrary", true); loadingTree = new FolderTree(); if (!await loadingTree.Init(folder, (treeFolder, file, progress, max) => { bool isDeterminant = max != 0; if (MainPage.Instance.Loader.IsDeterminant != isDeterminant) { MainPage.Instance.Loader.IsDeterminant = isDeterminant; } if (isDeterminant) { MainPage.Instance.Loader.Max = max; MainPage.Instance.Loader.Progress = progress; MainPage.Instance.Loader.Text = message ?? file; } })) { return(false); } MainPage.Instance.Loader.SetLocalizedText(message ?? "UpdateMusicLibrary"); Helper.CurrentFolder = folder; await Task.Run(() => { loadingTree.MergeFrom(Settings.settings.Tree); Settings.settings.Tree = loadingTree; Settings.settings.RootPath = folder.Path; }); MusicLibraryPage.SortAndSetAllSongs(await Task.Run(Settings.settings.Tree.Flatten)); MainPage.Instance.Loader.Progress = 0; MainPage.Instance.Loader.Max = listeners.Count; for (int i = 0; i < listeners.Count;) { var listener = listeners[i]; listener.PathSet(folder.Path); MainPage.Instance.Loader.Progress = ++i; } MediaHelper.RemoveBadMusic(); App.Save(); MainPage.Instance.Loader.Hide(); return(true); }
private async void OnLaunched(LaunchActivatedEventArgs e, Music music) { await Settings.Init(); await MusicLibraryPage.Init(); if (Settings.settings.LastPage == "Albums") { await AlbumsPage.Init(); } await Helper.Init(); await UpdateHelper.Init(); Frame rootFrame = Window.Current.Content as Frame; // 不要在窗口已包含内容时重复应用程序初始化, // 只需确保窗口处于活动状态 if (rootFrame == null) { // 创建要充当导航上下文的框架,并导航到第一页 rootFrame = new Frame(); rootFrame.NavigationFailed += OnNavigationFailed; if (e?.PreviousExecutionState == ApplicationExecutionState.Terminated) { //TODO: 从之前挂起的应用程序加载状态 } // 将框架放在当前窗口中 Window.Current.Content = rootFrame; } if (e == null || e.PrelaunchActivated == false) { if (Windows.Foundation.Metadata.ApiInformation.IsMethodPresent("Windows.ApplicationModel.Core.CoreApplication", "EnablePrelaunch")) { Windows.ApplicationModel.Core.CoreApplication.EnablePrelaunch(true); } if (rootFrame.Content == null) { // 当导航堆栈尚未还原时,导航到第一页, // 并通过将所需信息作为导航参数传入来配置 // 参数 rootFrame.Navigate(typeof(MainPage), e?.Arguments); if (e != null && e.TileId != "App") { var tileId = System.Net.WebUtility.UrlDecode(e.TileId); MainPage.Instance.NavigateToPage(bool.Parse(e.Arguments) ? typeof(PlaylistsPage) : tileId.StartsWith(Helper.Localize(MenuFlyoutHelper.MyFavorites)) ? typeof(MyFavoritesPage) : typeof(AlbumPage), tileId); } } // 确保当前窗口处于活动状态 Window.Current.Activate(); } Windows.ApplicationModel.Core.CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true; MediaHelper.Init(music); await AlbumsPage.Init(); await RecentPage.Init(); ToastHelper.Init(); //LaunchVoiceAssistant(); foreach (var listener in LoadedListeners) { listener.Invoke(); } Inited = true; // If background task is already registered, do nothing if (BackgroundTaskRegistration.AllTasks.Any(i => i.Value.Name.Equals(ToastHelper.ToastTaskName))) { return; } // Otherwise request access BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync(); // Create the background task BackgroundTaskBuilder builder = new BackgroundTaskBuilder() { Name = ToastHelper.ToastTaskName }; // Assign the toast action trigger builder.SetTrigger(new ToastNotificationActionTrigger()); // And register the task BackgroundTaskRegistration registration = builder.Register(); }