Пример #1
0
        // Fired from javascript when a different song starts playing
        public void songChangeEvent(string song, string album, string artist, string url)
        {
            PlaybackAPI.Instance.UpdateCurrentSong(song, artist, album, url);

            mainForm.Invoke((MethodInvoker) delegate
            {
                // Update the title to show the current song
                mainForm.Text = song + " - " + artist;
            });

            // If no desktop notifications just stop here :)
            if (!Properties.Settings.Default.DesktopNotifications)
            {
                return;
            }
            try {
                // If the alert box already exists we need to kill it
                // Trick the timer into thinking it is over
                if (alert != null)
                {
                    alert.currentStep = 99999;
                }

                // GUI tasks should be run on a GUI thread
                mainForm.Invoke((MethodInvoker)async delegate
                {
                    // Wait for the alert box to dispose of it self
                    await TaskEx.Run(delegate
                    {
                        while (alert != null)
                        {
                            ;
                        }
                    });
                    alert              = new SongAlert(song, album, artist, url);
                    alert.FormClosing += new FormClosingEventHandler(Song_Alert_Close);
                    alert.Show();
                });
            } catch
            {
                // This try catch is to prevent application crashes when a user spams the forward / back track button
                // The AsyncJSBind in CEFSharp can't handle the amount of communication and throws a NullPointer
                // TODO: Check CEF progress on this issue
            }
            try
            {
                new LastFM().updateNowPlaying(artist, song).Wait();
            } catch (Exception e)
            {
                // last.fm not authenticated
            }
        }
Пример #2
0
 // When the SongAlert closes set it to null in this scope so we know
 private void Song_Alert_Close(object sender, FormClosingEventArgs e)
 {
     // We must handle an unsafe thread disposal here so that the parent forms Dispose method does not cause cross thread errors
     // But first we have to check if the handle is created yet, if it isn't we attach to the HandleCreated event
     if (alert.IsHandleCreated)
     {
         Control.CheckForIllegalCrossThreadCalls = false;
         alert.Dispose();
         Control.CheckForIllegalCrossThreadCalls = true;
         alert = null;
     }
     else
     {
         alert.HandleCreated += (send, ev) =>
         {
             Control.CheckForIllegalCrossThreadCalls = false;
             alert.Dispose();
             Control.CheckForIllegalCrossThreadCalls = true;
             alert = null;
         };
     }
 }
        // Fired from javascript when a different song starts playing
        public void songChangeEvent(string song, string artist, string album, string url)
        {
            if (!Properties.Settings.Default.DesktopNotifications)
            {
                return;
            }
            try {
                // If the alert box already exists we need to kill it
                // Trick the timer into thinking it is over
                if (alert != null)
                {
                    alert.currentStep = 99999;
                }

                // GUI tasks should be run on a GUI thread
                mainForm.Invoke((MethodInvoker) async delegate
                {
                    // Wait for the alert box to dispose of it self
                    await TaskEx.Run(delegate
                    {
                        while (alert != null) ;
                    });
                    alert = new SongAlert(song, artist, album, url);
                    alert.FormClosing += new FormClosingEventHandler(Song_Alert_Close);
                    alert.Show();
                });
            } catch
            {
                // This try catch is to prevent application crashes when a user spams the forward / back track button
                // The AsyncJSBind in CEFSharp can't handle the amount of communication and throws a NullPointer
                // TODO: Check CEF progress on this issue
            }
        }
 // When the SongAlert closes set it to null in this scope so we know
 private void Song_Alert_Close(object sender, FormClosingEventArgs e)
 {
     // We must handle an unsafe thread disposal here so that the parent forms Dispose method does not cause cross thread errors
     // But first we have to check if the handle is created yet, if it isn't we attach to the HandleCreated event
     if (alert.IsHandleCreated)
     {
         Control.CheckForIllegalCrossThreadCalls = false;
         alert.Dispose();
         Control.CheckForIllegalCrossThreadCalls = true;
         alert = null;
     } else
     {
         alert.HandleCreated += (send, ev) =>
         {
             Control.CheckForIllegalCrossThreadCalls = false;
             alert.Dispose();
             Control.CheckForIllegalCrossThreadCalls = true;
             alert = null;
         };
     }
 }
        // Fired from javascript when a different song starts playing
        public void songChangeEvent(string song, string album, string artist, string url)
        {
            PlaybackAPI.Instance.UpdateCurrentSong(song, artist, album, url);

            mainForm.Invoke((MethodInvoker)delegate
            {
                // Update the title to show the current song
                mainForm.Text = song + " - " + artist;
            });

            // If no desktop notifications just stop here :)
            if (!Properties.Settings.Default.DesktopNotifications)
            {
                return;
            }
            try {
                // If the alert box already exists we need to kill it
                // Trick the timer into thinking it is over
                if (alert != null)
                {
                    alert.currentStep = 99999;
                }

                // GUI tasks should be run on a GUI thread
                mainForm.Invoke((MethodInvoker) async delegate
                {
                    // Wait for the alert box to dispose of it self
                    await TaskEx.Run(delegate
                    {
                        while (alert != null) ;
                    });
                    alert = new SongAlert(song, album, artist, url);
                    alert.FormClosing += new FormClosingEventHandler(Song_Alert_Close);
                    alert.Show();
                });
            } catch
            {
                // This try catch is to prevent application crashes when a user spams the forward / back track button
                // The AsyncJSBind in CEFSharp can't handle the amount of communication and throws a NullPointer
                // TODO: Check CEF progress on this issue
            }
            try
            {
                new LastFM().updateNowPlaying(artist, song).Wait();
            } catch (Exception e)
            {
                // last.fm not authenticated
            }
        }