diff --git a/desktop-client/tray.js b/desktop-client/tray.js index 59ba8cd..034a18b 100644 --- a/desktop-client/tray.js +++ b/desktop-client/tray.js @@ -14,30 +14,6 @@ const TRAY_ICON_BASE64 = 'PB7S4/EuoISgYrLKD1dOhOPFP6+4R7ieoQPNv9/ULZ+zfis+0Y1e+F7oF3H5F+Xt' + 'T5p0AqBYeEeEF8k/gtcS56z6f/E5UOLHL8A8a4yC0IHbH4AAAAASUVORK5CYII='; -let trayInstance = null; -let opts = null; -let currentTitle = null; -let currentArtist = null; - -function buildMenu() { - const url = `http://localhost:${opts.port}/`; - const nowPlaying = - currentTitle && currentArtist - ? `${currentTitle} — ${currentArtist}` - : currentTitle || 'Nothing playing'; - - return Menu.buildFromTemplate([ - { label: "What's That Music", enabled: false }, - { label: `Now Playing: ${nowPlaying}`, enabled: false }, - { type: 'separator' }, - { label: 'Show Player', click: () => opts.onShow && opts.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() }, - ]); -} - /** * @param {Object} options * @param {number} options.port @@ -45,8 +21,29 @@ function buildMenu() { * @param {() => void} options.onQuit * @returns {{ update: (info: { title: string|null, artist: string|null }) => void, destroy: () => void }} */ -function createTray(options) { - opts = options; +function createTray({ port, onShow, onQuit }) { + let trayInstance = null; + let currentTitle = null; + let currentArtist = null; + + function buildMenu() { + const url = `http://localhost:${port}/`; + const nowPlaying = + currentTitle && currentArtist + ? `${currentTitle} — ${currentArtist}` + : currentTitle || 'Nothing playing'; + + return Menu.buildFromTemplate([ + { label: "What's That Music", enabled: false }, + { label: `Now Playing: ${nowPlaying}`, enabled: false }, + { type: 'separator' }, + { 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: () => onQuit && onQuit() }, + ]); + } const icon = nativeImage.createFromDataURL(TRAY_ICON_BASE64); icon.setTemplateImage(true);