Exemple #1
0
        private async void InternalLaunchAsync(ILaunchActivatedEventArgs e)
        {
            UIElement splashScreen = default(UIElement);
            if (SplashFactory != null)
            {
                splashScreen = SplashFactory(e.SplashScreen);
                Window.Current.Content = splashScreen;
            }

            // setup frame
            RootFrame = RootFrame ?? new Frame();
            RootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0];
            NavigationService = new Services.NavigationService.NavigationService(RootFrame);

            // expire state
            var state = NavigationService.State();
            if (state.Values.ContainsKey(CacheKey))
            {
                DateTime cacheDate;
                if (DateTime.TryParse(state.Values[CacheKey]?.ToString(), out cacheDate))
                {
                    var cacheAge = DateTime.Now.Subtract(cacheDate);
                    if (cacheAge >= CacheMaxDuration)
                    {
                        foreach (var item in state.Containers)
                        {
                            state.DeleteContainer(item.Key);
                        }
                        state.Values.Clear();
                    }
                }
            }

            // the user may override to set custom content
            await OnInitializeAsync();
            switch (e.PreviousExecutionState)
            {
                case ApplicationExecutionState.NotRunning:
                case ApplicationExecutionState.Running:
                case ApplicationExecutionState.Suspended:
                    {
                        // launch if not restored
                        await OnStartAsync(StartKind.Launch, e);
                        break;
                    }
                case ApplicationExecutionState.Terminated:
                    await OnStartAsync(StartKind.Launch, e);
                    break;
                case ApplicationExecutionState.ClosedByUser:
                    {
                        // restore if you need to/can do
                        var restored = NavigationService.RestoreSavedNavigation();
                        if (!restored)
                        {
                            await OnStartAsync(StartKind.Launch, e);
                        }
                        break;
                    }
            }

            // if the user didn't already set custom content use rootframe
            if (Window.Current.Content == splashScreen)
            {
                Window.Current.Content = RootFrame;
            }
            if (Window.Current.Content == null)
            {
                Window.Current.Content = RootFrame;
            }

            // ensure active
            Window.Current.Activate();

            // Hook up the default Back handler
            Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested += (s, args) =>
            {
                args.Handled = true;
                OnBackRequested();
            };

            // Hook up keyboard and mouse Back handler
            var keyboard = new Services.KeyboardService.KeyboardService();
            keyboard.AfterBackGesture = () => OnBackRequested();

            // Hook up keyboard and house Forward handler
            keyboard.AfterForwardGesture = () => OnForwardRequested();
        }
Exemple #2
0
        private async void InternalLaunchAsync(ILaunchActivatedEventArgs e)
        {
            UIElement splashScreen = default(UIElement);

            if (SplashFactory != null)
            {
                splashScreen           = SplashFactory(e.SplashScreen);
                Window.Current.Content = splashScreen;
            }

            // setup frame
            RootFrame          = RootFrame ?? new Frame();
            RootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0];
            NavigationService  = new Services.NavigationService.NavigationService(RootFrame);

            // expire state
            var state = NavigationService.State();

            if (state.Values.ContainsKey(CacheKey))
            {
                DateTime cacheDate;
                if (DateTime.TryParse(state.Values[CacheKey]?.ToString(), out cacheDate))
                {
                    var cacheAge = DateTime.Now.Subtract(cacheDate);
                    if (cacheAge >= CacheMaxDuration)
                    {
                        foreach (var item in state.Containers)
                        {
                            state.DeleteContainer(item.Key);
                        }
                        state.Values.Clear();
                    }
                }
            }

            // the user may override to set custom content
            await OnInitializeAsync();

            switch (e.PreviousExecutionState)
            {
            case ApplicationExecutionState.NotRunning:
            case ApplicationExecutionState.Running:
            case ApplicationExecutionState.Suspended:
            {
                // launch if not restored
                await OnStartAsync(StartKind.Launch, e);

                break;
            }

            case ApplicationExecutionState.Terminated:
                await OnStartAsync(StartKind.Launch, e);

                break;

            case ApplicationExecutionState.ClosedByUser:
            {
                // restore if you need to/can do
                var restored = NavigationService.RestoreSavedNavigation();
                if (!restored)
                {
                    await OnStartAsync(StartKind.Launch, e);
                }
                break;
            }
            }

            // if the user didn't already set custom content use rootframe
            if (Window.Current.Content == splashScreen)
            {
                Window.Current.Content = RootFrame;
            }
            if (Window.Current.Content == null)
            {
                Window.Current.Content = RootFrame;
            }

            // ensure active
            Window.Current.Activate();

            // Hook up the default Back handler
            Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested += (s, args) =>
            {
                args.Handled = true;
                OnBackRequested();
            };

            // Hook up keyboard and mouse Back handler
            var keyboard = new Services.KeyboardService.KeyboardService();

            keyboard.AfterBackGesture = () => OnBackRequested();

            // Hook up keyboard and house Forward handler
            keyboard.AfterForwardGesture = () => OnForwardRequested();
        }