From af62ec5aa7b91d98a04ede159a08248c03b01af5 Mon Sep 17 00:00:00 2001 From: Emilio Astarita Date: Tue, 27 Dec 2016 22:58:26 -0300 Subject: [PATCH] Not spamming same message on toastr and stop current song error. --- render/LyricfierRender.ts | 13 +++++++++++++ render/SpotifyService.ts | 7 ++++++- render/views/Song.html | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/render/LyricfierRender.ts b/render/LyricfierRender.ts index 64b3c65..67795c7 100644 --- a/render/LyricfierRender.ts +++ b/render/LyricfierRender.ts @@ -22,8 +22,21 @@ class LyricfierRender { protected currentView; protected liveReload = false; protected settings: SettingsValues; + protected lastMessageTime = 0; + protected lastMessage = ''; listenStatus(msg) { + if (msg === this.lastMessage) { + // not spamming same message. + const now = new Date(); + const last = new Date(this.lastMessageTime); + last.setMilliseconds(last.getMilliseconds() + 4500); + if (now < last) { + return; + } + } + this.lastMessageTime = (new Date()).getTime(); + this.lastMessage = msg; toastr.info(msg); } diff --git a/render/SpotifyService.ts b/render/SpotifyService.ts index 1539d76..5ea3cba 100644 --- a/render/SpotifyService.ts +++ b/render/SpotifyService.ts @@ -187,7 +187,12 @@ export class SpotifyService { public getCurrentSong(cb) { this.getStatus((err, status)=> { - if (err) return cb(err); + if (err) { + this.foundPort = false; + this.csrfToken = null; + this.oAuthToken.t = null; + return cb(err); + } console.log('getStatus', status); if (status.track && status.track.track_resource) { diff --git a/render/views/Song.html b/render/views/Song.html index 218a3cf..f4151cc 100644 --- a/render/views/Song.html +++ b/render/views/Song.html @@ -32,7 +32,7 @@

lyricfier

Waveform

Looking for a Song on Spotify

-

Is Spotify running?

+

Connecting...

Try Again