mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-12 11:01:45 +00:00
fix: callback for time-changed event (#2577)
Co-authored-by: Derek Alsop <15299183+Azorant@users.noreply.github.com>
This commit is contained in:
@ -8,7 +8,10 @@ import previousIcon from '@assets/media-icons-black/previous.png?asset&asarUnpac
|
||||
import { notificationImage, secondsToMinutes, ToastStyles } from './utils';
|
||||
|
||||
import getSongControls from '@/providers/song-controls';
|
||||
import registerCallback, { SongInfo } from '@/providers/song-info';
|
||||
import registerCallback, {
|
||||
type SongInfo,
|
||||
SongInfoEvent,
|
||||
} from '@/providers/song-info';
|
||||
import { changeProtocolHandler } from '@/providers/protocol-handler';
|
||||
import { setTrayOnClick, setTrayOnDoubleClick } from '@/tray';
|
||||
import { mediaIcons } from '@/types/media-icons';
|
||||
@ -258,15 +261,14 @@ export default (
|
||||
let currentSeconds = 0;
|
||||
on('ytmd:player-api-loaded', () => send('ytmd:setup-time-changed-listener'));
|
||||
|
||||
on('ytmd:time-changed', (t: number) => {
|
||||
currentSeconds = t;
|
||||
});
|
||||
|
||||
let savedSongInfo: SongInfo;
|
||||
let lastUrl: string | undefined;
|
||||
|
||||
// Register songInfoCallback
|
||||
registerCallback((songInfo) => {
|
||||
registerCallback((songInfo, event) => {
|
||||
if (event === SongInfoEvent.TimeChanged) {
|
||||
currentSeconds = songInfo.elapsedSeconds ?? 0;
|
||||
}
|
||||
if (!songInfo.artist && !songInfo.title) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -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)
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user