Exemplo n.º 1
0
        /// <summary>
        /// Override this method only if you (the developer) wants to programmatically
        /// control the means by which and when the Core Window is activated by Template 10.
        /// One scenario might be a delayed activation for Splash Screen.
        /// </summary>
        /// <param name="source">Reason for the call from Template 10</param>
        public void ActivateWindow(ActivateWindowSources source, SplashLogic splashLogic)
        {
            if (source != ActivateWindowSources.SplashScreen)
            {
                splashLogic.Hide();
            }

            Window.Current.Activate();
        }
Exemplo n.º 2
0
            /// <summary>
            /// Override this method only if you (the developer) wants to programmatically
            /// control the means by which and when the Core Window is activated by Template 10.
            /// One scenario might be a delayed activation for Splash Screen.
            /// </summary>
            /// <param name="source">Reason for the call from Template 10</param>
            public void ActivateWindow(ActivateWindowSources source, SplashLogic splashLogic)
            {
                DebugWrite($"source:{source}");

                if (source != ActivateWindowSources.SplashScreen)
                {
                    splashLogic.Hide();
                }

                Window.Current.Activate();
            }
Exemplo n.º 3
0
        private async void StartupOrchestratorAsync(IActivatedEventArgs e, StartKind kind)
        {
            DebugWrite($"kind:{kind} previous:{e.PreviousExecutionState}");

            if (OriginalActivatedArgs == null)
            {
                OriginalActivatedArgs = e;

                // if resume tries to launch, don't continue on
                // StartupOrchestratorAsync will be called twice
                if (OriginalActivatedArgs == null)
                {
                    OnResuming(this, null, AppExecutionState.Terminated);
                    return;
                }
            }

            // is the kind really right?
            if (kind == StartKind.Launch && CurrentStateHistory.ContainsValue(BootstrapperStates.Launched))
            {
                kind = StartKind.Activate;
            }
            else if (kind == StartKind.Launch && e.PreviousExecutionState == ApplicationExecutionState.Running)
            {
                kind = StartKind.Activate;
            }
            else if (kind == StartKind.Activate && e.PreviousExecutionState != ApplicationExecutionState.Running)
            {
                kind = StartKind.Launch;
            }

            // handle activate
            if (kind == StartKind.Activate)
            {
                // never activate until launch has completed
                while (!CurrentStateHistory.ContainsValue(BootstrapperStates.Launched))
                {
                    await Task.Delay(10);
                }
                await OnStartAsync(kind, e);

                CurrentState = BootstrapperStates.Started;

                WindowLogic.ActivateWindow(ActivateWindowSources.Activating, SplashLogic);
                CurrentState = BootstrapperStates.Activated;
            }

            // handle first-time launch
            else if (kind == StartKind.Launch)
            {
                SplashLogic.Show(e.SplashScreen, this);

                // do some one-time things
                SetupKeyboardListeners();
                SetupLifecycleListeners();
                SetupSystemListeners();
                SetupCustomTitleBar();

                // default Unspecified extended session
                await ExtendedSessionService.StartAsync();

                // OnInitializeAsync
                await OnInitializeAsync(e);

                CurrentState = BootstrapperStates.Initialized;

                // if there no pre-existing root then generate root
                if (SplashLogic.Splashing || Window.Current.Content == null)
                {
                    Window.Current.Content = CreateRootElement(e);
                }

                // okay, now handle launch
                bool restored    = false;
                var  IsPrelaunch = (e as LaunchActivatedEventArgs)?.PrelaunchActivated ?? false;
                switch (e.PreviousExecutionState)
                {
                case ApplicationExecutionState.Suspended:
                case ApplicationExecutionState.Terminated:
                    OnResuming(this, null, IsPrelaunch ? AppExecutionState.Prelaunch : AppExecutionState.Terminated);
                    if (AutoRestoreAfterTerminated)
                    {
                        restored = await LifecycleLogic.AutoRestoreAsync(e as ILaunchActivatedEventArgs, NavigationService);

                        CurrentState = BootstrapperStates.Restored;
                    }
                    break;
                }

                // handle if pre-launch (no UI)
                if (IsPrelaunch)
                {
                    var runOnStartAsync = false;
                    await OnPrelaunchAsync(e, out runOnStartAsync);

                    CurrentState = BootstrapperStates.Prelaunched;
                    if (!runOnStartAsync)
                    {
                        return;
                    }
                }

                // handle if not restored (new launch)
                if (!restored)
                {
                    await OnStartAsync(StartKind.Launch, e);

                    CurrentState = BootstrapperStates.Started;
                }

                // this will also hide any showing splashscreen
                WindowLogic.ActivateWindow(ActivateWindowSources.Launching, SplashLogic);
                CurrentState = BootstrapperStates.Launched;
            }
        }
