Exemplo n.º 1
0
        private async void loadApplication()
        {
            var loadingTask = Task.Run(async() =>
            {
                var client = Client.Current;
                if (client.NeedLogOn)
                {
                    try
                    {
                        var pass = AccountManager.CurrentCredential;
                        if (pass != null)
                        {
                            pass.RetrievePassword();
                            await client.LogOnAsync(pass.UserName, pass.Password, null);
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
                if (!client.NeedLogOn)
                {
                    SettingCollection.Current.Apply();
                    client.ResetExCookie();
                    var initSearchTask = SearchVM.InitAsync();
                    var waitTime       = 0;
                    while (waitTime < 7000)
                    {
                        await Task.Delay(250);
                        waitTime += 250;
                        if (initSearchTask.Status != Windows.Foundation.AsyncStatus.Started)
                        {
                            initSearchTask.Close();
                            break;
                        }
                    }
                }
                ExClient.HentaiVerse.HentaiVerseInfo.MonsterEncountered += (s, e) =>
                {
                    if (SettingCollection.Current.OpenHVOnMonsterEncountered)
                    {
                        Opportunity.MvvmUniverse.DispatcherHelper.BeginInvokeOnUIThread(async() =>
                        {
                            await Windows.System.Launcher.LaunchUriAsync(e.Uri);
                        });
                    }
                };
            });
            await Dispatcher.YieldIdle();

            this.rootControl = new RootControl();
            FindName(nameof(this.ccHided));
            this.ccHided.Content = this.rootControl;
            await loadingTask;

            if (Client.Current.NeedLogOn)
            {
                await RootControl.RootController.RequestLogOn();
            }
            if (this.effectLoaded)
            {
                setLoadingFinished();
            }
            else
            {
                this.applicationLoaded = true;
            }
        }