mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-10 10:11:46 +00:00
46 lines
867 B
JavaScript
46 lines
867 B
JavaScript
const path = require('node:path');
|
|
|
|
const { app } = require('electron');
|
|
|
|
const getSongControls = require('./song-controls');
|
|
|
|
const APP_PROTOCOL = 'youtubemusic';
|
|
|
|
let protocolHandler;
|
|
|
|
function setupProtocolHandler(win) {
|
|
if (process.defaultApp && process.argv.length >= 2) {
|
|
app.setAsDefaultProtocolClient(
|
|
APP_PROTOCOL,
|
|
process.execPath,
|
|
[path.resolve(process.argv[1])],
|
|
);
|
|
} else {
|
|
app.setAsDefaultProtocolClient(APP_PROTOCOL);
|
|
}
|
|
|
|
const songControls = getSongControls(win);
|
|
|
|
protocolHandler = (cmd) => {
|
|
if (Object.keys(songControls).includes(cmd)) {
|
|
songControls[cmd]();
|
|
}
|
|
};
|
|
}
|
|
|
|
function handleProtocol(cmd) {
|
|
protocolHandler(cmd);
|
|
}
|
|
|
|
function changeProtocolHandler(f) {
|
|
protocolHandler = f;
|
|
}
|
|
|
|
module.exports = {
|
|
APP_PROTOCOL,
|
|
setupProtocolHandler,
|
|
handleProtocol,
|
|
changeProtocolHandler,
|
|
};
|
|
|