From cff266c9df9e432b11d9ee81e05f80e559b04f07 Mon Sep 17 00:00:00 2001 From: vapormusic Date: Thu, 10 Feb 2022 15:53:31 +0700 Subject: [PATCH] attempt to fix lastfm --- src/main/plugins/lastfm.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/plugins/lastfm.ts b/src/main/plugins/lastfm.ts index 5d9adf66..53644bb2 100644 --- a/src/main/plugins/lastfm.ts +++ b/src/main/plugins/lastfm.ts @@ -15,6 +15,7 @@ export default class LastFMPlugin { private _app: any; private _lastfm: any; private _store: any; + private _timer: any; private authenticateFromFile() { let sessionData = require(this.sessionPath) @@ -78,7 +79,7 @@ export default class LastFMPlugin { } private async scrobbleSong(attributes: any) { - await new Promise(resolve => setTimeout(resolve, Math.round(attributes.durationInMillis * (this._store.lastfm.scrobble_after / 100)))); + this._timer = setTimeout(() => { const currentAttributes = attributes; if (!this._lastfm || this._lastfm.cachedAttributes === attributes) { @@ -113,7 +114,7 @@ export default class LastFMPlugin { } } else { return console.log('[LastFM] Did not add ', attributes.name, '—', this.filterArtistName(attributes.artistName), 'because now playing a other song.'); - } + }},Math.round(attributes.durationInMillis * (this._store.lastfm.scrobble_after / 100))); } private filterArtistName(artist: any) { @@ -248,6 +249,7 @@ export default class LastFMPlugin { this._lastfm.cachedAttributes = false} this.scrobbleSong(attributes) this.updateNowPlayingSong(attributes) + if(this._timer) clearTimeout(this._timer) } } \ No newline at end of file