2026-04-26 09:42:49 -07:00
|
|
|
const { ipcRenderer } = require('electron');
|
2026-10-04 11:37:38 -07:00
|
|
|
const { scrapeNowPlaying } = require('./now-playing');
|
2026-04-26 09:42:49 -07:00
|
|
|
|
|
|
|
|
const POLL_INTERVAL_MS = 3000;
|
|
|
|
|
let lastSent = null;
|
|
|
|
|
|
|
|
|
|
function changed(a, b) {
|
|
|
|
|
if (a === null && b === null) return false;
|
|
|
|
|
if (a === null || b === null) return true;
|
|
|
|
|
return (
|
|
|
|
|
a.title !== b.title ||
|
|
|
|
|
a.artist !== b.artist ||
|
|
|
|
|
a.albumArt !== b.albumArt ||
|
|
|
|
|
a.isPlaying !== b.isPlaying
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function poll() {
|
2026-10-04 11:37:38 -07:00
|
|
|
const data = scrapeNowPlaying(document, navigator);
|
2026-04-26 09:42:49 -07:00
|
|
|
if (!changed(data, lastSent)) return;
|
|
|
|
|
lastSent = data;
|
|
|
|
|
ipcRenderer.send('wtm:state', data || { isPlaying: false });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setInterval(poll, POLL_INTERVAL_MS);
|
|
|
|
|
poll();
|
|
|
|
|
|
|
|
|
|
console.log('[wtm] yt-scraper preload loaded');
|