Esempio n. 1
0
        private void CheckTitle()
        {
            Song currentSong = Spotify.GetCurrentSong();

            if (currentSong != null && currentSong.IsValid() && !currentSong.Equals(this.currentSong))
            {
                // set the previous title asap so that the next timer call to this function will
                // fail fast (setting it at the end may cause multiple web requests)
                this.currentSong = currentSong;

                try
                {
                    Spotify.SetCoverArt(currentSong);
                }
                catch
                {
                    // Exceptions will be handled (for telemetry etc.) within SetCoverArt, but they will be rethrown
                    // so that we can set custom artwork here
                    currentSong.CoverArtUrl = ALBUM_ACCESS_DENIED_ICON;
                }

                // Toastify-specific custom logic around album art (if it's missing, or an ad)
                UpdateSongForToastify(currentSong);

                toastIcon = currentSong.CoverArtUrl;

                this.Dispatcher.Invoke((Action) delegate { Title1.Text = currentSong.Track; Title2.Text = currentSong.Artist; }, System.Windows.Threading.DispatcherPriority.Normal);

                foreach (var p in this.Plugins)
                {
                    try
                    {
                        p.TrackChanged(currentSong.Artist, currentSong.Track);
                    }
                    catch (Exception)
                    {
                        //For now we swallow any plugin errors.
                    }
                }

                this.Dispatcher.Invoke((Action) delegate { FadeIn(); }, System.Windows.Threading.DispatcherPriority.Normal);

                if (SettingsXml.Current.SaveTrackToFile)
                {
                    if (!string.IsNullOrEmpty(SettingsXml.Current.SaveTrackToFilePath))
                    {
                        try
                        {
                            string trackText = GetClipboardText(currentSong);

                            File.WriteAllText(SettingsXml.Current.SaveTrackToFilePath, trackText);
                        }
                        catch { } // ignore errors writing out the album
                    }
                }
            }
        }