Example #1
0
        /// <summary>
        ///     Invoked when application execution is being suspended.  Application state is saved
        ///     without knowing whether the application will be terminated or resumed with the contents
        ///     of memory still intact.
        /// </summary>
        /// <param name="sender">The source of the suspend request.</param>
        /// <param name="e">Details about the suspend request.</param>
        private async void OnSuspending(object sender, SuspendingEventArgs e)
        {
            var deferral = e.SuspendingOperation.GetDeferral();

            if (Settings.IsCachingEnabled)
            {
                if (AnimeUpdateQuery.UpdatedSomething)
                {
                    await
                    DataCache.SaveDataForUser(Credentials.UserName,
                                              ResourceLocator.AnimeLibraryDataStorage.AllLoadedAnimeItemAbstractions.Select(
                                                  abstraction => abstraction.EntryData), AnimeListWorkModes.Anime);
                }
                if (MangaUpdateQuery.UpdatedSomething)
                {
                    await
                    DataCache.SaveDataForUser(Credentials.UserName,
                                              ResourceLocator.AnimeLibraryDataStorage.AllLoadedMangaItemAbstractions.Select(
                                                  abstraction => abstraction.EntryData), AnimeListWorkModes.Manga);
                }
            }
            try
            {
                foreach (
                    var file in
                    await ApplicationData.Current.TemporaryFolder.GetFilesAsync(CommonFileQuery.DefaultQuery))
                {
                    if (file.Name.Contains("_cropTemp"))
                    {
                        await file.DeleteAsync(StorageDeleteOption.PermanentDelete);
                    }
                }
            }
            catch (Exception)
            {
                //well...
            }
            await DataCache.SaveVolatileData();

            await DataCache.SaveHumMalIdDictionary();

            await ViewModelLocator.ForumsMain.SavePinnedTopics();

            await FavouritesManager.SaveData();

            await AnimeImageQuery.SaveData();

            await ResourceLocator.HandyDataStorage.SaveData();

            deferral.Complete();
        }
Example #2
0
        protected async void OnLaunchedOrActivated(IActivatedEventArgs e)
        {
            ApplicationView.GetForCurrentView().SetPreferredMinSize(new Size(500, 500));
            var rootFrame = Window.Current.Content as Frame;
            Tuple <int, string>       navArgs     = null;
            Tuple <PageIndex, object> fullNavArgs = null;
            var launchArgs = e as LaunchActivatedEventArgs;

            if (!string.IsNullOrWhiteSpace(launchArgs?.Arguments))
            {
                if (Regex.IsMatch(launchArgs.Arguments, @"[OpenUrl,OpenDetails];.*"))
                {
                    var options = launchArgs.Arguments.Split(';');
                    if (options[0] == TileActions.OpenUrl.ToString())
                    {
                        LaunchUri(options[1]);
                    }
                    else if (launchArgs.Arguments.Contains('|')) //legacy
                    {
                        var detailArgs = options[1].Split('|');
                        navArgs = new Tuple <int, string>(int.Parse(detailArgs[0]), detailArgs[1]);
                    }
                    else
                    {
                        fullNavArgs = MalLinkParser.GetNavigationParametersForUrl(options[1]);
                    }
                }
                else
                {
                    fullNavArgs = MalLinkParser.GetNavigationParametersForUrl(launchArgs.Arguments);
                }
            }
            else if (e is ProtocolActivatedEventArgs)
            {
                fullNavArgs = MalLinkParser.GetNavigationParametersForUrl("https:" + (e as ProtocolActivatedEventArgs).Uri.AbsolutePath);
            }
            else
            {
                var activationArgs = e as ToastNotificationActivatedEventArgs;
                if (activationArgs != null)
                {
                    var arg = activationArgs.Argument;
                    var pos = arg.IndexOf('~');
                    if (pos != -1)
                    {
                        var id = arg.Substring(0, pos);
                        arg = arg.Substring(pos + 1);
                        MalNotificationsQuery.MarkNotifiactionsAsRead(new MalNotification(id));
                    }
                    if (arg.Contains(";"))
                    {
                        var options = activationArgs.Argument.Split(';');
                        if (options[0] == TileActions.OpenUrl.ToString())
                        {
                            LaunchUri(options[1]);
                        }
                    }
                    else
                    {
                        fullNavArgs = MalLinkParser.GetNavigationParametersForUrl(arg);
                    }
                }
            }



            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //nothing
                }
                if (e.PreviousExecutionState == ApplicationExecutionState.NotRunning)
                //Crashed - we have to remove cached anime list
                {
                    if (Settings.IsCachingEnabled)
                    {
                        await DataCache.ClearAnimeListData(); //clear all cached users data
                    }
                }



                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (rootFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                if (navArgs != null)
                {
                    MainViewModelBase.InitDetails = navArgs;
                }
                else if (fullNavArgs != null)
                {
                    MainViewModelBase.InitDetailsFull = fullNavArgs;
                }
                rootFrame.Navigate(typeof(MainPage));
            }
            else if (navArgs != null)
            {
                ViewModelLocator.GeneralMain.Navigate(PageIndex.PageAnimeDetails,
                                                      new AnimeDetailsPageNavigationArgs(navArgs.Item1, navArgs.Item2, null, null));
            }

            if (_initialized && fullNavArgs != null)
            {
                ViewModelLocator.GeneralMain.Navigate(fullNavArgs.Item1, fullNavArgs.Item2);
            }
            // Ensure the current window is active
            if (_initialized)
            {
                return;
            }

            InitializationRoutines.InitApp();

            NotificationTaskManager.StartNotificationTask(BgTasks.ToastActivation, false);
            NotificationTaskManager.StartNotificationTask(BgTasks.Notifications, false);
            NotificationTaskManager.OnNotificationTaskRequested += NotificationTaskManagerOnOnNotificationTaskRequested;
            ImageCache.PerformScheduledCacheCleanup();

            LiveTilesManager.LoadTileCache();

            Window.Current.Activate();
            RateReminderPopUp.ProcessRatePopUp();
            ProcessStatusBar();
            ProcessUpdate();
            StoreLogoWorkaroundHacker.Hack();
            _initialized = true;
        }