Exemplo n.º 4
0
        private async void StartupOrchestratorAsync(IActivatedEventArgs e, StartKind kind)
        {
            DebugWrite($"kind:{kind} previous:{e.PreviousExecutionState}");

            // check if this is the first activation at all, when we can save PreviousExecutionState and PrelaunchActivated
            if (!_firstActivationExecuted)
            {
                _firstActivationExecuted = true;
                PreviousExecutionState   = e.PreviousExecutionState;
                PrelaunchActivated       = (e as LaunchActivatedEventArgs)?.PrelaunchActivated ?? false;
            }

            // is the kind really right?
            if (kind == StartKind.Launch && CurrentStateHistory.ContainsValue(BootstrapperStates.Launching))
            {
                kind = StartKind.Activate;
            }
            else if (kind == StartKind.Launch && e.PreviousExecutionState == ApplicationExecutionState.Running)
            {
                kind = StartKind.Activate;
            }
            else if (kind == StartKind.Activate && e.PreviousExecutionState != ApplicationExecutionState.Running)
            {
                kind = StartKind.Launch;
            }

            // handle activate
            if (kind == StartKind.Activate)
            {
                CurrentState = BootstrapperStates.Activating;

                // never activate until launch has completed
                while (!CurrentStateHistory.ContainsValue(BootstrapperStates.Launched))
                {
                    await Task.Delay(10);
                }

                while (CurrentStateHistory.Count(x => x.Value == BootstrapperStates.Starting) != CurrentStateHistory.Count(x => x.Value == BootstrapperStates.Started))
                {
                    await Task.Delay(10);
                }

                CurrentState = BootstrapperStates.Starting;

                await OnStartAsync(kind, e);

                CurrentState = BootstrapperStates.Started;

                WindowLogic.ActivateWindow(ActivateWindowSources.Activating, SplashLogic);

                CurrentState = BootstrapperStates.Activated;
            }

            // handle first-time launch
            else if (kind == StartKind.Launch)
            {
                CurrentState = BootstrapperStates.Launching;

                SplashLogic.Show(e.SplashScreen, this);

                // do some one-time things
                SetupKeyboardListeners();
                SetupLifecycleListeners();
                SetupSystemListeners();
                SetupCustomTitleBar();

                // default Unspecified extended session
                if (AutoExtendExecutionSession)
                {
                    await ExtendedSessionService.StartUnspecifiedAsync();
                }

                CurrentState = BootstrapperStates.Initializing;

                // OnInitializeAsync
                await OnInitializeAsync(e);

                CurrentState = BootstrapperStates.Initialized;

                // if there no pre-existing root then generate root
                if (SplashLogic.Splashing || Window.Current.Content == null)
                {
                    Window.Current.Content = CreateRootElement(e);
                }

                // okay, now handle launch
                bool restored    = false;
                var  IsPrelaunch = (e as LaunchActivatedEventArgs)?.PrelaunchActivated ?? false;
                switch (e.PreviousExecutionState)
                {
                case ApplicationExecutionState.Suspended:
                case ApplicationExecutionState.Terminated:
                    OnResuming(this, null, IsPrelaunch ? AppExecutionState.Prelaunch : AppExecutionState.Terminated);
                    var launchedEventArgs = e as ILaunchActivatedEventArgs;
                    if (AutoRestoreAfterTerminated &&
                        DetermineStartCause(e) == AdditionalKinds.Primary || launchedEventArgs?.TileId == string.Empty)
                    {
                        CurrentState = BootstrapperStates.Restoring;

                        restored = await NavigationService.LoadAsync();

                        CurrentState = BootstrapperStates.Restored;
                    }
                    break;
                }

                // handle if pre-launch (no UI)
                if (IsPrelaunch)
                {
                    CurrentState = BootstrapperStates.Prelaunching;

                    var runOnStartAsync = false;
                    await OnPrelaunchAsync(e, out runOnStartAsync);

                    CurrentState = BootstrapperStates.Prelaunched;

                    if (!runOnStartAsync)
                    {
                        return;
                    }
                }

                // handle if not restored (new launch)
                if (!restored)
                {
                    CurrentState = BootstrapperStates.Starting;

                    await OnStartAsync(StartKind.Launch, e);

                    CurrentState = BootstrapperStates.Started;
                }

                // this will also hide any showing splashscreen
                WindowLogic.ActivateWindow(ActivateWindowSources.Launching, SplashLogic);

                CurrentState = BootstrapperStates.Launched;
            }
        }