Skip to content

Commit

Permalink
Added Discord Rich Presence for The Launcher
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardKanshen authored Feb 26, 2024
2 parents f80e7b4 + 24f6af3 commit bd6871c
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 10 deletions.
66 changes: 64 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
const { app, BrowserWindow, shell } = require('electron');
require('@electron/remote/main').initialize()
const DiscordRPC = require('discord-rpc');
const path = require('node:path');
const fs = require('fs');

let mainWindow;

const createWindow = () => {
const mainWindow = new BrowserWindow({
mainWindow = new BrowserWindow({
minWidth: 400,
minHeight: 300,
height: 600,
Expand All @@ -28,7 +32,7 @@ const createWindow = () => {
return { action: 'deny' }; // Prevent opening a new window in Electron
});
}
app.whenReady().then(() => {-7
app.whenReady().then(() => {
createWindow();

app.on('activate', function () {
Expand All @@ -39,3 +43,61 @@ app.whenReady().then(() => {-7
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit();
});

var version, clientID = "1211721853324890143", rpc = new DiscordRPC.Client({ transport: 'ipc' }), startTime = new Date();
fs.readFile(path.join(__dirname, 'package.json'), 'utf8', (err, data) => {
if (err) {
console.error(err);
return;
}
const JSONData = JSON.parse(data)
// handle the json data here
console.log(JSONData.version);
version = JSONData.version;
});

/*function setRPC() {
console.log("setting activity");
rpc.setActivity({
details: `running version v0.0.0-RPC`,
startTimestamp: startTime,
largeImageKey: 'deadcodelogo',
largeImageText: 'made by deadcode',
});
}
rpc.on('ready', () => {
setRPC();
});
rpc.login({ clientID }).catch(console.error);*/



async function setActivity() {
if (!rpc || !mainWindow) {
return;
}

// You'll need to have snek_large and snek_small assets uploaded to
// https://discord.com/developers/applications/<application_id>/rich-presence/assets
rpc.setActivity({
details: `the launcher by deadcode.`,
state: `running version ${version}.`,
startTimestamp: startTime,
largeImageKey: 'deadcodelogo',
largeImageText: 'made by deadcode',
instance: false,
});
}

rpc.on('ready', () => {
setActivity();

// activity can only be set every 15 seconds
setInterval(() => {
setActivity();
}, 15e3);
});

rpc.login({ clientId: clientID }).catch(console.error);
104 changes: 100 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "deadforge",
"version": "v0.0.0Fix",
"version": "v0.0.0RPC",
"description": "An Electron Launcher for DeadCode Projects.",
"main": "main.js",
"scripts": {
Expand All @@ -18,8 +18,8 @@
"appId": "dev.deadcode.forge",
"productName": "DeadForge",
"win": {
"target": "nsis",
"artifactName": "dev.deadcode.forge-${version}.${ext}"
"target": "nsis",
"artifactName": "dev.deadcode.forge-${version}.${ext}"
},
"mac": {
"target": "dmg",
Expand All @@ -31,6 +31,7 @@
}
},
"dependencies": {
"@electron/remote": "^2.1.2"
"@electron/remote": "^2.1.2",
"discord-rpc": "^4.0.1"
}
}

0 comments on commit bd6871c

Please sign in to comment.