From 38c1f05c35240f01badc0d13772ddab2ed275bde Mon Sep 17 00:00:00 2001 From: Mar0xy Date: Mon, 31 Jul 2023 12:06:31 +0200 Subject: [PATCH] Allow listenbrainz to be triggered on every play --- src/features/listenbrainz/listenbrainz.ts | 2 ++ src/preload.ts | 13 +++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/features/listenbrainz/listenbrainz.ts b/src/features/listenbrainz/listenbrainz.ts index f7a6e1d..303c2eb 100644 --- a/src/features/listenbrainz/listenbrainz.ts +++ b/src/features/listenbrainz/listenbrainz.ts @@ -81,3 +81,5 @@ export class ListenBrainz { } } } + +export { ListenBrainzStore }; \ No newline at end of file diff --git a/src/preload.ts b/src/preload.ts index 40678a3..e1bbbff 100644 --- a/src/preload.ts +++ b/src/preload.ts @@ -6,7 +6,7 @@ import { globalEvents } from "./constants/globalEvents"; import { settings } from "./constants/settings"; import { statuses } from "./constants/statuses"; import { Songwhip } from "./features/songwhip/songwhip"; -import { ListenBrainz } from "./features/listenbrainz/listenbrainz"; +import { ListenBrainz, ListenBrainzStore } from "./features/listenbrainz/listenbrainz"; import { Options } from "./models/options"; import { downloadFile } from "./scripts/download"; import { addHotkey } from "./scripts/hotkeys"; @@ -202,6 +202,11 @@ function playPause() { } } +/** + * Clears the old listenbrainz data on launch + */ +ListenBrainzStore.clear(); + /** * Add hotkeys for when tidal is focused * Reflects the desktop hotkeys found on: @@ -372,6 +377,9 @@ function updateMediaInfo(options: Options, notify: boolean) { }; player.playbackStatus = options.status == statuses.paused ? "Paused" : "Playing"; } + if (settingsStore.get(settings.ListenBrainz.enabled) && (ListenBrainzStore.get("OldData") as string[][1]) !== options.title) { + ListenBrainz.scrobble(options.title, options.artists, options.status, convertDuration(options.duration)); + } } } @@ -469,9 +477,6 @@ setInterval(function () { updateMediaInfo(options, titleOrArtistsChanged); if (titleOrArtistsChanged) { updateMediaSession(options); - if (settingsStore.get(settings.ListenBrainz.enabled)) { - ListenBrainz.scrobble(options.title, options.artists, options.status, convertDuration(options.duration)); - } } });