small cleanup to how discordrpc does things, fixed the icon for linux
This commit is contained in:
parent
eca7d4c78b
commit
c85b8d22ff
2 changed files with 28 additions and 24 deletions
|
@ -38,7 +38,7 @@ const CiderBase = {
|
||||||
|
|
||||||
let win = null
|
let win = null
|
||||||
const options = {
|
const options = {
|
||||||
icon: join(__dirname, `../../resources/icons/icon.ico`),
|
icon: join(__dirname, `../../resources/icons/icon.` + (process.platform === "win32" ? "ico" : "png")),
|
||||||
width: mainWindowState.width,
|
width: mainWindowState.width,
|
||||||
height: mainWindowState.height,
|
height: mainWindowState.height,
|
||||||
x: mainWindowState.x,
|
x: mainWindowState.x,
|
||||||
|
|
|
@ -9,7 +9,7 @@ module.exports = {
|
||||||
*/
|
*/
|
||||||
connect: function (clientId) {
|
connect: function (clientId) {
|
||||||
app.discord = {isConnected: false};
|
app.discord = {isConnected: false};
|
||||||
if (app.cfg.get('general.discord_rpc') == 0) return;
|
if (app.cfg.get('general.discord_rpc') == 0 || app.discord.isConnected) return;
|
||||||
|
|
||||||
DiscordRPC.register(clientId) // Apparently needed for ask to join, join, spectate etc.
|
DiscordRPC.register(clientId) // Apparently needed for ask to join, join, spectate etc.
|
||||||
const client = new DiscordRPC.Client({transport: "ipc"});
|
const client = new DiscordRPC.Client({transport: "ipc"});
|
||||||
|
@ -24,11 +24,6 @@ module.exports = {
|
||||||
|
|
||||||
app.discord.on('ready', () => {
|
app.discord.on('ready', () => {
|
||||||
console.log(`[DiscordRPC][connect] Successfully Connected to Discord. Authed for user: ${client.user.username} (${client.user.id})`);
|
console.log(`[DiscordRPC][connect] Successfully Connected to Discord. Authed for user: ${client.user.username} (${client.user.id})`);
|
||||||
|
|
||||||
if (app.discord.activityCache) {
|
|
||||||
client.setActivity(app.discord.activityCache).catch((e) => console.error(e));
|
|
||||||
app.discord.activityCache = null;
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// Handles Errors
|
// Handles Errors
|
||||||
|
@ -63,11 +58,10 @@ module.exports = {
|
||||||
if (app.cfg.get('general.discord_rpc') == 0) return;
|
if (app.cfg.get('general.discord_rpc') == 0) return;
|
||||||
|
|
||||||
if (!app.discord.isConnected) {
|
if (!app.discord.isConnected) {
|
||||||
this.connect()
|
app.discord.clearActivity().catch((e) => console.error(`[DiscordRPC][updateActivity] ${e}`));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!app.discord.isConnected) return;
|
|
||||||
|
|
||||||
// console.log('[DiscordRPC][updateActivity] Updating Discord Activity.')
|
// console.log('[DiscordRPC][updateActivity] Updating Discord Activity.')
|
||||||
|
|
||||||
const listenURL = `https://applemusicelectron.com/p?id=${attributes.playParams.id}`
|
const listenURL = `https://applemusicelectron.com/p?id=${attributes.playParams.id}`
|
||||||
|
@ -87,48 +81,58 @@ module.exports = {
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
if (ActivityObject.largeImageKey == "" || ActivityObject.largeImageKey == null) {
|
if (ActivityObject.largeImageKey == "" || ActivityObject.largeImageKey == null) {
|
||||||
ActivityObject.largeImageKey = (app.cfg.get("general.discord_rpc") == 1) ? "cider" : "logo"
|
ActivityObject.largeImageKey = (app.cfg.get("general.discord_rpc") == 1) ? "cider" : "logo"
|
||||||
}
|
}
|
||||||
// console.log(`[LinkHandler] Listening URL has been set to: ${listenURL}`);
|
|
||||||
|
|
||||||
if (app.cfg.get('general.discordClearActivityOnPause') == 1) {
|
// Remove the pause/play icon and test for clear activity on pause
|
||||||
|
if (app.cfg.get('general.discordClearActivityOnPause') == 1) {
|
||||||
delete ActivityObject.smallImageKey
|
delete ActivityObject.smallImageKey
|
||||||
delete ActivityObject.smallImageText
|
delete ActivityObject.smallImageText
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check all the values work
|
// Deletes the timestamp if its not greater than 0
|
||||||
if (!((new Date(attributes.endTime)).getTime() > 0)) {
|
if (!((new Date(attributes.endTime)).getTime() > 0)) {
|
||||||
delete ActivityObject.startTimestamp
|
delete ActivityObject.startTimestamp
|
||||||
delete ActivityObject.endTimestamp
|
delete ActivityObject.endTimestamp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Artist check
|
||||||
if (!attributes.artistName) {
|
if (!attributes.artistName) {
|
||||||
delete ActivityObject.state
|
delete ActivityObject.state
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Album text check
|
||||||
if (!ActivityObject.largeImageText || ActivityObject.largeImageText.length < 2) {
|
if (!ActivityObject.largeImageText || ActivityObject.largeImageText.length < 2) {
|
||||||
delete ActivityObject.largeImageText
|
delete ActivityObject.largeImageText
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Checks if the name is greater than 128 because some songs can be that long
|
||||||
if (ActivityObject.details.length > 128) {
|
if (ActivityObject.details.length > 128) {
|
||||||
AcitivityObject.details = ActivityObject.details.substring(0, 125) + '...'
|
ActivityObject.details = ActivityObject.details.substring(0, 125) + '...'
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear if if needed
|
|
||||||
|
|
||||||
|
|
||||||
|
// Check if its pausing (false) or playing (true)
|
||||||
if (!attributes.status) {
|
if (!attributes.status) {
|
||||||
if (app.cfg.get('general.discordClearActivityOnPause') == 1) {
|
if (app.cfg.get('general.discordClearActivityOnPause') == 1) {
|
||||||
app.discord.clearActivity().catch((e) => console.error(`[DiscordRPC][clearActivity] ${e}`));
|
app.discord.clearActivity().catch((e) => console.error(`[DiscordRPC][clearActivity] ${e}`));
|
||||||
ActivityObject = null
|
ActivityObject = null
|
||||||
} else
|
} else {
|
||||||
{
|
delete ActivityObject.startTimestamp
|
||||||
delete ActivityObject.startTimestamp
|
delete ActivityObject.endTimestamp
|
||||||
delete ActivityObject.endTimestamp
|
ActivityObject.smallImageKey = 'pause'
|
||||||
ActivityObject.smallImageKey = 'pause'
|
ActivityObject.smallImageText = 'Paused'
|
||||||
ActivityObject.smallImageText = 'Paused'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ActivityObject) {
|
|
||||||
|
if (ActivityObject && ActivityObject !== app.discord.activityCache && ActivityObject.details && ActivityObject.state) {
|
||||||
try {
|
try {
|
||||||
// console.log(`[DiscordRPC][setActivity] Setting activity to ${JSON.stringify(ActivityObject)}`);
|
// console.log(`[DiscordRPC][setActivity] Setting activity to ${JSON.stringify(ActivityObject)}`);
|
||||||
app.discord.setActivity(ActivityObject)
|
app.discord.setActivity(ActivityObject)
|
||||||
|
app.discord.activityCache = ActivityObject
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`[DiscordRPC][setActivity] ${err}`)
|
console.error(`[DiscordRPC][setActivity] ${err}`)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue