Files
youtube-music/providers/protocol-handler.js
2023-08-29 17:22:38 +09:00

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,
};