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

Commit

Permalink
current artist notification is no longer repeated if new site was loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin-Oehler committed May 29, 2017
1 parent 662ba85 commit 503c6b1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
13 changes: 11 additions & 2 deletions SteamVR-Spotify/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ class Program
{
static WebKitOverlay overlay;

static string current_artist;
static string current_song;

static void Main(string[] args)
{
SteamVR_WebKit.SteamVR_WebKit.Init(new CefSharp.CefSettings() { PersistSessionCookies = true, CachePath = "chrome-cache" });
SteamVR_WebKit.SteamVR_WebKit.FPS = 30;

current_artist = "";
current_song = "";
//SteamVR_WebKit.JsInterop.Notifications.RegisterIcon("default", new Bitmap(Environment.CurrentDirectory + "\\Resources\\spotify-logo-small.png")); -- leads to exception

overlay = new WebKitOverlay(new Uri("https://open.spotify.com"), 1024, 1024, "spotify", "Spotify", OverlayType.Dashboard);
Expand All @@ -37,7 +42,10 @@ static void Main(string[] args)

SteamVR_Application application = new SteamVR_Application();
application.InstallManifest(true);
//application.RemoveManifest();
if (args.Length > 0 && args[0] == "--debug")
{
application.RemoveManifest();
}

SteamVR_WebKit.SteamVR_WebKit.RunOverlays(); // Runs update/draw calls for all active overlays. And yes, it's blocking.
}
Expand All @@ -59,6 +67,8 @@ private static void Overlay_BrowserPreInit(object sender, EventArgs e)

overlay.Browser.ConsoleMessage += Browser_ConsoleMessage;
overlay.Browser.RegisterJsObject("notifications", new SteamVR_WebKit.JsInterop.Notifications(overlay.DashboardOverlay));
overlay.Browser.RegisterJsObject("current_artist", current_artist);
overlay.Browser.RegisterJsObject("current_song", current_song);
}

private static void PageReady(object sender, CefSharp.LoadingStateChangedEventArgs args)
Expand All @@ -71,7 +81,6 @@ private static void PageReady(object sender, CefSharp.LoadingStateChangedEventAr
//Console.WriteLine(script);
overlay.Browser.GetBrowser().MainFrame.ExecuteJavaScriptAsync(script);
}

}
}
}
11 changes: 4 additions & 7 deletions SteamVR-Spotify/Resources/Script.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ if (account_link) {
document.getElementById('login-pass').value = pwd
}
} else {
var last_artist = ''
var last_name = ''

function track_notification( )
{
var artist_dom = document.getElementsByClassName('track-info__artists')[0]
Expand All @@ -37,12 +34,12 @@ if (account_link) {
} else {
return
}
if (last_artist !== artist || last_name !== name) {
if (current_artist !== artist || current_song !== name) {
notifications.sendNotification('Now playing: ' + artist + ' - ' + name)
last_artist = artist
last_name = name
current_artist = artist
current_song = name
}
}

setInterval(track_notification, 2000);
}
}

0 comments on commit 503c6b1

Please sign in to comment.