-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from asoji/discord-rpc
Discord Rich Presence
- Loading branch information
Showing
6 changed files
with
175 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const DiscordRPC = require(`discord-rpc`); | ||
const pkg = require(`../package.json`); | ||
|
||
const clientId = `997378700611952660`; | ||
|
||
let client = null; | ||
|
||
let projectTimestamp = new Date(); | ||
let projectDetails = `Loading...`; | ||
|
||
module.exports._test = () => { | ||
console.log(projectDetails); | ||
}; | ||
|
||
module.exports.setDetails = text => { | ||
projectDetails = text; | ||
|
||
if (client == null) setup(); | ||
else setActivity(); | ||
}; | ||
|
||
module.exports.resetTime = () => { | ||
projectTimestamp = new Date(); | ||
|
||
if (client == null) setup(); | ||
else setActivity(); | ||
}; | ||
|
||
module.exports.destroy = () => { | ||
if (client == null) return; | ||
client.destroy(); | ||
}; | ||
|
||
function setup() { | ||
client = new DiscordRPC.Client({ transport: `ipc` }); | ||
|
||
client.on(`ready`, () => { | ||
setActivity(); | ||
}); | ||
|
||
client.login({ clientId }).catch(console.error); | ||
} | ||
|
||
function setActivity() { | ||
if (client != null) client.setActivity({ | ||
details: projectDetails, | ||
startTimestamp: projectTimestamp, | ||
largeImageKey: `logo`, | ||
largeImageText: `v${pkg.version}`, | ||
instance: false | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
const { contextBridge, ipcRenderer } = require(`electron`); | ||
const pkg = require(`../package.json`); | ||
const drpc = require(`./drpc.js`); | ||
|
||
const appVersion = `Node Studio ${pkg.version}`; | ||
|
||
function setWinTitle(text) { | ||
function setProjectTitle(text) { | ||
document.title = `${text} | ${appVersion}`; | ||
drpc.setDetails(text); | ||
} | ||
|
||
window.addEventListener(`DOMContentLoaded`, () => { | ||
document.querySelector(`#version`).innerHTML = appVersion; | ||
}); | ||
|
||
contextBridge.exposeInMainWorld(`memUsage`, process.memoryUsage); | ||
contextBridge.exposeInMainWorld(`setWinTitle`, setWinTitle); | ||
contextBridge.exposeInMainWorld(`setProjectTitle`, setProjectTitle); | ||
contextBridge.exposeInMainWorld(`DRPCResetTime`, drpc.resetTime); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters