diff --git a/config/store.js b/config/store.js index 66163acc..07984820 100644 --- a/config/store.js +++ b/config/store.js @@ -13,10 +13,10 @@ const migrations = { setDefaultPluginOptions(store, "visualizer"); if (store.get("plugins.notifications.toastStyle") === undefined) { - const pluginOptions = store.get("plugins.notifications") || {}; - store.set("plugins.notifications", { - ...defaults.plugins.notifications, - ...pluginOptions, + const pluginOptions = store.get("plugins.notifications") || {}; + store.set("plugins.notifications", { + ...defaults.plugins.notifications, + ...pluginOptions, }); } }, diff --git a/index.js b/index.js index 18b71540..da6947cc 100644 --- a/index.js +++ b/index.js @@ -337,7 +337,7 @@ app.on("ready", () => { // Clear cache after 20s const clearCacheTimeout = setTimeout(() => { if (is.dev()) { - console.log("Clearing app cache."); + console.log("Clearing app cache."); } electron.session.defaultSession.clearCache(); clearTimeout(clearCacheTimeout); diff --git a/plugins/notifications/interactive.js b/plugins/notifications/interactive.js index 00a0c99f..17a480f9 100644 --- a/plugins/notifications/interactive.js +++ b/plugins/notifications/interactive.js @@ -19,7 +19,7 @@ module.exports = (win) => { let currentSeconds = 0; ipcMain.on('apiLoaded', () => win.webContents.send('setupTimeChangedListener')); - ipcMain.on('timeChanged', (_, t) => currentSeconds = t); + ipcMain.on('timeChanged', (_, t) => currentSeconds = t); if (app.isPackaged) save_temp_icons(); @@ -29,7 +29,7 @@ module.exports = (win) => { // Register songInfoCallback registerCallback(songInfo => { savedSongInfo = { ...songInfo }; - if (!songInfo.isPaused && + if (!songInfo.isPaused && (songInfo.url !== lastUrl || config.get("unpauseNotification")) ) { lastUrl = songInfo.url @@ -68,11 +68,11 @@ module.exports = (win) => { if (Object.keys(songControls).includes(cmd)) { songControls[cmd](); if (config.get("refreshOnPlayPause") && ( - cmd === 'pause' || - (cmd === 'play' && !config.get("unpauseNotification")) - ) + cmd === 'pause' || + (cmd === 'play' && !config.get("unpauseNotification")) + ) ) { - setImmediate(() => + setImmediate(() => sendNotification({ ...savedSongInfo, isPaused: cmd === 'pause', @@ -91,16 +91,16 @@ function sendNotification(songInfo) { savedNotification?.close(); savedNotification = new Notification({ - title: songInfo.title || "Playing", - body: songInfo.artist, - icon: iconSrc, - silent: true, - // https://learn.microsoft.com/en-us/uwp/schemas/tiles/toastschema/schema-root - // https://learn.microsoft.com/en-us/windows/apps/design/shell/tiles-and-notifications/toast-schema - // https://learn.microsoft.com/en-us/windows/apps/design/shell/tiles-and-notifications/adaptive-interactive-toasts?tabs=xml - // https://learn.microsoft.com/en-us/uwp/api/windows.ui.notifications.toasttemplatetype - toastXml: get_xml(songInfo, iconSrc), - }); + title: songInfo.title || "Playing", + body: songInfo.artist, + icon: iconSrc, + silent: true, + // https://learn.microsoft.com/en-us/uwp/schemas/tiles/toastschema/schema-root + // https://learn.microsoft.com/en-us/windows/apps/design/shell/tiles-and-notifications/toast-schema + // https://learn.microsoft.com/en-us/windows/apps/design/shell/tiles-and-notifications/adaptive-interactive-toasts?tabs=xml + // https://learn.microsoft.com/en-us/uwp/api/windows.ui.notifications.toasttemplatetype + toastXml: get_xml(songInfo, iconSrc), + }); savedNotification.on("close", (_) => { savedNotification = undefined; @@ -112,7 +112,7 @@ function sendNotification(songInfo) { const get_xml = (songInfo, iconSrc) => { switch (config.get("toastStyle")) { default: - case ToastStyles.logo: + case ToastStyles.logo: case ToastStyles.legacy: return xml_logo(songInfo, iconSrc); case ToastStyles.banner_top_custom: @@ -133,7 +133,7 @@ const iconLocation = app.isPackaged ? path.resolve(__dirname, '..', '..', 'assets/media-icons-black'); const display = (kind) => { - if (config.get("toastStyle") === ToastStyles.legacy ) { + if (config.get("toastStyle") === ToastStyles.legacy) { return `content="${icons[kind]}"`; } else { return `\ @@ -166,23 +166,18 @@ const toast = (content, isPaused) => `\ ${getButtons(isPaused)} `; -const xml_logo = ({title, artist, isPaused}, imgSrc) => toast(`\ - +const xml_image = ({ title, artist, isPaused }, imgSrc, placement) => toast(`\ + ${title} ${artist}\ `, isPaused); -const xml_hero = ({title, artist, isPaused}, imgSrc) => toast(`\ - - ${title} - ${artist}\ -`, isPaused); -const xml_banner_bottom = ({title, artist, isPaused}, imgSrc) => toast(`\ - - ${title} - ${artist}\ -`, isPaused); +const xml_logo = (songInfo, imgSrc) => xml_image(songInfo, imgSrc, 'placement="appLogoOverride"'); + +const xml_hero = (songInfo, imgSrc) => xml_image(songInfo, imgSrc, 'placement="hero"'); + +const xml_banner_bottom = (songInfo, imgSrc) => xml_image(songInfo, imgSrc, ''); const xml_banner_top_custom = (songInfo, imgSrc) => toast(`\ @@ -196,15 +191,15 @@ const xml_banner_top_custom = (songInfo, imgSrc) => toast(`\ \ `, songInfo.isPaused); -const xml_more_data = ({ album, elapsedSeconds, songDuration })=> `\ +const xml_more_data = ({ album, elapsedSeconds, songDuration }) => `\ - ${album ? + ${album ? `${album}` : ''} ${secondsToMinutes(elapsedSeconds)} / ${secondsToMinutes(songDuration)} \ `; -const xml_banner_centered_bottom = ({title, artist, isPaused}, imgSrc) => toast(`\ +const xml_banner_centered_bottom = ({ title, artist, isPaused }, imgSrc) => toast(`\ @@ -215,7 +210,7 @@ const xml_banner_centered_bottom = ({title, artist, isPaused}, imgSrc) => toast( \ `, isPaused); -const xml_banner_centered_top = ({title, artist, isPaused}, imgSrc) => toast(`\ +const xml_banner_centered_top = ({ title, artist, isPaused }, imgSrc) => toast(`\ diff --git a/plugins/notifications/menu.js b/plugins/notifications/menu.js index cb3ff603..014be184 100644 --- a/plugins/notifications/menu.js +++ b/plugins/notifications/menu.js @@ -5,55 +5,55 @@ const config = require("./config"); module.exports = (_win, options) => [ ...(is.linux() ? [ - { - label: "Notification Priority", - submenu: urgencyLevels.map((level) => ({ - label: level.name, - type: "radio", - checked: options.urgency === level.value, - click: () => config.set("urgency", level.value), - })), - }, - ] + { + label: "Notification Priority", + submenu: urgencyLevels.map((level) => ({ + label: level.name, + type: "radio", + checked: options.urgency === level.value, + click: () => config.set("urgency", level.value), + })), + }, + ] : []), ...(is.windows() ? [ - { - label: "Interactive Notifications", - type: "checkbox", - checked: options.interactive, - // doesn't update until restart - click: (item) => config.setAndMaybeRestart("interactive", item.checked), - }, - { - // submenu with settings for interactive notifications (name shouldn't be too long) - label: "Interactive Settings", - submenu: [ - { - label: "Open/Close on tray click", - type: "checkbox", - checked: options.trayControls, - click: (item) => config.set("trayControls", item.checked), - }, - { - label: "Hide Button Text", - type: "checkbox", - checked: options.hideButtonText, - click: (item) => config.set("hideButtonText", item.checked), - }, - { - label: "Refresh on Play/Pause", - type: "checkbox", - checked: options.refreshOnPlayPause, - click: (item) => config.set("refreshOnPlayPause", item.checked), - } - ] - }, - { - label: "Style", - submenu: getToastStyleMenuItems(options) - }, - ] + { + label: "Interactive Notifications", + type: "checkbox", + checked: options.interactive, + // doesn't update until restart + click: (item) => config.setAndMaybeRestart("interactive", item.checked), + }, + { + // submenu with settings for interactive notifications (name shouldn't be too long) + label: "Interactive Settings", + submenu: [ + { + label: "Open/Close on tray click", + type: "checkbox", + checked: options.trayControls, + click: (item) => config.set("trayControls", item.checked), + }, + { + label: "Hide Button Text", + type: "checkbox", + checked: options.hideButtonText, + click: (item) => config.set("hideButtonText", item.checked), + }, + { + label: "Refresh on Play/Pause", + type: "checkbox", + checked: options.refreshOnPlayPause, + click: (item) => config.set("refreshOnPlayPause", item.checked), + } + ] + }, + { + label: "Style", + submenu: getToastStyleMenuItems(options) + }, + ] : []), { label: "Show notification on unpause", diff --git a/plugins/notifications/utils.js b/plugins/notifications/utils.js index 3b408e07..8717b3a1 100644 --- a/plugins/notifications/utils.js +++ b/plugins/notifications/utils.js @@ -35,7 +35,7 @@ module.exports.notificationImage = (songInfo) => { if (!songInfo.image) return icon; if (!config.get("interactive")) return nativeImageToLogo(songInfo.image); - switch(config.get("toastStyle")) { + switch (config.get("toastStyle")) { case module.exports.ToastStyles.logo: case module.exports.ToastStyles.legacy: return this.saveImage(nativeImageToLogo(songInfo.image), tempIcon); @@ -67,13 +67,13 @@ function nativeImageToLogo(nativeImage) { } module.exports.save_temp_icons = () => { - for (const kind of Object.keys(module.exports.icons)) { + for (const kind of Object.keys(module.exports.icons)) { const destinationPath = path.join(userData, 'icons', `${kind}.png`); if (fs.existsSync(destinationPath)) continue; - const iconPath = path.resolve(__dirname, "../../assets/media-icons-black", `${kind}.png`); + const iconPath = path.resolve(__dirname, "../../assets/media-icons-black", `${kind}.png`); fs.mkdirSync(path.dirname(destinationPath), { recursive: true }); - fs.copyFile(iconPath, destinationPath, ()=>{}); - } + fs.copyFile(iconPath, destinationPath, () => { }); + } }; module.exports.snakeToCamel = (str) => { diff --git a/plugins/shortcuts/mpris.js b/plugins/shortcuts/mpris.js index 4857b34c..e0ab3468 100644 --- a/plugins/shortcuts/mpris.js +++ b/plugins/shortcuts/mpris.js @@ -1,5 +1,5 @@ const mpris = require("mpris-service"); -const {ipcMain} = require("electron"); +const { ipcMain } = require("electron"); const registerCallback = require("../../providers/song-info"); const getSongControls = require("../../providers/song-controls"); const config = require("../../config"); @@ -21,7 +21,7 @@ function setupMPRIS() { /** @param {Electron.BrowserWindow} win */ function registerMPRIS(win) { const songControls = getSongControls(win); - const {playPause, next, previous, volumeMinus10, volumePlus10, shuffle} = songControls; + const { playPause, next, previous, volumeMinus10, volumePlus10, shuffle } = songControls; try { const secToMicro = n => Math.round(Number(n) * 1e6); const microToSec = n => Math.round(Number(n) / 1e6); @@ -117,7 +117,7 @@ function registerMPRIS(win) { // With precise volume we can set the volume to the exact value. let newVol = parseInt(newVolume * 100); if (parseInt(player.volume * 100) !== newVol) { - if (!autoUpdate){ + if (!autoUpdate) { mprisVolNewer = true; autoUpdate = false; win.webContents.send('setVolume', newVol); diff --git a/providers/protocol-handler.js b/providers/protocol-handler.js index 18eaea31..6b0d36e1 100644 --- a/providers/protocol-handler.js +++ b/providers/protocol-handler.js @@ -16,7 +16,7 @@ function setupProtocolHandler(win) { } else { app.setAsDefaultProtocolClient(APP_PROTOCOL) } - + const songControls = getSongControls(win); protocolHandler = (cmd) => {