mirror of
https://github.com/dscalzi/HeliosLauncher.git
synced 2024-12-23 04:02:14 -08:00
810e81521c
Linted the entire project. Using different rules for the script files as there are a lot of undefined variables just because of the way the DOM's global scope works. Mostly just code cleanup, however the linter did catch a minor bug with a settings regex. That has been corrected.
46 lines
1.5 KiB
JavaScript
46 lines
1.5 KiB
JavaScript
// Work in progress
|
|
const {Client} = require('discord-rpc')
|
|
|
|
let client
|
|
let activity
|
|
|
|
exports.initRPC = function(genSettings, servSettings, initialDetails = 'Waiting for Client..'){
|
|
client = new Client({ transport: 'ipc' })
|
|
|
|
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
|
|
}
|
|
|
|
client.on('ready', () => {
|
|
console.log('%c[Discord Wrapper]', 'color: #a02d2a; font-weight: bold', 'Discord RPC Connected')
|
|
client.setActivity(activity)
|
|
})
|
|
|
|
client.login({clientId: genSettings.clientId}).catch(error => {
|
|
if(error.message.includes('ENOENT')) {
|
|
console.log('%c[Discord Wrapper]', 'color: #a02d2a; font-weight: bold', 'Unable to initialize Discord Rich Presence, no client detected.')
|
|
} else {
|
|
console.log('%c[Discord Wrapper]', 'color: #a02d2a; font-weight: bold', 'Unable to initialize Discord Rich Presence: ' + error.message, error)
|
|
}
|
|
})
|
|
}
|
|
|
|
exports.updateDetails = function(details){
|
|
activity.details = details
|
|
client.setActivity(activity)
|
|
}
|
|
|
|
exports.shutdownRPC = function(){
|
|
if(!client) return
|
|
client.clearActivity()
|
|
client.destroy()
|
|
client = null
|
|
activity = null
|
|
} |