Fix settings toggles for discord
This commit is contained in:
parent
6480e6ad1e
commit
b57fe0f3ac
4 changed files with 33 additions and 18 deletions
1
index.js
1
index.js
|
@ -10,6 +10,7 @@ const configSchema = {
|
||||||
"close_behavior": 0, // 0 = close, 1 = minimize, 2 = minimize to tray
|
"close_behavior": 0, // 0 = close, 1 = minimize, 2 = minimize to tray
|
||||||
"startup_behavior": 0, // 0 = nothing, 1 = open on startup
|
"startup_behavior": 0, // 0 = nothing, 1 = open on startup
|
||||||
"discord_rpc": 1, // 0 = disabled, 1 = enabled as Cider, 2 = enabled as Apple Music
|
"discord_rpc": 1, // 0 = disabled, 1 = enabled as Cider, 2 = enabled as Apple Music
|
||||||
|
"discordClearActivityOnPause" : 0, // 0 = disabled, 1 = enabled
|
||||||
"volume": 1
|
"volume": 1
|
||||||
},
|
},
|
||||||
"audio": {
|
"audio": {
|
||||||
|
|
|
@ -205,7 +205,7 @@ const CiderBase = {
|
||||||
mpris.connect(win)
|
mpris.connect(win)
|
||||||
|
|
||||||
// Discord
|
// Discord
|
||||||
discord.connect('911790844204437504');
|
discord.connect((app.cfg.get("general.discord_rpc") == 1) ? '911790844204437504' : '886578863147192350');
|
||||||
ipcMain.on('playbackStateDidChange', (_event, a) => {
|
ipcMain.on('playbackStateDidChange', (_event, a) => {
|
||||||
discord.updateActivity(a)
|
discord.updateActivity(a)
|
||||||
mpris.updateState(a)
|
mpris.updateState(a)
|
||||||
|
|
|
@ -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')) return;
|
if (app.cfg.get('general.discord_rpc') == 0) 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"});
|
||||||
|
@ -43,7 +43,7 @@ module.exports = {
|
||||||
* Disconnects from Discord RPC
|
* Disconnects from Discord RPC
|
||||||
*/
|
*/
|
||||||
disconnect: function () {
|
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 {
|
try {
|
||||||
app.discord.destroy().then(() => {
|
app.discord.destroy().then(() => {
|
||||||
|
@ -60,7 +60,7 @@ module.exports = {
|
||||||
* @param {object} attributes
|
* @param {object} attributes
|
||||||
*/
|
*/
|
||||||
updateActivity: function (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) {
|
if (!app.discord.isConnected) {
|
||||||
this.connect()
|
this.connect()
|
||||||
|
@ -87,14 +87,14 @@ module.exports = {
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
if (ActivityObject.largeImageKey == "" || ActivityObject.largeImageKey == null) {
|
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')) {
|
if (app.cfg.get('general.discordClearActivityOnPause') == 1) {
|
||||||
// delete ActivityObject.smallImageKey
|
delete ActivityObject.smallImageKey
|
||||||
// delete ActivityObject.smallImageText
|
delete ActivityObject.smallImageText
|
||||||
// }
|
}
|
||||||
|
|
||||||
// Check all the values work
|
// Check all the values work
|
||||||
if (!((new Date(attributes.endTime)).getTime() > 0)) {
|
if (!((new Date(attributes.endTime)).getTime() > 0)) {
|
||||||
|
@ -113,21 +113,21 @@ module.exports = {
|
||||||
|
|
||||||
// Clear if if needed
|
// Clear if if needed
|
||||||
if (!attributes.status) {
|
if (!attributes.status) {
|
||||||
//if (app.cfg.get('general.discordClearActivityOnPause')) {
|
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) {
|
||||||
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)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`[DiscordRPC][setActivity] ${err}`)
|
console.error(`[DiscordRPC][setActivity] ${err}`)
|
||||||
|
|
|
@ -382,7 +382,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="md-option-header">
|
<div class="md-option-header">
|
||||||
<span>Unfinished / Non Functional</span>
|
<span>Conectivity</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="md-option-line">
|
<div class="md-option-line">
|
||||||
<div class="md-option-segment">
|
<div class="md-option-segment">
|
||||||
|
@ -396,6 +396,20 @@
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</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-line">
|
||||||
<div class="md-option-segment">
|
<div class="md-option-segment">
|
||||||
Enable AudioContext Functionality
|
Enable AudioContext Functionality
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue