Merge remote-tracking branch 'upstream/main' into Prettier
This commit is contained in:
commit
4f6a55bec3
6 changed files with 1703 additions and 2624 deletions
|
@ -40,7 +40,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,
|
||||||
|
|
|
@ -1,48 +1,35 @@
|
||||||
const {app} = require('electron'),
|
const {app} = require('electron'),
|
||||||
DiscordRPC = require('discord-rpc');
|
DiscordRPC = require('discord-rpc')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connects to Discord RPC
|
* Connects to Discord RPC
|
||||||
* @param {string} clientId
|
* @param {string} clientId
|
||||||
*/
|
*/
|
||||||
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"});
|
||||||
app.discord = Object.assign(client, {
|
app.discord = Object.assign(client, {error: false, activityCache: null, isConnected: false});
|
||||||
error: false,
|
|
||||||
activityCache: null,
|
|
||||||
isConnected: false
|
|
||||||
});
|
|
||||||
|
|
||||||
// Login to Discord
|
// Login to Discord
|
||||||
app.discord
|
app.discord.login({clientId})
|
||||||
.login({ clientId })
|
|
||||||
.then(() => {
|
.then(() => {
|
||||||
app.discord.isConnected = true;
|
app.discord.isConnected = true;
|
||||||
})
|
})
|
||||||
.catch((e) => console.error(`[DiscordRPC][connect] ${e}`));
|
.catch((e) => console.error(`[DiscordRPC][connect] ${e}`));
|
||||||
|
|
||||||
app.discord.on('ready', () => {
|
app.discord.on('ready', () => {
|
||||||
console.log(
|
console.log(`[DiscordRPC][connect] Successfully Connected to Discord. Authed for user: ${client.user.username} (${client.user.id})`);
|
||||||
`[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
|
||||||
app.discord.on('error', (err) => {
|
app.discord.on('error', err => {
|
||||||
console.error(`[DiscordRPC] ${err}`);
|
console.error(`[DiscordRPC] ${err}`);
|
||||||
this.disconnect();
|
this.disconnect()
|
||||||
app.discord.isConnected = false;
|
app.discord.isConnected = false;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -51,21 +38,15 @@ module.exports = {
|
||||||
* Disconnects from Discord RPC
|
* Disconnects from Discord RPC
|
||||||
*/
|
*/
|
||||||
disconnect: function () {
|
disconnect: function () {
|
||||||
if (app.cfg.get('general.discord_rpc') == 0 || !app.discord.isConnected)
|
if (app.cfg.get('general.discord_rpc') == 0 || !app.discord.isConnected) return;
|
||||||
return;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
app.discord
|
app.discord.destroy().then(() => {
|
||||||
.destroy()
|
|
||||||
.then(() => {
|
|
||||||
app.discord.isConnected = false;
|
app.discord.isConnected = false;
|
||||||
console.log(
|
console.log('[DiscordRPC][disconnect] Disconnected from discord.')
|
||||||
'[DiscordRPC][disconnect] Disconnected from discord.'
|
}).catch((e) => console.error(`[DiscordRPC][disconnect] ${e}`));
|
||||||
);
|
|
||||||
})
|
|
||||||
.catch((e) => console.error(`[DiscordRPC][disconnect] ${e}`));
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -77,87 +58,85 @@ 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}`
|
||||||
//console.log(attributes)
|
//console.log(attributes)
|
||||||
let ActivityObject = {
|
let ActivityObject = {
|
||||||
details: attributes.name,
|
details: attributes.name,
|
||||||
state: `by ${attributes.artistName}`,
|
state: `by ${attributes.artistName}`,
|
||||||
startTimestamp: attributes.startTime,
|
startTimestamp: attributes.startTime,
|
||||||
endTimestamp: attributes.endTime,
|
endTimestamp: attributes.endTime,
|
||||||
largeImageKey:
|
largeImageKey: (attributes.artwork.url.replace('{w}', '1024').replace('{h}', '1024')) ?? 'cider',
|
||||||
attributes.artwork.url
|
|
||||||
.replace('{w}', '1024')
|
|
||||||
.replace('{h}', '1024') ?? 'cider',
|
|
||||||
largeImageText: attributes.albumName,
|
largeImageText: attributes.albumName,
|
||||||
smallImageKey: attributes.status ? 'play' : 'pause',
|
smallImageKey: (attributes.status ? 'play' : 'pause'),
|
||||||
smallImageText: attributes.status ? 'Playing' : 'Paused',
|
smallImageText: (attributes.status ? 'Playing' : 'Paused'),
|
||||||
instance: true,
|
instance: true,
|
||||||
buttons: [{ label: 'Listen on Cider', url: listenURL }]
|
buttons: [
|
||||||
|
{label: "Listen on Cider", url: listenURL},
|
||||||
|
]
|
||||||
};
|
};
|
||||||
if (
|
if (ActivityObject.largeImageKey == "" || ActivityObject.largeImageKey == null) {
|
||||||
ActivityObject.largeImageKey == '' ||
|
ActivityObject.largeImageKey = (app.cfg.get("general.discord_rpc") == 1) ? "cider" : "logo"
|
||||||
ActivityObject.largeImageKey == null
|
|
||||||
) {
|
|
||||||
ActivityObject.largeImageKey =
|
|
||||||
app.cfg.get('general.discord_rpc') == 1 ? 'cider' : 'logo';
|
|
||||||
}
|
}
|
||||||
// console.log(`[LinkHandler] Listening URL has been set to: ${listenURL}`);
|
|
||||||
|
|
||||||
|
// Remove the pause/play icon and test for clear activity on pause
|
||||||
if (app.cfg.get('general.discordClearActivityOnPause') == 1) {
|
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
|
||||||
}
|
|
||||||
if (
|
|
||||||
!ActivityObject.largeImageText ||
|
|
||||||
ActivityObject.largeImageText.length < 2
|
|
||||||
) {
|
|
||||||
delete ActivityObject.largeImageText;
|
|
||||||
}
|
|
||||||
if (ActivityObject.details.length > 128) {
|
|
||||||
AcitivityObject.details =
|
|
||||||
ActivityObject.details.substring(0, 125) + '...';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear if if needed
|
// Album text check
|
||||||
|
if (!ActivityObject.largeImageText || ActivityObject.largeImageText.length < 2) {
|
||||||
|
delete ActivityObject.largeImageText
|
||||||
|
}
|
||||||
|
|
||||||
|
// Checks if the name is greater than 128 because some songs can be that long
|
||||||
|
if (ActivityObject.details.length > 128) {
|
||||||
|
ActivityObject.details = ActivityObject.details.substring(0, 125) + '...'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 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
|
app.discord.clearActivity().catch((e) => console.error(`[DiscordRPC][clearActivity] ${e}`));
|
||||||
.clearActivity()
|
ActivityObject = null
|
||||||
.catch((e) =>
|
|
||||||
console.error(`[DiscordRPC][clearActivity] ${e}`)
|
|
||||||
);
|
|
||||||
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}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
6
src/renderer/assets/feather/unheart.svg
Normal file
6
src/renderer/assets/feather/unheart.svg
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||||
|
<svg width="100%" height="100%" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill:currentColor;fill-rule:evenodd;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;">
|
||||||
|
<path d="M20.84,4.61C19.809,3.578 18.409,2.998 16.95,2.998C15.491,2.998 14.091,3.578 13.06,4.61L12,5.67L10.94,4.61C9.909,3.579 8.508,2.999 7.05,2.999C4.032,2.999 1.549,5.482 1.549,8.5C1.549,9.958 2.129,11.359 3.16,12.39L12,21.23L20.84,12.39C21.872,11.359 22.452,9.959 22.452,8.5C22.452,7.041 21.872,5.641 20.84,4.61Z" style="fill:none;fill-rule:nonzero;stroke:currentColor;stroke-width:2px;"/>
|
||||||
|
<path d="M12,5.67L14.614,9.632L10.399,12.114L14.536,14.354L12,20.013" style="fill:none;stroke:currentColor;stroke-width:2px;stroke-miterlimit:1.5;"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 1,021 B |
File diff suppressed because it is too large
Load diff
|
@ -289,7 +289,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"icon": "./assets/feather/x-circle.svg",
|
"icon": "./assets/feather/unheart.svg",
|
||||||
"id": "unlove",
|
"id": "unlove",
|
||||||
"name": "Unlove",
|
"name": "Unlove",
|
||||||
"disabled": true,
|
"disabled": true,
|
||||||
|
|
|
@ -356,7 +356,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"icon": "./assets/feather/x-circle.svg",
|
"icon": "./assets/feather/unheart.svg",
|
||||||
"id": "unlove",
|
"id": "unlove",
|
||||||
"name": "Unlove",
|
"name": "Unlove",
|
||||||
"disabled": true,
|
"disabled": true,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue