From 25c9151a0c402c2ffa83233da3ecd6c84f630fa6 Mon Sep 17 00:00:00 2001 From: JellyBrick Date: Sun, 3 Nov 2024 18:53:43 +0900 Subject: [PATCH] fix: do not handle TimeChanged event --- src/plugins/notifications/main.ts | 8 ++++++-- src/plugins/scrobbler/main.ts | 4 +++- src/plugins/touchbar/index.ts | 5 +++-- src/tray.ts | 8 +++++--- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/plugins/notifications/main.ts b/src/plugins/notifications/main.ts index 0782c6a0c9..dbf3d94bd2 100644 --- a/src/plugins/notifications/main.ts +++ b/src/plugins/notifications/main.ts @@ -5,7 +5,10 @@ import is from 'electron-is'; import { notificationImage } from './utils'; import interactive from './interactive'; -import registerCallback, { type SongInfo } from '@/providers/song-info'; +import registerCallback, { + type SongInfo, + SongInfoEvent, +} from '@/providers/song-info'; import type { NotificationsPluginConfig } from './index'; import type { BackendContext } from '@/types/contexts'; @@ -30,8 +33,9 @@ const setup = () => { let oldNotification: Notification; let currentUrl: string | undefined; - registerCallback((songInfo: SongInfo) => { + registerCallback((songInfo: SongInfo, event) => { if ( + event !== SongInfoEvent.TimeChanged && !songInfo.isPaused && (songInfo.url !== currentUrl || config.unpauseNotification) ) { diff --git a/src/plugins/scrobbler/main.ts b/src/plugins/scrobbler/main.ts index 73053f137d..91a02a75ef 100644 --- a/src/plugins/scrobbler/main.ts +++ b/src/plugins/scrobbler/main.ts @@ -3,6 +3,7 @@ import { BrowserWindow } from 'electron'; import registerCallback, { MediaType, type SongInfo, + SongInfoEvent, } from '@/providers/song-info'; import { createBackend } from '@/utils'; @@ -70,7 +71,8 @@ export const backend = createBackend< await this.createSessions(config, setConfig); this.setConfig = setConfig; - registerCallback((songInfo: SongInfo) => { + registerCallback((songInfo: SongInfo, event) => { + if (event === SongInfoEvent.TimeChanged) return; // Set remove the old scrobble timer clearTimeout(scrobbleTimer); if (!songInfo.isPaused) { diff --git a/src/plugins/touchbar/index.ts b/src/plugins/touchbar/index.ts index 8b75d15ecb..501452fbb0 100644 --- a/src/plugins/touchbar/index.ts +++ b/src/plugins/touchbar/index.ts @@ -2,7 +2,7 @@ import { nativeImage, type NativeImage, TouchBar } from 'electron'; import { createPlugin } from '@/utils'; import getSongControls from '@/providers/song-controls'; -import registerCallback from '@/providers/song-info'; +import registerCallback, { SongInfoEvent } from '@/providers/song-info'; import { t } from '@/i18n'; import youtubeMusicIcon from '@assets/youtube-music.png?asset&asarUnpack'; @@ -81,7 +81,8 @@ export default createPlugin({ controls = [previous, playPause, next, dislike, like]; // Register the callback - registerCallback((songInfo) => { + registerCallback((songInfo, event) => { + if (event === SongInfoEvent.TimeChanged) return; // Song information changed, so lets update the touchBar // Set the song title diff --git a/src/tray.ts b/src/tray.ts index 2f609bc189..6059d0e07a 100644 --- a/src/tray.ts +++ b/src/tray.ts @@ -1,4 +1,4 @@ -import { Menu, screen, nativeImage, Tray } from 'electron'; +import { Menu, nativeImage, screen, Tray } from 'electron'; import is from 'electron-is'; import defaultTrayIconAsset from '@assets/youtube-music-tray.png?asset&asarUnpack'; @@ -7,7 +7,7 @@ import pausedTrayIconAsset from '@assets/youtube-music-tray-paused.png?asset&asa import config from './config'; import { restart } from './providers/app-controls'; -import registerCallback from './providers/song-info'; +import registerCallback, { SongInfoEvent } from './providers/song-info'; import getSongControls from './providers/song-controls'; import { t } from '@/i18n'; @@ -125,7 +125,9 @@ export const setUpTray = (app: Electron.App, win: Electron.BrowserWindow) => { const trayMenu = Menu.buildFromTemplate(template); tray.setContextMenu(trayMenu); - registerCallback((songInfo) => { + registerCallback((songInfo, event) => { + if (event === SongInfoEvent.TimeChanged) return; + if (tray) { if (typeof songInfo.isPaused === 'undefined') { tray.setImage(defaultTrayIcon);