protected override async Task OnPreStartAsync(IActivatedEventArgs args, AppStartInfo info)
        {
            await UmengAnalytics.StartTrackAsync(UmengAppkey);

            if (RootFrame != null)
            {
                info.NavigatePage = null;
            }
        }
示例#2
0
        private async void InternalStartAsync(IActivatedEventArgs args, AppStartInfo info)
        {
            Window hostWindow = null;
            // 当前创建的窗口是否是新窗口。
            bool isNewWindow = false;

            // 当前窗口是否是应用程序初启动窗口。
            bool isMainWindow = args.PreviousExecutionState == ApplicationExecutionState.NotRunning || args.PreviousExecutionState == ApplicationExecutionState.Terminated || args.PreviousExecutionState == ApplicationExecutionState.ClosedByUser;

            if (info.IsShowInNewWindow == false)
            {
                // 不需要创建新窗口。
                hostWindow = Window.Current;
            }
            else
            {
                if (isMainWindow)
                {
                    // 当前窗口是应用程序初启动窗口。
                    hostWindow = Window.Current;
                }
                else
                {
                    hostWindow = await CreateNewWindowAsync();

                    isNewWindow = true;
                }
            }

            await ShowExtendedSplashScreenAsync(hostWindow, isNewWindow, args, info);

            await InitializeRootFrameAsync(hostWindow);

            await NavigateToFirstPageAsync(hostWindow, info.NavigatePage, info.Parameter);

            await hostWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                // 确保激活窗口。
                hostWindow.Activate();
            });
        }
        protected override async Task OnPreStartAsync(IActivatedEventArgs args, AppStartInfo info)
        {
            await UmengAnalytics.StartTrackAsync(UmengAppKey);

            if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar"))
            {
                await StatusBar.GetForCurrentView().HideAsync();
            }

            if (RootFrame != null)
            {
                info.NavigatePage = null;
            }

#if DEBUG
            DispatcherTimer timer = new DispatcherTimer();
            timer.Tick += delegate
            {
                var rect = Window.Current.Bounds;
                Debug.WriteLine(rect.Width + ":" + (rect.Height + 32));
            };
            timer.Start();
#endif
        }
 protected virtual Task OnFileSavePickerStartAsync(FileSavePickerActivatedEventArgs args, AppStartInfo info)
 {
     return Task.FromResult<object>(null);
 }
 protected virtual Task OnFileTypeAssociationStartAsync(FileActivatedEventArgs args, AppStartInfo info)
 {
     return Task.FromResult<object>(null);
 }
 protected override async Task OnPreStartAsync(IActivatedEventArgs args, AppStartInfo info)
 {
     await SetTitleBar();
 }
 protected virtual Task OnCachedFileUpdaterStartAsync(CachedFileUpdaterActivatedEventArgs args, AppStartInfo info)
 {
     return Task.FromResult<object>(null);
 }
示例#8
0
 /// <summary>
 /// 通过其它未列出的方式启动、激活时,使用此方法作为入口。
 /// </summary>
 /// <param name="args">事件的事件数据。</param>
 /// <param name="info"></param>
 /// <returns></returns>
 protected virtual Task OnOtherStartAsync(IActivatedEventArgs args, AppStartInfo info)
 {
     return(Task.FromResult <object>(null));
 }
示例#9
0
 /// <summary>
 /// 通过保存文件对话框激活应用程序时使用此方法作为入口。
 /// </summary>
 /// <param name="args">事件的事件数据。</param>
 /// <param name="info"></param>
 /// <returns></returns>
 protected virtual Task OnFileSavePickerStartAsync(FileSavePickerActivatedEventArgs args, AppStartInfo info)
 {
     return(Task.FromResult <object>(null));
 }
