Skip to content

Commit

Permalink
handle discordrpc disconnects better
Browse files Browse the repository at this point in the history
  • Loading branch information
axellse committed Aug 31, 2024
1 parent 4e9025b commit 8b82592
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions helpers/misc/discordRpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,19 @@ import { setPlayStatus } from '../player/playStatus.js';
import { config } from '../../snippets/config.js';

let ep
let connected = false

if (process.argv[2] == 'launch') {
let lastActivity

if (process.argv[2] == 'launch' && config['discordRpcEnabled']) {
ep = new _ep.EasyPresence("1263923824613920861")

ep.on('connected', () => {
connected = true
setPlayStatus('important', 'Connected to Discord.')
setTimeout(() => {
setPlayStatus("report", {
'special' : 'idling'
})
if (!lastActivity) return
setPlayStatus("report", lastActivity)
}, 500) //wait a little before starting discordrpc
})
ep.on('disconnected', () => connected = false)
}

export function changeRpcStatus(title, thumbnail, id, idling = false) {
Expand All @@ -32,7 +30,6 @@ export function changeRpcStatus(title, thumbnail, id, idling = false) {
},
timestamps: { start: new Date() },
}

if (!idling) {
activity['buttons'] = [
{
Expand All @@ -42,5 +39,6 @@ export function changeRpcStatus(title, thumbnail, id, idling = false) {
]
}

lastActivity = activity
ep.setActivity(activity)
}

0 comments on commit 8b82592

Please sign in to comment.