Skip to content

Commit

Permalink
fix: do not handle TimeChanged event
Browse files Browse the repository at this point in the history
  • Loading branch information
JellyBrick committed Nov 3, 2024
1 parent b258d97 commit 25c9151
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
8 changes: 6 additions & 2 deletions src/plugins/notifications/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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)
) {
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/scrobbler/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { BrowserWindow } from 'electron';
import registerCallback, {
MediaType,
type SongInfo,
SongInfoEvent,
} from '@/providers/song-info';
import { createBackend } from '@/utils';

Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/touchbar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions src/tray.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 25c9151

Please sign in to comment.