示例#10
0
        private static async Task ShowExtendedSplashScreenAsync(Window hostWindow, bool isNewWindow, IActivatedEventArgs args, AppStartInfo info)
        {
            // 窗口中是否已经有内容。
            if (await GetIsWindowExistContentAsync(hostWindow))
            {
                return;
            }

            var temp = await CreateExtendedSplashScreenContentAsync(hostWindow, info);

            // 扩展屏幕内容。
            ExtendedSplashScreenContent extendedSplashScreenContent = temp.Item1;

            // 扩展启动屏幕结束回调信号。
            TaskCompletionSource <object> extendedSplashScreenTcs = temp.Item2;

            // 窗口内容。
            UIElement hostWindowContent = null;

            if (extendedSplashScreenContent != null)
            {
                // 如果扩展屏幕窗口内容不为 null,则创建扩展启动屏幕容器并赋值到 hostWindowContent 变量。
                hostWindowContent = await BuildExtendedSplashScreenAsync(hostWindow, extendedSplashScreenContent, args);
            }

            if (hostWindowContent == null && isNewWindow)
            {
                // 对于新窗口,必须确保存在内容。
                await hostWindowContent.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    hostWindowContent = new ContentControl();
                });
            }

            await ShowWindowContentAsync(hostWindow, hostWindowContent);

            if (isNewWindow)
            {
                // 切换到新窗口。
                await SwitchToWindowAsync(hostWindow);
            }

            // 使用了扩展启动屏幕。
            if (extendedSplashScreenTcs != null)
            {
                // 等待回调信号。
                await extendedSplashScreenTcs.Task;
            }

            // 清除窗口内容,准备导航操作。
            await hostWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                SetContent(hostWindow, null);
            });
        }
 protected virtual Task OnToastStartAsync(LaunchActivatedEventArgs args, AppStartInfo info)
 {
     return Task.FromResult<object>(null);
 }
示例#12
0
 protected virtual Task OnVoiceCommandStartAsync(VoiceCommandActivatedEventArgs voiceCommandArgs, AppStartInfo info)
 {
     return(Task.FromResult <object>(null));
 }
示例#13
0
        private static async Task <Tuple <ExtendedSplashScreenContent, TaskCompletionSource <object> > > CreateExtendedSplashScreenContentAsync(Window hostWindow, AppStartInfo info)
        {
            // 创建创建扩展启动屏幕方法为 null。
            if (info.ExtendedSplashScreen == null)
            {
                return(Tuple.Create <ExtendedSplashScreenContent, TaskCompletionSource <object> >(null, null));
            }

            ExtendedSplashScreenContent   extendedSplashScreenContent = null;
            TaskCompletionSource <object> extendedSplashScreenTcs     = null;
            await hostWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                extendedSplashScreenContent = info.ExtendedSplashScreen();
                if (extendedSplashScreenContent != null)
                {
                    extendedSplashScreenTcs = new TaskCompletionSource <object>();

                    EventHandler extendedSplashScreenFinishedHandler = null;
                    extendedSplashScreenFinishedHandler = delegate
                    {
                        extendedSplashScreenContent.Finished -= extendedSplashScreenFinishedHandler;
                        extendedSplashScreenTcs.SetResult(null);
                    };
                    extendedSplashScreenContent.Finished += extendedSplashScreenFinishedHandler;
                }
            });

            return(Tuple.Create <ExtendedSplashScreenContent, TaskCompletionSource <object> >(extendedSplashScreenContent, extendedSplashScreenTcs));
        }
示例#14
0
 /// <summary>
 /// 应用程序通过吐司通知启动时使用此方法作为入口。
 /// </summary>
 /// <param name="args">事件的事件数据。</param>
 /// <param name="info"></param>
 /// <returns></returns>
 protected virtual Task OnToastStartAsync(LaunchActivatedEventArgs args, AppStartInfo info)
 {
     return(Task.FromResult <object>(null));
 }
示例#15
0
 /// <summary>
 /// 作为系统共享目标时使用此方法作为入口。
 /// </summary>
 /// <param name="args">事件的事件数据。</param>
 /// <param name="info"></param>
 /// <returns></returns>
 protected virtual Task OnShareTargetStartAsync(ShareTargetActivatedEventArgs args, AppStartInfo info)
 {
     return(Task.FromResult <object>(null));
 }
示例#16
0
 /// <summary>
 /// 应用程序通过关联协议激活时使用此方法作为入口。
 /// </summary>
 /// <param name="protocolArgs">事件的事件数据。</param>
 /// <param name="info"></param>
 /// <returns></returns>
 protected virtual Task OnProtocolStartAsync(ProtocolActivatedEventArgs protocolArgs, AppStartInfo info)
 {
     return(Task.FromResult <object>(null));
 }
 protected virtual Task OnOtherStartAsync(IActivatedEventArgs args, AppStartInfo info)
 {
     return Task.FromResult<object>(null);
 }
 private void NavigateToFirstPage(IActivatedEventArgs args, AppStartInfo info)
 {
     if (RootFrame.Content == null)
     {
         RootFrame.Navigate(info.MainPage, info.Parameter);
     }
 }
 protected virtual Task OnShareTargetStartAsync(ShareTargetActivatedEventArgs args, AppStartInfo info)
 {
     return Task.FromResult<object>(null);
 }
