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(); }
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(); }
/// <summary> /// This handles all the preliminary stuff unique to Launched before calling OnStartAsync(). /// This is private because it is a specialized prelude to OnStartAsync(). /// OnStartAsync will not be called if state restore is determined /// </summary> private async void InternalLaunchAsync(ILaunchActivatedEventArgs e) { if (e.PreviousExecutionState != ApplicationExecutionState.Running) { await InitializeFrameAsync(e); } // okay, now handle launch switch (e.PreviousExecutionState) { //case ApplicationExecutionState.ClosedByUser: case ApplicationExecutionState.Terminated: { /* * Restore state if you need to/can do. * Remember that only the primary tile should restore. * (this includes toast with no data payload) * The rest are already providing a nav path. * * In the event that the cache has expired, attempting to restore * from state will fail because of missing values. * This is okay & by design. */ if (DetermineStartCause(e) == AdditionalKinds.Primary) { var restored = NavigationService.RestoreSavedNavigation(); if (!restored) { await OnStartAsync(StartKind.Launch, e); } } else { await OnStartAsync(StartKind.Launch, e); } SubscribeBackButton(); break; } case ApplicationExecutionState.ClosedByUser: case ApplicationExecutionState.NotRunning: // launch if not restored await OnStartAsync(StartKind.Launch, e); SubscribeBackButton(); break; default: { // launch if not restored await OnStartAsync(StartKind.Launch, e); break; } } // ensure active (this will hide any custom splashscreen) Window.Current.Activate(); // Hook up keyboard and mouse Back handler var keyboard = new Services.KeyboardService.KeyboardService(); keyboard.AfterBackGesture = () => { //the result is no matter var handled = false; RaiseBackRequested(ref handled); }; // Hook up keyboard and mouse Forward handler keyboard.AfterForwardGesture = RaiseForwardRequested; }
/// <summary> /// This handles all the preliminary stuff unique to Launched before calling OnStartAsync(). /// This is private because it is a specialized prelude to OnStartAsync(). /// OnStartAsync will not be called if state restore is determined /// </summary> private async void InternalLaunchAsync(ILaunchActivatedEventArgs e) { await InitializeFrameAsync(e); // okay, now handle launch switch (e.PreviousExecutionState) { case ApplicationExecutionState.ClosedByUser: case ApplicationExecutionState.Terminated: { /* Restore state if you need to/can do. Remember that only the primary tile should restore. (this includes toast with no data payload) The rest are already providing a nav path. In the event that the cache has expired, attempting to restore from state will fail because of missing values. This is okay & by design. */ if (DecipherStartCause(e) == AdditionalKinds.Primary) { var restored = NavigationService.RestoreSavedNavigation(); if (!restored) { await OnStartAsync(StartKind.Launch, e); } } else { await OnStartAsync(StartKind.Launch, e); } break; } default: { // launch if not restored await OnStartAsync(StartKind.Launch, e); break; } } // ensure active (this will hide any custom splashscreen) Window.Current.Activate(); // Hook up the default Back handler global::Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested += (s, args) => { // only handle as long as there is a default backstack args.Handled = !NavigationService.CanGoBack; RaiseBackRequested(); }; // Hook up keyboard and mouse Back handler var keyboard = new Services.KeyboardService.KeyboardService(); keyboard.AfterBackGesture = () => RaiseBackRequested(); // Hook up keyboard and house Forward handler keyboard.AfterForwardGesture = () => RaiseForwardRequested(); }
private async void InternalLaunchAsync(ILaunchActivatedEventArgs e) { // first handle prelaunch, which will not continue if ((e.Kind == ActivationKind.Launch) && ((e as LaunchActivatedEventArgs)?.PrelaunchActivated ?? false)) { OnPrelaunch(); return; } // now handle normal activation UIElement splashScreen = default(UIElement); if (SplashFactory != null) { splashScreen = SplashFactory(e.SplashScreen); Window.Current.Content = splashScreen; } // setup frame var frame = new Frame { Language = global::Windows.Globalization.ApplicationLanguages.Languages[0] }; frame.Navigated += (s, args) => { global::Windows.UI.Core.SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = (ShowShellBackButton && frame.CanGoBack) ? AppViewBackButtonVisibility.Visible : AppViewBackButtonVisibility.Collapsed; }; // setup default view var view = WindowWrapper.ActiveWrappers.First(); var navigationService = new Services.NavigationService.NavigationService(frame); view.NavigationServices.Add(navigationService); // expire state (based on expiry) DateTime cacheDate; var otherwise = DateTime.MinValue.ToString(); if (DateTime.TryParse(navigationService.Frame.GetFrameState(CacheKey, otherwise), out cacheDate)) { var cacheAge = DateTime.Now.Subtract(cacheDate); if (cacheAge >= CacheMaxDuration) { // clear state in every nav service in every view foreach (var service in WindowWrapper.ActiveWrappers.SelectMany(x => x.NavigationServices)) { service.Frame.ClearFrameState(); } } } else { // no date, that's okay } // 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.ClosedByUser: case ApplicationExecutionState.Terminated: { // 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 = frame; } if (Window.Current.Content == null) { Window.Current.Content = frame; } // ensure active Window.Current.Activate(); // Hook up the default Back handler global::Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested += (s, args) => { // TODO: handled=true canisn't true at end of backstack args.Handled = true; RaiseBackRequested(); }; // Hook up keyboard and mouse Back handler var keyboard = new Services.KeyboardService.KeyboardService(); keyboard.AfterBackGesture = () => RaiseBackRequested(); // Hook up keyboard and house Forward handler keyboard.AfterForwardGesture = () => RaiseForwardRequested(); }
// this is private because it is a specialized prelude to OnStartAsync private async void InternalLaunchAsync(ILaunchActivatedEventArgs e) { // create the root frame var defaultFrame = InitializeFrame(e); // the user may override to set custom content await OnInitializeAsync(e); // okay, now handle launch switch (e.PreviousExecutionState) { case ApplicationExecutionState.NotRunning: case ApplicationExecutionState.Running: case ApplicationExecutionState.Suspended: { // launch if not restored await OnStartAsync(StartKind.Launch, e); break; } case ApplicationExecutionState.ClosedByUser: case ApplicationExecutionState.Terminated: { // restore if you need to/can do // restore if there is no TileId or if the app is luanched via the primary tile // TODO: is it actually possible to have a TileID of null? Don't think so. if (e.TileId == null || e.TileId == "App") { // In the event that the cache ahs expired, attempting to restore // from state will fail because of missing values. This is by design. var restored = NavigationService.RestoreSavedNavigation(); if (!restored) { await OnStartAsync(StartKind.Launch, e); } } else { await OnStartAsync(StartKind.Launch, e); } break; } } // ensure active (this will hide any custom splashscreen) Window.Current.Activate(); // Hook up the default Back handler global::Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested += (s, args) => { // only handle as long as there is a default backstack args.Handled = !NavigationService.CanGoBack; RaiseBackRequested(); }; // Hook up keyboard and mouse Back handler var keyboard = new Services.KeyboardService.KeyboardService(); keyboard.AfterBackGesture = () => RaiseBackRequested(); // Hook up keyboard and house Forward handler keyboard.AfterForwardGesture = () => RaiseForwardRequested(); }
private async void InternalLaunchAsync(ILaunchActivatedEventArgs e) { UIElement splashScreen = default(UIElement); if (SplashFactory != null) { splashScreen = SplashFactory(e.SplashScreen); Window.Current.Content = splashScreen; } RootFrame = RootFrame ?? new Frame(); RootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0]; NavigationService = new Services.NavigationService.NavigationService(RootFrame); // 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: case ApplicationExecutionState.ClosedByUser: { if (EnableRestoreNavigationState) { // restore if you need to/can do var restored = NavigationService.RestoreSavedNavigation(); if (!restored) await OnStartAsync(StartKind.Launch, e); } else { 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(); }
private async void InternalLaunchAsync(ILaunchActivatedEventArgs e) { UIElement splashScreen = default(UIElement); if (SplashFactory != null) { splashScreen = SplashFactory(e.SplashScreen); Window.Current.Content = splashScreen; } RootFrame = RootFrame ?? new Frame(); RootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0]; NavigationService = new Services.NavigationService.NavigationService(RootFrame); // 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: case ApplicationExecutionState.ClosedByUser: { if (EnableRestoreNavigationState) { // restore if you need to/can do var restored = NavigationService.RestoreSavedNavigation(); if (!restored) { await OnStartAsync(StartKind.Launch, e); } } else { 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(); }
private async void InternalLaunchAsync(ILaunchActivatedEventArgs e) { // first handle prelaunch, which will not continue if ((e.Kind == ActivationKind.Launch) && ((e as LaunchActivatedEventArgs)?.PrelaunchActivated ?? false)) { OnPrelaunch(); return; } // create the root frame var frame = InitializeFrame(e); // 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.ClosedByUser: case ApplicationExecutionState.Terminated: { // restore if you need to/can do // restore if there is no TileId or if the app is luanched via the primary tile if (e.TileId == null || e.TileId == "App") { var restored = NavigationService.RestoreSavedNavigation(); if (!restored) { await OnStartAsync(StartKind.Launch, e); } } else { await OnStartAsync(StartKind.Launch, e); } break; } } // ensure active Window.Current.Activate(); // Hook up the default Back handler global::Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested += (s, args) => { // TODO: handled=true canisn't true at end of backstack args.Handled = true; RaiseBackRequested(); }; // Hook up keyboard and mouse Back handler var keyboard = new Services.KeyboardService.KeyboardService(); keyboard.AfterBackGesture = () => RaiseBackRequested(); // Hook up keyboard and house Forward handler keyboard.AfterForwardGesture = () => RaiseForwardRequested(); }
#pragma warning restore 809 /// <summary> /// This handles all the preliminary stuff unique to Launched before calling OnStartAsync(). /// This is private because it is a specialized prelude to OnStartAsync(). /// OnStartAsync will not be called if state restore is determined /// </summary> private async void InternalLaunchAsync(ILaunchActivatedEventArgs e) { await InitializeFrameAsync(e); // okay, now handle launch switch (e.PreviousExecutionState) { case ApplicationExecutionState.ClosedByUser: case ApplicationExecutionState.Terminated: { /* * Restore state if you need to/can do. * Remember that only the primary tile should restore. * (this includes toast with no data payload) * The rest are already providing a nav path. * * In the event that the cache has expired, attempting to restore * from state will fail because of missing values. * This is okay & by design. */ if (DecipherStartCause(e) == AdditionalKinds.Primary) { var restored = NavigationService.RestoreSavedNavigation(); if (!restored) { await OnStartAsync(StartKind.Launch, e); } } else { await OnStartAsync(StartKind.Launch, e); } break; } default: { // launch if not restored await OnStartAsync(StartKind.Launch, e); break; } } // ensure active (this will hide any custom splashscreen) Window.Current.Activate(); // Hook up the default Back handler global::Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested += (s, args) => { // only handle as long as there is a default backstack args.Handled = !NavigationService.CanGoBack; RaiseBackRequested(); }; // Hook up keyboard and mouse Back handler var keyboard = new Services.KeyboardService.KeyboardService(); keyboard.AfterBackGesture = () => RaiseBackRequested(); // Hook up keyboard and house Forward handler keyboard.AfterForwardGesture = () => RaiseForwardRequested(); }
// this is private because it is a specialized prelude to OnStartAsync private async void InternalLaunchAsync(ILaunchActivatedEventArgs e) { // create the root frame var defaultFrame = InitializeFrame(e); // the user may override to set custom content await OnInitializeAsync(e); // okay, now handle launch switch (e.PreviousExecutionState) { case ApplicationExecutionState.NotRunning: case ApplicationExecutionState.Running: case ApplicationExecutionState.Suspended: { // launch if not restored await OnStartAsync(StartKind.Launch, e); break; } case ApplicationExecutionState.ClosedByUser: case ApplicationExecutionState.Terminated: { // restore if you need to/can do // restore if there is no TileId or if the app is luanched via the primary tile // TODO: is it actually possible to have a TileID of null? Don't think so. if (e.TileId == null || e.TileId == "App") { // In the event that the cache ahs expired, attempting to restore // from state will fail because of missing values. This is by design. var restored = NavigationService.RestoreSavedNavigation(); if (!restored) { await OnStartAsync(StartKind.Launch, e); } } else { await OnStartAsync(StartKind.Launch, e); } break; } } // ensure active (this will hide any custom splashscreen) Window.Current.Activate(); // Hook up the default Back handler global::Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested += (s, args) => { // only handle as long as there is a default backstack args.Handled = !NavigationService.CanGoBack; RaiseBackRequested(); }; // Hook up keyboard and mouse Back handler var keyboard = new Services.KeyboardService.KeyboardService(); keyboard.AfterBackGesture = () => RaiseBackRequested(); // Hook up keyboard and house Forward handler keyboard.AfterForwardGesture = () => RaiseForwardRequested(); }
private async void InternalLaunchAsync(ILaunchActivatedEventArgs e) { // first handle prelaunch, which will not continue if ((e.Kind == ActivationKind.Launch) && ((e as LaunchActivatedEventArgs)?.PrelaunchActivated ?? false)) { OnPrelaunch(); return; } // now handle normal activation UIElement splashScreen = default(UIElement); if (SplashFactory != null) { splashScreen = SplashFactory(e.SplashScreen); Window.Current.Content = splashScreen; } // setup frame var frame = new Frame { Language = global::Windows.Globalization.ApplicationLanguages.Languages[0] }; frame.Navigated += (s, args) => { global::Windows.UI.Core.SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = (ShowShellBackButton && frame.CanGoBack) ? AppViewBackButtonVisibility.Visible : AppViewBackButtonVisibility.Collapsed; }; // setup default view var view = WindowWrapper.ActiveWrappers.First(); var navigationService = new Services.NavigationService.NavigationService(frame); view.NavigationServices.Add(navigationService); // expire state (based on expiry) DateTime cacheDate; var otherwise = DateTime.MinValue.ToString(); if (DateTime.TryParse(navigationService.Frame.GetFrameState(CacheKey, otherwise), out cacheDate)) { var cacheAge = DateTime.Now.Subtract(cacheDate); if (cacheAge >= CacheMaxDuration) { // clear state in every nav service in every view foreach (var service in WindowWrapper.ActiveWrappers.SelectMany(x => x.NavigationServices)) { service.Frame.ClearFrameState(); } } } else { // no date, that's okay } // 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.ClosedByUser: case ApplicationExecutionState.Terminated: { // 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 = frame; } if (Window.Current.Content == null) { Window.Current.Content = frame; } // ensure active Window.Current.Activate(); // Hook up the default Back handler global::Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested += (s, args) => { args.Handled = true; RaiseBackRequested(); }; // Hook up keyboard and mouse Back handler var keyboard = new Services.KeyboardService.KeyboardService(); keyboard.AfterBackGesture = () => RaiseBackRequested(); // Hook up keyboard and house Forward handler keyboard.AfterForwardGesture = () => RaiseForwardRequested(); }