Add 2 more config options

refreshOnPlayPause: false
trayControls: true,
This commit is contained in:
Araxeus
2023-01-09 23:46:44 +02:00
parent 1c5d61854e
commit bc5023c360
5 changed files with 88 additions and 21 deletions

23
tray.js
View File

@ -1,14 +1,29 @@
const path = require("path");
const { app, Menu, nativeImage, Tray } = require("electron");
const { Menu, nativeImage, Tray } = require("electron");
const { restart } = require("./providers/app-controls");
const config = require("./config");
const getSongControls = require("./providers/song-controls");
// Prevent tray being garbage collected
/** @type {Electron.Tray} */
let tray;
module.exports.setTrayOnClick = (fn) => {
if (!tray) return;
tray.removeAllListeners('click');
tray.on("click", fn);
};
// wont do anything on macos since its disabled
module.exports.setTrayOnDoubleClick = (fn) => {
if (!tray) return;
tray.removeAllListeners('double-click');
tray.on("double-click", fn);
};
module.exports.setUpTray = (app, win) => {
if (!config.get("options.tray")) {
tray = undefined;
@ -17,13 +32,19 @@ module.exports.setUpTray = (app, win) => {
const { playPause, next, previous } = getSongControls(win);
const iconPath = path.join(__dirname, "assets", "youtube-music-tray.png");
let trayIcon = nativeImage.createFromPath(iconPath).resize({
width: 16,
height: 16,
});
tray = new Tray(trayIcon);
tray.setToolTip("Youtube Music");
// macOS only
tray.setIgnoreDoubleClickEvents(true);
tray.on("click", () => {
if (config.get("options.trayClickPlayPause")) {
playPause();