Move tray state into createTray closure

Removes top-level let trayInstance, opts, currentTitle, currentArtist
and the top-level buildMenu function. All mutable state and buildMenu
now live inside the createTray closure. Public API and behaviour are
unchanged.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-26 09:56:48 -07:00
co-authored by Claude Sonnet 4.6
parent 8be1999a6b
commit 65e871c16e
+11 -14
View File
@@ -14,13 +14,20 @@ const TRAY_ICON_BASE64 =
'PB7S4/EuoISgYrLKD1dOhOPFP6+4R7ieoQPNv9/ULZ+zfis+0Y1e+F7oF3H5F+Xt' +
'T5p0AqBYeEeEF8k/gtcS56z6f/E5UOLHL8A8a4yC0IHbH4AAAAASUVORK5CYII=';
/**
* @param {Object} options
* @param {number} options.port
* @param {() => void} options.onShow
* @param {() => void} options.onQuit
* @returns {{ update: (info: { title: string|null, artist: string|null }) => void, destroy: () => void }}
*/
function createTray({ port, onShow, onQuit }) {
let trayInstance = null;
let opts = null;
let currentTitle = null;
let currentArtist = null;
function buildMenu() {
const url = `http://localhost:${opts.port}/`;
const url = `http://localhost:${port}/`;
const nowPlaying =
currentTitle && currentArtist
? `${currentTitle} — ${currentArtist}`
@@ -30,24 +37,14 @@ function buildMenu() {
{ label: "What's That Music", enabled: false },
{ label: `Now Playing: ${nowPlaying}`, enabled: false },
{ type: 'separator' },
{ label: 'Show Player', click: () => opts.onShow && opts.onShow() },
{ label: 'Show Player', click: () => onShow && onShow() },
{ label: 'Open Overlay in Browser', click: () => shell.openExternal(url) },
{ label: 'Copy OBS URL', click: () => clipboard.writeText(url) },
{ type: 'separator' },
{ label: 'Quit', click: () => opts.onQuit && opts.onQuit() },
{ label: 'Quit', click: () => onQuit && onQuit() },
]);
}
/**
* @param {Object} options
* @param {number} options.port
* @param {() => void} options.onShow
* @param {() => void} options.onQuit
* @returns {{ update: (info: { title: string|null, artist: string|null }) => void, destroy: () => void }}
*/
function createTray(options) {
opts = options;
const icon = nativeImage.createFromDataURL(TRAY_ICON_BASE64);
icon.setTemplateImage(true);