From c7e196e07f4113bd1d645e05fce6157a89b5e2f4 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 6 Mar 2018 16:38:51 -0600 Subject: [PATCH 1/3] Changing Class Name --- Toastify/Spotify.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Toastify/Spotify.cs b/Toastify/Spotify.cs index 9b911d8a..68bebbbd 100644 --- a/Toastify/Spotify.cs +++ b/Toastify/Spotify.cs @@ -318,7 +318,7 @@ public static void KillSpotify() private static IntPtr GetSpotify() { - var windowClassName = "SpotifyMainWindow"; + var windowClassName = "Chrome_WidgetWin_0"; return Win32.FindWindow(windowClassName, null); } From c423842903272607573abe611af921337b4224ac Mon Sep 17 00:00:00 2001 From: root Date: Wed, 7 Mar 2018 12:54:00 -0600 Subject: [PATCH 2/3] changing how spotify is found --- Toastify/Spotify.cs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/Toastify/Spotify.cs b/Toastify/Spotify.cs index 68bebbbd..293e7a5c 100644 --- a/Toastify/Spotify.cs +++ b/Toastify/Spotify.cs @@ -9,11 +9,16 @@ using System.Reflection; using System.Net; using Newtonsoft.Json; +using System.Diagnostics; namespace Toastify { internal class Win32 { + + [DllImport("user32.dll", SetLastError = true)] + internal static extern IntPtr FindWindowEx(IntPtr hWndParent, IntPtr hWndChildAfter, string lpClassName, string lpWindowName); + [DllImport("user32.dll", SetLastError = true)] internal static extern IntPtr FindWindow(string lpClassName, string lpWindowName); @@ -21,10 +26,10 @@ internal class Win32 [DllImport("user32.dll")] internal static extern bool EnumWindows(EnumWindowsProc enumProc, IntPtr lParam); - + [DllImport("user32.dll")] internal static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId); - + [DllImport("user32.dll", CharSet = CharSet.Auto)] internal static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam); @@ -318,9 +323,16 @@ public static void KillSpotify() private static IntPtr GetSpotify() { - var windowClassName = "Chrome_WidgetWin_0"; + var procs = System.Diagnostics.Process.GetProcessesByName("Spotify"); - return Win32.FindWindow(windowClassName, null); + foreach (var proc in procs) + { + if (proc.MainWindowHandle != IntPtr.Zero) + { + return proc.MainWindowHandle; + } + } + return IntPtr.Zero; } public static bool IsRunning() @@ -429,7 +441,7 @@ public static void SetCoverArt(Song song) if (response != null) { - Telemetry.TrackEvent(TelemetryCategory.SpotifyWebService, Telemetry.TelemetryEvent.SpotifyWebService.NetworkError, + Telemetry.TrackEvent(TelemetryCategory.SpotifyWebService, Telemetry.TelemetryEvent.SpotifyWebService.NetworkError, "URL: " + spotifyTrackSearchURL + " \nError Code: " + response.StatusCode + " Dump: " + e.ToString()); } else @@ -448,7 +460,7 @@ public static void SetCoverArt(Song song) jsonResponse.Substring(0, jsonResponse.Length > 100 ? 100 : jsonResponse.Length)); - Telemetry.TrackEvent(TelemetryCategory.SpotifyWebService, Telemetry.TelemetryEvent.SpotifyWebService.ResponseError, "URL: " + spotifyTrackSearchURL + " \nType: " + e.GetType().Name + " JSON excerpt: " + jsonSubstring +" dump: " + e.ToString()); + Telemetry.TrackEvent(TelemetryCategory.SpotifyWebService, Telemetry.TelemetryEvent.SpotifyWebService.ResponseError, "URL: " + spotifyTrackSearchURL + " \nType: " + e.GetType().Name + " JSON excerpt: " + jsonSubstring + " dump: " + e.ToString()); throw; } From 4d2804737eacf1fbca438df30d3b559ff070f9ec Mon Sep 17 00:00:00 2001 From: root Date: Wed, 7 Mar 2018 12:57:30 -0600 Subject: [PATCH 3/3] removing unneeded code --- Toastify/Spotify.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Toastify/Spotify.cs b/Toastify/Spotify.cs index 293e7a5c..dd590a83 100644 --- a/Toastify/Spotify.cs +++ b/Toastify/Spotify.cs @@ -9,16 +9,12 @@ using System.Reflection; using System.Net; using Newtonsoft.Json; -using System.Diagnostics; namespace Toastify { internal class Win32 { - [DllImport("user32.dll", SetLastError = true)] - internal static extern IntPtr FindWindowEx(IntPtr hWndParent, IntPtr hWndChildAfter, string lpClassName, string lpWindowName); - [DllImport("user32.dll", SetLastError = true)] internal static extern IntPtr FindWindow(string lpClassName, string lpWindowName);