Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
Fix issue with Toastify waiting indefinitely for Spotify [Premium] (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleab committed Sep 19, 2018
1 parent 07c4299 commit 77c9d22
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
15 changes: 7 additions & 8 deletions Toastify/src/Core/Spotify.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Sockets;
Expand Down Expand Up @@ -942,19 +943,17 @@ private async void SpotifyWindow_InitializationFinished(object sender, EventArgs

// Fake the Connected event
string currentTitle = this.spotifyWindow.Title;
SpotifyStateEventArgs spotifyStateEventArgs = null;
SpotifyStateEventArgs spotifyStateEventArgs;

if (string.Equals(currentTitle, SpotifyWindow.PausedTitle, StringComparison.InvariantCulture))
if (SpotifyWindow.PausedTitles.Contains(currentTitle, StringComparer.InvariantCulture))
spotifyStateEventArgs = new SpotifyStateEventArgs(null, false, 1.0, 1.0);
else
{
Song newSong = Song.FromSpotifyWindowTitle(currentTitle);
if (newSong != null)
spotifyStateEventArgs = new SpotifyStateEventArgs(newSong, true, 1.0, 1.0);
spotifyStateEventArgs = new SpotifyStateEventArgs(newSong, true, 1.0, 1.0);
}

if (spotifyStateEventArgs != null)
await this.OnSpotifyConnected(spotifyStateEventArgs).ConfigureAwait(false);
await this.OnSpotifyConnected(spotifyStateEventArgs).ConfigureAwait(false);
}
else
{
Expand All @@ -978,12 +977,12 @@ private async void SpotifyWindowTitleWatcher_TitleChanged(object sender, WindowT
try
{
bool updateSong = true;
if (string.Equals(e.NewTitle, SpotifyWindow.PausedTitle, StringComparison.InvariantCulture))
if (SpotifyWindow.PausedTitles.Contains(e.NewTitle, StringComparer.InvariantCulture))
{
this.SpotifyLocalAPI_OnPlayStateChange(this, new PlayStateEventArgs { Playing = false });
updateSong = false;
}
else if (string.Equals(e.OldTitle, SpotifyWindow.PausedTitle, StringComparison.InvariantCulture))
else if (SpotifyWindow.PausedTitles.Contains(e.OldTitle, StringComparer.InvariantCulture))
this.SpotifyLocalAPI_OnPlayStateChange(this, new PlayStateEventArgs { Playing = true });

if (updateSong)
Expand Down
4 changes: 3 additions & 1 deletion Toastify/src/Core/SpotifyWindow.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -17,7 +18,8 @@ public class SpotifyWindow

#region Static Fields and Properties

public static string PausedTitle { get; } = "Spotify";
public static IReadOnlyList<string> PausedTitles { get; } = new List<string> { "Spotify", "Spotify Premium" };

private static int GetWindowHandleTimeout { get; } = 2000;

#endregion
Expand Down

0 comments on commit 77c9d22

Please sign in to comment.