mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 10:31:47 +00:00
Add 2 more config options
refreshOnPlayPause: false trayControls: true,
This commit is contained in:
23
tray.js
23
tray.js
@ -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();
|
||||
|
||||
Reference in New Issue
Block a user