Merge remote-tracking branch 'upstream/main' into Prettier

This commit is contained in:
N0chteil 2022-01-07 21:19:24 +01:00
commit 4f6a55bec3
6 changed files with 1703 additions and 2624 deletions

View file

@ -40,7 +40,7 @@ const CiderBase = {
let win = null;
const options = {
icon: join(__dirname, `../../resources/icons/icon.ico`),
icon: join(__dirname, `../../resources/icons/icon.` + (process.platform === "win32" ? "ico" : "png")),
width: mainWindowState.width,
height: mainWindowState.height,
x: mainWindowState.x,

View file

@ -1,48 +1,35 @@
const { app } = require('electron'),
DiscordRPC = require('discord-rpc');
const {app} = require('electron'),
DiscordRPC = require('discord-rpc')
module.exports = {
/**
* Connects to Discord RPC
* @param {string} clientId
*/
connect: function (clientId) {
app.discord = { isConnected: false };
if (app.cfg.get('general.discord_rpc') == 0) return;
app.discord = {isConnected: false};
if (app.cfg.get('general.discord_rpc') == 0 || app.discord.isConnected) return;
DiscordRPC.register(clientId); // Apparently needed for ask to join, join, spectate etc.
const client = new DiscordRPC.Client({ transport: 'ipc' });
app.discord = Object.assign(client, {
error: false,
activityCache: null,
isConnected: false
});
DiscordRPC.register(clientId) // Apparently needed for ask to join, join, spectate etc.
const client = new DiscordRPC.Client({transport: "ipc"});
app.discord = Object.assign(client, {error: false, activityCache: null, isConnected: false});
// Login to Discord
app.discord
.login({ clientId })
app.discord.login({clientId})
.then(() => {
app.discord.isConnected = true;
})
.catch((e) => console.error(`[DiscordRPC][connect] ${e}`));
app.discord.on('ready', () => {
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;
}
});
console.log(`[DiscordRPC][connect] Successfully Connected to Discord. Authed for user: ${client.user.username} (${client.user.id})`);
})
// Handles Errors
app.discord.on('error', (err) => {
app.discord.on('error', err => {
console.error(`[DiscordRPC] ${err}`);
this.disconnect();
this.disconnect()
app.discord.isConnected = false;
});
},
@ -51,21 +38,15 @@ module.exports = {
* Disconnects from Discord RPC
*/
disconnect: function () {
if (app.cfg.get('general.discord_rpc') == 0 || !app.discord.isConnected)
return;
if (app.cfg.get('general.discord_rpc') == 0 || !app.discord.isConnected) return;
try {
app.discord
.destroy()
.then(() => {
app.discord.isConnected = false;
console.log(
'[DiscordRPC][disconnect] Disconnected from discord.'
);
})
.catch((e) => console.error(`[DiscordRPC][disconnect] ${e}`));
app.discord.destroy().then(() => {
app.discord.isConnected = false;
console.log('[DiscordRPC][disconnect] Disconnected from discord.')
}).catch((e) => console.error(`[DiscordRPC][disconnect] ${e}`));
} 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.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.')
const listenURL = `https://applemusicelectron.com/p?id=${attributes.playParams.id}`;
const listenURL = `https://applemusicelectron.com/p?id=${attributes.playParams.id}`
//console.log(attributes)
let ActivityObject = {
details: attributes.name,
state: `by ${attributes.artistName}`,
startTimestamp: attributes.startTime,
endTimestamp: attributes.endTime,
largeImageKey:
attributes.artwork.url
.replace('{w}', '1024')
.replace('{h}', '1024') ?? 'cider',
largeImageKey: (attributes.artwork.url.replace('{w}', '1024').replace('{h}', '1024')) ?? 'cider',
largeImageText: attributes.albumName,
smallImageKey: attributes.status ? 'play' : 'pause',
smallImageText: attributes.status ? 'Playing' : 'Paused',
smallImageKey: (attributes.status ? 'play' : 'pause'),
smallImageText: (attributes.status ? 'Playing' : 'Paused'),
instance: true,
buttons: [{ label: 'Listen on Cider', url: listenURL }]
buttons: [
{label: "Listen on Cider", url: listenURL},
]
};
if (
ActivityObject.largeImageKey == '' ||
ActivityObject.largeImageKey == null
) {
ActivityObject.largeImageKey =
app.cfg.get('general.discord_rpc') == 1 ? 'cider' : 'logo';
if (ActivityObject.largeImageKey == "" || 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) {
delete ActivityObject.smallImageKey;
delete ActivityObject.smallImageText;
delete ActivityObject.smallImageKey
delete ActivityObject.smallImageText
}
// Check all the values work
if (!(new Date(attributes.endTime).getTime() > 0)) {
delete ActivityObject.startTimestamp;
delete ActivityObject.endTimestamp;
// Deletes the timestamp if its not greater than 0
if (!((new Date(attributes.endTime)).getTime() > 0)) {
delete ActivityObject.startTimestamp
delete ActivityObject.endTimestamp
}
// Artist check
if (!attributes.artistName) {
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) + '...';
delete ActivityObject.state
}
// 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 (app.cfg.get('general.discordClearActivityOnPause') == 1) {
app.discord
.clearActivity()
.catch((e) =>
console.error(`[DiscordRPC][clearActivity] ${e}`)
);
ActivityObject = null;
app.discord.clearActivity().catch((e) => console.error(`[DiscordRPC][clearActivity] ${e}`));
ActivityObject = null
} else {
delete ActivityObject.startTimestamp;
delete ActivityObject.endTimestamp;
ActivityObject.smallImageKey = 'pause';
ActivityObject.smallImageText = 'Paused';
delete ActivityObject.startTimestamp
delete ActivityObject.endTimestamp
ActivityObject.smallImageKey = 'pause'
ActivityObject.smallImageText = 'Paused'
}
}
if (ActivityObject) {
if (ActivityObject && ActivityObject !== app.discord.activityCache && ActivityObject.details && ActivityObject.state) {
try {
// console.log(`[DiscordRPC][setActivity] Setting activity to ${JSON.stringify(ActivityObject)}`);
app.discord.setActivity(ActivityObject);
app.discord.setActivity(ActivityObject)
app.discord.activityCache = ActivityObject
} catch (err) {
console.error(`[DiscordRPC][setActivity] ${err}`);
console.error(`[DiscordRPC][setActivity] ${err}`)
}
}
}
};
},
}

View 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

View file

@ -289,7 +289,7 @@
}
},
{
"icon": "./assets/feather/x-circle.svg",
"icon": "./assets/feather/unheart.svg",
"id": "unlove",
"name": "Unlove",
"disabled": true,

View file

@ -356,7 +356,7 @@
}
},
{
"icon": "./assets/feather/x-circle.svg",
"icon": "./assets/feather/unheart.svg",
"id": "unlove",
"name": "Unlove",
"disabled": true,