Example #1
0
        // The authentication loop method
        private async void Startup(bool afterLogOut = false)
        {
            // If we're here because the user just launched the application and hasn't authorized the application
            if (!afterLogOut)
            {
                // Set the appropriate status on the (hidden) status bar
                SetStatus(LocalizationStrings.NotificationThread_Status_StartingUp);

                // Initialize the application
                List <Exception> pathExceptions = Core.InitializeApplication();

                if (pathExceptions != null && pathExceptions.Any())
                {
                    foreach (Exception ex in pathExceptions)
                    {
                        Logger.FileLogger.Write(_logPathAndFilename, "Scrobble Ui", $"Unexpected Exception during application start: {ex.Message}");
                    }
                }

                // Hide this user interface
                if (Core.Settings.StartMinimized)
                {
                    this.WindowState = FormWindowState.Minimized;
                }

                // Set the appropriate status on the (hidden) status bar
                SetStatus(LocalizationStrings.ScrobblerUi_Status_LoadingPlugins);

                // Get the available external scrobble plugins
                await GetPlugins().ConfigureAwait(false);
            }
            else
            {
                // Remove the online status tracking delegate
                ScrobbleFactory.OnlineStatusUpdated -= OnlineStatusUpdated;
            }

            // Set the appropriate status on the (hidden) status bar
            SetStatus(LocalizationStrings.ScrobblerUi_Status_ConnectingToLastfm);

            // Use the Last.fm API client to check the status of authorization
            await ConnectToLastFM(afterLogOut).ConfigureAwait(false);

            // Initialize the Scrobbling handler (only gets here when the client is authorized)
            await ScrobbleFactory.Initialize(base.APIClient, this, _logPathAndFilename).ConfigureAwait(false);

            // Make sure we have a default status available for all the loaded plugins
            ApplicationConfiguration.CheckPluginDefaultStatus();

            // If we got here because the application is starting
            if (!afterLogOut)
            {
                // Update the user interface to show the current settings
                DisplaySettings();
            }

            // Enable scrobbling only if there are any plugins enabled
            ScrobbleFactory.ScrobblingEnabled = Core.Settings.ScrobblerStatus.Count(plugin => plugin.IsEnabled) > 0;

            // Assign a delegate to update the Ui when the user goes on/offline with the Last.fm API
            ScrobbleFactory.OnlineStatusUpdated += OnlineStatusUpdated;
        }