fix formatting

This commit is contained in:
Noah
2022-01-30 13:15:29 -06:00
parent e9a670831c
commit 543db59a55

View File

@ -30,13 +30,14 @@ 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()) console.log("Attempted to connect with active RPC object"); if (dev())
console.log('Attempted to connect with active RPC object');
return; return;
} }
@ -47,24 +48,19 @@ 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) if (showErr) dialog.showMessageBox(window, { title: 'Connection failed', message: err.message || String(err), type: 'error' });
dialog.showMessageBox(window, {
title: "Connection failed",
message: err.message || String(err),
type: "error",
});
}); });
}; };
@ -74,15 +70,12 @@ let clearActivity;
*/ */
let updateActivity; let updateActivity;
module.exports = ( module.exports = (win, { activityTimoutEnabled, activityTimoutTime, listenAlong }) => {
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;
} }
@ -98,11 +91,7 @@ module.exports = (
} }
// clear directly if timeout is 0 // clear directly if timeout is 0
if ( if (songInfo.isPaused && activityTimoutEnabled && activityTimoutTime === 0) {
songInfo.isPaused &&
activityTimoutEnabled &&
activityTimoutTime === 0
) {
info.rpc.clearActivity().catch(console.error); info.rpc.clearActivity().catch(console.error);
return; return;
} }
@ -116,9 +105,9 @@ module.exports = (
state: songInfo.artist, state: songInfo.artist,
largeImageKey: songInfo.imageSrc, largeImageKey: songInfo.imageSrc,
largeImageText: songInfo.album, largeImageText: songInfo.album,
buttons: listenAlong buttons: listenAlong ? [
? [{ label: "Listen Along", url: songInfo.url }] { label: "Listen Along", url: songInfo.url },
: undefined, ] : undefined,
}; };
if (songInfo.isPaused) { if (songInfo.isPaused) {
@ -127,15 +116,13 @@ module.exports = (
activityInfo.smallImageText = "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( clearActivity = setTimeout(() => info.rpc.clearActivity().catch(console.error), activityTimoutTime ?? 10000);
() => 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 = songStartTime + songInfo.songDuration * 1000; activityInfo.endTimestamp =
songStartTime + songInfo.songDuration * 1000;
} }
info.rpc.setActivity(activityInfo).catch(console.error); info.rpc.setActivity(activityInfo).catch(console.error);
@ -146,7 +133,7 @@ module.exports = (
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 = () => {