Fix now-playing scraper, quit hang, tray icon, and tray race (v1.0.1)
- Read the track from the Media Session API, falling back to the legacy ytmusic-player-bar scrape. Current YT Music layouts render no player bar, so the API and tray stayed empty while music played. Artist is also clean now (no "• views • likes" suffix). - Terminate connected WebSocket clients before closing the server. ws's close() waits for every client to disconnect, so quitting with an overlay open hung forever, leaving the window playing and the port bound. - Replace the tray icon with a valid PNG (the old one had a bad IDAT CRC and decoded to an empty image) and test that its chunks are well formed. - Create the tray before the window so early state updates are not dropped. - Bump version to 1.0.1. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,42 +1,9 @@
|
||||
const { ipcRenderer } = require('electron');
|
||||
const { scrapeNowPlaying } = require('./now-playing');
|
||||
|
||||
const POLL_INTERVAL_MS = 3000;
|
||||
let lastSent = null;
|
||||
|
||||
function scrapeNowPlaying() {
|
||||
const titleEl =
|
||||
document.querySelector('ytmusic-player-bar .title') ||
|
||||
document.querySelector('.ytmusic-player-bar .title');
|
||||
const title = titleEl ? titleEl.textContent.trim() : null;
|
||||
|
||||
const bylineEl =
|
||||
document.querySelector('ytmusic-player-bar .byline') ||
|
||||
document.querySelector('.ytmusic-player-bar .byline');
|
||||
const artist = bylineEl ? bylineEl.textContent.trim() : null;
|
||||
|
||||
const artImg =
|
||||
document.querySelector('ytmusic-player-bar .middle-controls .thumbnail-image-wrapper img') ||
|
||||
document.querySelector('ytmusic-player-bar .image img') ||
|
||||
document.querySelector('ytmusic-player-bar img.image');
|
||||
const albumArt = artImg ? artImg.src : null;
|
||||
|
||||
// The play/pause button's title indicates state: when music is playing the
|
||||
// button's action is "Pause", and vice versa.
|
||||
const playPauseBtn = document.querySelector('#play-pause-button');
|
||||
let isPlaying = false;
|
||||
if (playPauseBtn) {
|
||||
const btnTitle = (
|
||||
playPauseBtn.getAttribute('title') ||
|
||||
playPauseBtn.getAttribute('aria-label') ||
|
||||
''
|
||||
).toLowerCase();
|
||||
isPlaying = btnTitle.includes('pause');
|
||||
}
|
||||
|
||||
if (!title) return null;
|
||||
return { title, artist, albumArt, isPlaying };
|
||||
}
|
||||
|
||||
function changed(a, b) {
|
||||
if (a === null && b === null) return false;
|
||||
if (a === null || b === null) return true;
|
||||
@@ -49,7 +16,7 @@ function changed(a, b) {
|
||||
}
|
||||
|
||||
function poll() {
|
||||
const data = scrapeNowPlaying();
|
||||
const data = scrapeNowPlaying(document, navigator);
|
||||
if (!changed(data, lastSent)) return;
|
||||
lastSent = data;
|
||||
ipcRenderer.send('wtm:state', data || { isPlaying: false });
|
||||
|
||||
Reference in New Issue
Block a user