示例#20
0
 /// <summary>
 /// 应用程序作为缓存文件更新器时激活使用此方法作为入口。
 /// </summary>
 /// <param name="args">事件的事件数据。</param>
 /// <param name="info"></param>
 /// <returns></returns>
 protected virtual Task OnCacheFileUpdaterStartAsync(CachedFileUpdaterActivatedEventArgs args, AppStartInfo info)
 {
     return(Task.FromResult <object>(null));
 }
        private async void InternalStartAsync(IActivatedEventArgs args, AppStartInfo info)
        {
            await this.ShowExtendedSplashScreenAsync(args, info);

            this.InitializeRootFrame(args);

            this.NavigateToFirstPage(args, info);

            Window.Current.Activate();
        }
示例#22
0
 /// <summary>
 /// 应用程序关联文件协议,打开文件激活时使用此方法作为入口。
 /// </summary>
 /// <param name="args">事件的事件数据。</param>
 /// <param name="info"></param>
 /// <returns></returns>
 protected virtual Task OnFileTypeAssociationStartAsync(FileActivatedEventArgs args, AppStartInfo info)
 {
     return(Task.FromResult <object>(null));
 }
        private async Task ShowExtendedSplashScreenAsync(IActivatedEventArgs args, AppStartInfo info)
        {
            TaskCompletionSource<object> extendedSplashScreenTcs = null;

            // App 已运行则不显示扩展启动屏幕。
            if (args.PreviousExecutionState != ApplicationExecutionState.Running)
            {
                ExtendedSplashScreenContent extendedSplashScreenContent = info?.ExtendedSplashScreen();

                if (extendedSplashScreenContent != null)
                {
                    #region 扩展启动屏幕结束,设置回调信号。

                    extendedSplashScreenTcs = new TaskCompletionSource<object>();
                    extendedSplashScreenContent.Finished += (sender, e) =>
                    {
                        extendedSplashScreenTcs.SetResult(null);
                    };

                    #endregion 扩展启动屏幕结束,设置回调信号。

                    ExtendedSplashScreen extendedSplashScreen = await ExtendedSplashScreen.CreateAsync(args.SplashScreen, extendedSplashScreenContent);
                    Window.Current.Content = extendedSplashScreen;
                    Window.Current.Activate();

                    // 等待回调信号。
                    await extendedSplashScreenTcs.Task;
                }
            }
        }
示例#24
0
        protected override sealed async void OnActivated(IActivatedEventArgs args)
        {
            await this.HandleWaitForConstructedActionsAsync();

            AppStartInfo info = AppStartInfo.Default;

            await this.OnPreStartAsync(args, info);

            #region 所有激活类型

            switch (args.Kind)
            {
            case ActivationKind.Launch:
            case ActivationKind.Search:
            case ActivationKind.ShareTarget:
            case ActivationKind.File:
                goto default;

            case ActivationKind.Protocol:
                ProtocolActivatedEventArgs protocolArgs = (ProtocolActivatedEventArgs)args;
                await this.OnProtocolStartAsync(protocolArgs, info);

                break;

            case ActivationKind.FileOpenPicker:
            case ActivationKind.FileSavePicker:
            case ActivationKind.CachedFileUpdater:
            case ActivationKind.ContactPicker:
            case ActivationKind.Device:
            case ActivationKind.PrintTaskSettings:
            case ActivationKind.CameraSettings:
            case ActivationKind.RestrictedLaunch:
            case ActivationKind.AppointmentsProvider:
            case ActivationKind.Contact:
            case ActivationKind.LockScreenCall:
                goto default;

            case ActivationKind.VoiceCommand:
                VoiceCommandActivatedEventArgs voiceCommandArgs = (VoiceCommandActivatedEventArgs)args;
                await this.OnVoiceCommandStartAsync(voiceCommandArgs, info);

                break;

            case ActivationKind.LockScreen:
            case ActivationKind.PickerReturned:
            case ActivationKind.WalletAction:
            case ActivationKind.PickFileContinuation:
            case ActivationKind.PickSaveFileContinuation:
            case ActivationKind.PickFolderContinuation:
            case ActivationKind.WebAuthenticationBrokerContinuation:
            case ActivationKind.WebAccountProvider:
            case ActivationKind.ComponentUI:
            case ActivationKind.ProtocolForResults:
            case ActivationKind.ToastNotification:
            case ActivationKind.DialReceiver:
            default:
                await this.OnOtherStartAsync(args, info);

                break;
            }

            #endregion 所有激活类型

            this.InternalStartAsync(args, info);
        }