mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-16 20:52:06 +00:00
Add album title to largeImage and change paused icon
This commit is contained in:
@ -4,8 +4,8 @@ const { dialog, app } = require("electron");
|
|||||||
|
|
||||||
const registerCallback = require("../../providers/song-info");
|
const registerCallback = require("../../providers/song-info");
|
||||||
|
|
||||||
// Application ID registered by @semvis123
|
// Application ID registered by @xn-oah
|
||||||
const clientId = "790655993809338398";
|
const clientId = "937234785716285471";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} Info
|
* @typedef {Object} Info
|
||||||
@ -30,14 +30,13 @@ const resetInfo = () => {
|
|||||||
info.ready = false;
|
info.ready = false;
|
||||||
clearTimeout(clearActivity);
|
clearTimeout(clearActivity);
|
||||||
if (dev()) console.log("discord disconnected");
|
if (dev()) console.log("discord disconnected");
|
||||||
refreshCallbacks.forEach(cb => cb());
|
refreshCallbacks.forEach((cb) => cb());
|
||||||
};
|
};
|
||||||
|
|
||||||
let window;
|
let window;
|
||||||
const connect = (showErr = false) => {
|
const connect = (showErr = false) => {
|
||||||
if (info.rpc) {
|
if (info.rpc) {
|
||||||
if (dev())
|
if (dev()) console.log("Attempted to connect with active RPC object");
|
||||||
console.log('Attempted to connect with active RPC object');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,19 +47,24 @@ const connect = (showErr = false) => {
|
|||||||
|
|
||||||
info.rpc.once("connected", () => {
|
info.rpc.once("connected", () => {
|
||||||
if (dev()) console.log("discord connected");
|
if (dev()) console.log("discord connected");
|
||||||
refreshCallbacks.forEach(cb => cb());
|
refreshCallbacks.forEach((cb) => cb());
|
||||||
});
|
});
|
||||||
info.rpc.once("ready", () => {
|
info.rpc.once("ready", () => {
|
||||||
info.ready = true;
|
info.ready = true;
|
||||||
if (info.lastSongInfo) updateActivity(info.lastSongInfo)
|
if (info.lastSongInfo) updateActivity(info.lastSongInfo);
|
||||||
});
|
});
|
||||||
info.rpc.once("disconnected", resetInfo);
|
info.rpc.once("disconnected", resetInfo);
|
||||||
|
|
||||||
// Startup the rpc client
|
// Startup the rpc client
|
||||||
info.rpc.login({ clientId }).catch(err => {
|
info.rpc.login({ clientId }).catch((err) => {
|
||||||
resetInfo();
|
resetInfo();
|
||||||
if (dev()) console.error(err);
|
if (dev()) console.error(err);
|
||||||
if (showErr) dialog.showMessageBox(window, { title: 'Connection failed', message: err.message || String(err), type: 'error' });
|
if (showErr)
|
||||||
|
dialog.showMessageBox(window, {
|
||||||
|
title: "Connection failed",
|
||||||
|
message: err.message || String(err),
|
||||||
|
type: "error",
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -70,12 +74,15 @@ let clearActivity;
|
|||||||
*/
|
*/
|
||||||
let updateActivity;
|
let updateActivity;
|
||||||
|
|
||||||
module.exports = (win, { activityTimoutEnabled, activityTimoutTime, listenAlong }) => {
|
module.exports = (
|
||||||
|
win,
|
||||||
|
{ activityTimoutEnabled, activityTimoutTime, listenAlong }
|
||||||
|
) => {
|
||||||
window = win;
|
window = win;
|
||||||
// We get multiple events
|
// We get multiple events
|
||||||
// Next song: PAUSE(n), PAUSE(n+1), PLAY(n+1)
|
// Next song: PAUSE(n), PAUSE(n+1), PLAY(n+1)
|
||||||
// Skip time: PAUSE(N), PLAY(N)
|
// Skip time: PAUSE(N), PLAY(N)
|
||||||
updateActivity = songInfo => {
|
updateActivity = (songInfo) => {
|
||||||
if (songInfo.title.length === 0 && songInfo.artist.length === 0) {
|
if (songInfo.title.length === 0 && songInfo.artist.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -91,7 +98,11 @@ module.exports = (win, { activityTimoutEnabled, activityTimoutTime, listenAlong
|
|||||||
}
|
}
|
||||||
|
|
||||||
// clear directly if timeout is 0
|
// clear directly if timeout is 0
|
||||||
if (songInfo.isPaused && activityTimoutEnabled && activityTimoutTime === 0) {
|
if (
|
||||||
|
songInfo.isPaused &&
|
||||||
|
activityTimoutEnabled &&
|
||||||
|
activityTimoutTime === 0
|
||||||
|
) {
|
||||||
info.rpc.clearActivity().catch(console.error);
|
info.rpc.clearActivity().catch(console.error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -104,28 +115,27 @@ module.exports = (win, { activityTimoutEnabled, activityTimoutTime, listenAlong
|
|||||||
details: songInfo.title,
|
details: songInfo.title,
|
||||||
state: songInfo.artist,
|
state: songInfo.artist,
|
||||||
largeImageKey: songInfo.imageSrc,
|
largeImageKey: songInfo.imageSrc,
|
||||||
largeImageText: [
|
largeImageText: songInfo.album,
|
||||||
songInfo.uploadDate,
|
buttons: listenAlong
|
||||||
songInfo.views.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + " views",
|
? [{ label: "Listen Along", url: songInfo.url }]
|
||||||
].join(' || '),
|
: undefined,
|
||||||
buttons: listenAlong ? [
|
|
||||||
{ label: "Listen Along", url: songInfo.url },
|
|
||||||
] : undefined,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (songInfo.isPaused) {
|
if (songInfo.isPaused) {
|
||||||
// Add an idle icon to show that the song is paused
|
// Add a paused icon to show that the song is paused
|
||||||
activityInfo.smallImageKey = "idle";
|
activityInfo.smallImageKey = "paused";
|
||||||
activityInfo.smallImageText = "idle/paused";
|
activityInfo.smallImageText = "Paused";
|
||||||
// Set start the timer so the activity gets cleared after a while if enabled
|
// Set start the timer so the activity gets cleared after a while if enabled
|
||||||
if (activityTimoutEnabled)
|
if (activityTimoutEnabled)
|
||||||
clearActivity = setTimeout(() => info.rpc.clearActivity().catch(console.error), activityTimoutTime ?? 10000);
|
clearActivity = setTimeout(
|
||||||
|
() => info.rpc.clearActivity().catch(console.error),
|
||||||
|
activityTimoutTime ?? 10000
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
// Add the start and end time of the song
|
// Add the start and end time of the song
|
||||||
const songStartTime = Date.now() - songInfo.elapsedSeconds * 1000;
|
const songStartTime = Date.now() - songInfo.elapsedSeconds * 1000;
|
||||||
activityInfo.startTimestamp = songStartTime;
|
activityInfo.startTimestamp = songStartTime;
|
||||||
activityInfo.endTimestamp =
|
activityInfo.endTimestamp = songStartTime + songInfo.songDuration * 1000;
|
||||||
songStartTime + songInfo.songDuration * 1000;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
info.rpc.setActivity(activityInfo).catch(console.error);
|
info.rpc.setActivity(activityInfo).catch(console.error);
|
||||||
@ -136,7 +146,7 @@ module.exports = (win, { activityTimoutEnabled, activityTimoutTime, listenAlong
|
|||||||
registerCallback(updateActivity);
|
registerCallback(updateActivity);
|
||||||
connect();
|
connect();
|
||||||
});
|
});
|
||||||
app.on('window-all-closed', module.exports.clear)
|
app.on("window-all-closed", module.exports.clear);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.clear = () => {
|
module.exports.clear = () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user