Exemple #1
0
        private async Task PerformAsyncWork(string path)
        {
            LoggingService.Log(LoggingService.LogType.Debug, "Page loaded, performing async work");

            // Set the app language
            ApplicationLanguages.PrimaryLanguageOverride =
                string.IsNullOrEmpty(SettingsService.Instance.CurrentAppLanguage)
                    ? ApplicationLanguages.Languages[0]
                    : SettingsService.Instance.CurrentAppLanguage;

            SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested;

            // Navigate to the first page
            await HandleProtocolAsync(path);

            // Run on the background thread
            await Task.Run(async() =>
            {
                // We have not yet run the online init
                if (!App.OnlineAppInitComplete)
                {
                    // Update the keys anyway to ensure we have the latest.
                    await UWPAuthorizationHelpers.OnlineAppInitAsync(true);
                }

                // Test Version and tell user app upgraded
                await HandleNewAppVersionAsync();

                // Clear the unread badge
                BadgeUpdateManager.CreateBadgeUpdaterForApplication().Clear();

                // Get the store and check for app updates
                var updates = await StoreContext.GetDefault().GetAppAndOptionalStorePackageUpdatesAsync();

                // If we have updates navigate to the update page where we
                // ask the user if they would like to update or not (depending
                // if the update is mandatory or not).
                if (updates.Count > 0)
                {
                    await NavigationService.Current.CallDialogAsync <PendingUpdateDialog>();
                }

                // Load logged in user objects
                await SoundByteService.Current.InitUsersAsync();

                App.Telemetry.TrackEvent("Connected Accounts", new Dictionary <string, string>
                {
                    { "IsSoundByteConnected", SoundByteService.Current.IsServiceConnected(ServiceType.SoundByte).ToString() },
                    { "IsSoundCloudConnected", SoundByteService.Current.IsServiceConnected(ServiceType.SoundCloud).ToString() },
                    { "IsFanburstConnected", SoundByteService.Current.IsServiceConnected(ServiceType.Fanburst).ToString() },
                    { "IsYouTubeConnected", SoundByteService.Current.IsServiceConnected(ServiceType.YouTube).ToString() }
                });

                // Register notifications
                //  var engagementManager = StoreServicesEngagementManager.GetDefault();
                //   await engagementManager.RegisterNotificationChannelAsync();
                // TODO: NUGET FILE TOO LONG


                try
                {
                    // Install Cortana Voice Commands
                    var vcdStorageFile = await Package.Current.InstalledLocation.GetFileAsync(@"SoundByteCommands.xml");
                    await VoiceCommandDefinitionManager.InstallCommandDefinitionsFromStorageFileAsync(vcdStorageFile);
                }
                catch
                {
                    // Ignore
                }
            });
        }
Exemple #2
0
        /// <summary>
        ///     Creates the window and performs any protocol logic needed
        /// </summary>
        /// <param name="parameters">Param string, (soundbyte://core/user?id=454345)</param>
        /// <returns></returns>
        private async Task InitializeShellAsync(string parameters = null)
        {
            LoggingService.Log(LoggingService.LogType.Debug, "Initialize Main App Shell...");

            _isInit = true;

            // Live tile helpers
            TileHelper.Init();

            // Before we init the v3 service, we must check to see if we have the required API keys
            if (!AppKeysHelper.KeysValid)
            {
                LoggingService.Log(LoggingService.LogType.Info, "App keys are not valid. Requesting new keys.");

                // If this fails getting the keys, we have an issue and must close the app
                if (!await UWPAuthorizationHelpers.OnlineAppInitAsync(true))
                {
                    return;
                }

                OnlineAppInitComplete = true;
            }

            // Init service
            InitV3Service();

            // Init the telemetry service
            await Telemetry.InitAsync(AppKeysHelper.GoogleAnalyticsTrackerId, AppKeysHelper.HockeyAppClientId,
                                      AppKeysHelper.AppCenterClientId);

            // Get the main shell
            var shell = Window.Current.Content as AppShell;

            // If the shell is null, we need to set it up.
            if (shell == null)
            {
                LoggingService.Log(LoggingService.LogType.Debug, "Shell does not exist, creating new shell");
                shell = new AppShell(parameters);

                // Hook the key pressed event for the global app
                Window.Current.CoreWindow.KeyDown += CoreWindowOnKeyDown;
                Window.Current.CoreWindow.KeyUp   += (s, e) =>
                {
                    if (e.VirtualKey == VirtualKey.Control)
                    {
                        _isCtrlKeyPressed = false;
                    }
                };
            }
            else
            {
                LoggingService.Log(LoggingService.LogType.Debug, "Shell exists, running protocol logic");
                await shell.HandleProtocolAsync(parameters);
            }

            // Set the root shell as the window content
            Window.Current.Content = shell;

            // If on xbox display the screen to the full width and height
            if (DeviceHelper.IsXbox)
            {
                ApplicationView.GetForCurrentView().SetDesiredBoundsMode(ApplicationViewBoundsMode.UseCoreWindow);
            }

            // Activate the window
            LoggingService.Log(LoggingService.LogType.Debug, "Activiating Window");
            Window.Current.Activate();
        }