Exemple #1
0
        public async Task <bool> Activate(Query query)
        {
            var queryParts = query.RawQuery.Split(new[] { ' ' }, 2);

            var shouldActivate = queryParts.Length > 0 && _keywords.Contains(queryParts[0]);

            switch (shouldActivate)
            {
            case false:
                return(false);

            case true when !_isAuthenticated:
            {
                var tokens = await _authManager.Authenticate();

                if (tokens?.access_token != null && tokens.refresh_token != null)
                {
                    _spotifyClient.InitializeClientWithTokens(tokens);
                    _isAuthenticated = true;
                }

                break;
            }
            }

            return(_isAuthenticated);
        }
Exemple #2
0
        public bool TryLoad()
        {
            var settings = AppSettings.GetAsOrDefault <SpotifyPluginSettings>("spotify", null);

            if (settings?.RefreshToken == null)
            {
                var tokens = _authManager.Authenticate();
                _spotifyClient.InitializeClientWithTokens(tokens);
            }
            return(true);
        }