Fix settings toggles for discord

This commit is contained in:
vapormusic 2021-12-28 10:55:44 +07:00
parent 6480e6ad1e
commit b57fe0f3ac
4 changed files with 33 additions and 18 deletions

View file

@ -10,6 +10,7 @@ const configSchema = {
"close_behavior": 0, // 0 = close, 1 = minimize, 2 = minimize to tray
"startup_behavior": 0, // 0 = nothing, 1 = open on startup
"discord_rpc": 1, // 0 = disabled, 1 = enabled as Cider, 2 = enabled as Apple Music
"discordClearActivityOnPause" : 0, // 0 = disabled, 1 = enabled
"volume": 1
},
"audio": {

View file

@ -205,7 +205,7 @@ const CiderBase = {
mpris.connect(win)
// Discord
discord.connect('911790844204437504');
discord.connect((app.cfg.get("general.discord_rpc") == 1) ? '911790844204437504' : '886578863147192350');
ipcMain.on('playbackStateDidChange', (_event, a) => {
discord.updateActivity(a)
mpris.updateState(a)

View file

@ -9,7 +9,7 @@ module.exports = {
*/
connect: function (clientId) {
app.discord = {isConnected: false};
if (!app.cfg.get('general.discord_rpc')) return;
if (app.cfg.get('general.discord_rpc') == 0) return;
DiscordRPC.register(clientId) // Apparently needed for ask to join, join, spectate etc.
const client = new DiscordRPC.Client({transport: "ipc"});
@ -43,7 +43,7 @@ module.exports = {
* Disconnects from Discord RPC
*/
disconnect: function () {
if (!app.cfg.get('general.discord_rpc') || !app.discord.isConnected) return;
if (app.cfg.get('general.discord_rpc') == 0 || !app.discord.isConnected) return;
try {
app.discord.destroy().then(() => {
@ -60,7 +60,7 @@ module.exports = {
* @param {object} attributes
*/
updateActivity: function (attributes) {
if (!app.cfg.get('general.discord_rpc')) return;
if (app.cfg.get('general.discord_rpc') == 0) return;
if (!app.discord.isConnected) {
this.connect()
@ -87,14 +87,14 @@ module.exports = {
]
};
if (ActivityObject.largeImageKey == "" || ActivityObject.largeImageKey == null) {
ActivityObject.largeImageKey = "cider"
ActivityObject.largeImageKey = (app.cfg.get("general.discord_rpc") == 1) ? "cider" : "logo"
}
//console.log(`[LinkHandler] Listening URL has been set to: ${listenURL}`);
// console.log(`[LinkHandler] Listening URL has been set to: ${listenURL}`);
// if (app.cfg.get('general.discordClearActivityOnPause')) {
// delete ActivityObject.smallImageKey
// delete ActivityObject.smallImageText
// }
if (app.cfg.get('general.discordClearActivityOnPause') == 1) {
delete ActivityObject.smallImageKey
delete ActivityObject.smallImageText
}
// Check all the values work
if (!((new Date(attributes.endTime)).getTime() > 0)) {
@ -113,21 +113,21 @@ module.exports = {
// Clear if if needed
if (!attributes.status) {
//if (app.cfg.get('general.discordClearActivityOnPause')) {
// app.discord.clearActivity().catch((e) => console.error(`[DiscordRPC][clearActivity] ${e}`));
// ActivityObject = null
// } else
// {
if (app.cfg.get('general.discordClearActivityOnPause') == 1) {
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'
//}
}
}
if (ActivityObject) {
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)
} catch (err) {
console.error(`[DiscordRPC][setActivity] ${err}`)

View file

@ -382,7 +382,7 @@
</div>
</div>
<div class="md-option-header">
<span>Unfinished / Non Functional</span>
<span>Conectivity</span>
</div>
<div class="md-option-line">
<div class="md-option-segment">
@ -396,6 +396,20 @@
</select>
</div>
</div>
<div class="md-option-line">
<div class="md-option-segment">
Clear Discord RPC on Pause
</div>
<div class="md-option-segment md-option-segment_auto">
<select class="md-select" v-model="app.cfg.general.discordClearActivityOnPause">
<option value="0">Disabled</option>
<option value="1">Enabled</option>
</select>
</div>
</div>
<div class="md-option-header">
<span>Unfinished / Non Functional</span>
</div>
<div class="md-option-line">
<div class="md-option-segment">
Enable AudioContext Functionality