mirror of
https://github.com/dscalzi/HeliosLauncher.git
synced 2024-10-31 19:36:39 -07:00
50 lines
1.5 KiB
JavaScript
50 lines
1.5 KiB
JavaScript
// Work in progress
|
|
const {Client} = require('discord-rpc')
|
|
const ConfigManager = require('./configmanager.js')
|
|
|
|
let rpc
|
|
let activity
|
|
|
|
exports.initRPC = function(genSettings, servSettings, initialDetails = 'Waiting for Client..'){
|
|
rpc = new Client({ transport: 'ipc' })
|
|
|
|
rpc.on('ready', () => {
|
|
activity = {
|
|
details: initialDetails,
|
|
state: 'Server: ' + servSettings.shortId,
|
|
largeImageKey: servSettings.largeImageKey,
|
|
largeImageText: servSettings.largeImageText,
|
|
smallImageKey: genSettings.smallImageKey,
|
|
smallImageText: genSettings.smallImageText,
|
|
startTimestamp: new Date().getTime() / 1000,
|
|
instance: false
|
|
}
|
|
|
|
rpc.setActivity(activity)
|
|
})
|
|
|
|
rpc.login(genSettings.clientID).catch(error => {
|
|
if(error.message.includes('ENOENT')) {
|
|
console.log('Unable to initialize Discord Rich Presence, no client detected.')
|
|
} else {
|
|
console.log('Unable to initialize Discord Rich Presence: ' + error.message, error)
|
|
}
|
|
})
|
|
}
|
|
|
|
exports.updateDetails = function(details){
|
|
if(activity == null){
|
|
console.error('Discord RPC is not initialized and therefore cannot be updated.')
|
|
}
|
|
activity.details = details
|
|
rpc.setActivity(activity)
|
|
}
|
|
|
|
exports.shutdownRPC = function(){
|
|
if(!rpc) return
|
|
// Workaround until discord rpc releases clearActivity()
|
|
rpc.request('SET_ACTIVITY', {pid: process.pid})
|
|
rpc.destroy()
|
|
rpc = null
|
|
activity = null
|
|
} |