summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLawnCable <git@lawncable.net>2021-03-01 03:03:08 +0100
committerLawnCable <git@lawncable.net>2021-03-01 03:03:08 +0100
commit1ece0228b13809e0ea3879bba0525e271a2b9586 (patch)
tree7ced3ac33f2c1caff5d11bb090ee0fc9df9cfff4
parentf123c8c3406d78daca9d30f2c0b243e400e6c228 (diff)
downloadelectron-1ece0228b13809e0ea3879bba0525e271a2b9586.tar.gz
electron-1ece0228b13809e0ea3879bba0525e271a2b9586.tar.bz2
electron-1ece0228b13809e0ea3879bba0525e271a2b9586.tar.xz
electron-1ece0228b13809e0ea3879bba0525e271a2b9586.zip
change rich presence part a bit
and use discord-rpc directly
-rw-r--r--package-lock.json74
-rw-r--r--package.json4
-rw-r--r--src/main.ts10
-rw-r--r--src/main/richpresence.ts60
4 files changed, 62 insertions, 86 deletions
diff --git a/package-lock.json b/package-lock.json
index d7f9990..bc6b66f 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -110,6 +110,12 @@
"defer-to-connect": "^1.0.1"
}
},
+ "@types/discord-rpc": {
+ "version": "3.0.4",
+ "resolved": "https://registry.npmjs.org/@types/discord-rpc/-/discord-rpc-3.0.4.tgz",
+ "integrity": "sha512-Ee0vt82qcg05OeJrQZ/YN+NQwaBCnAul1rVLYaMLPkwR5f44WC3BpBQNvn5Z3Axu9szaVOHqXEDBI+uAXAiyrg==",
+ "dev": true
+ },
"@types/fs-extra": {
"version": "9.0.7",
"resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-9.0.7.tgz",
@@ -296,11 +302,6 @@
"integrity": "sha512-NW2cX8m1Q7KPA7a5M2ULQeZ2wR5qI5PAbw5L0UOMxdioVk9PMZ0h1TmyZEkPYrCvYjDlFICusOu1dlEKAAeXBw==",
"dev": true
},
- "async-limiter": {
- "version": "1.0.0",
- "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz",
- "integrity": "sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg=="
- },
"asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
@@ -843,51 +844,13 @@
"dev": true,
"optional": true
},
- "discord-rich-presence": {
- "version": "0.0.8",
- "resolved": "https://registry.npmjs.org/discord-rich-presence/-/discord-rich-presence-0.0.8.tgz",
- "integrity": "sha512-IpVMPjv15C9UvppxvrrGdv6bzQHOW1P1vLoMH15HvdJwGJ3dBd2bnrJ63Uy36YRUfrAMxGLiwUDHncvC8AuPaQ==",
- "requires": {
- "discord-rpc": "github:discordjs/rpc"
- },
- "dependencies": {
- "discord-rpc": {
- "version": "github:discordjs/rpc#60ddddc38d2bd3ffe6df91e518ac7974239562b5",
- "from": "github:discordjs/rpc",
- "requires": {
- "node-fetch": "^2.6.1",
- "ws": "^7.3.1"
- },
- "dependencies": {
- "ws": {
- "version": "7.4.3",
- "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.3.tgz",
- "integrity": "sha512-hr6vCR76GsossIRsr8OLR9acVVm1jyfEWvhbNjtgPOrfvAlKzvyeg/P6r8RuDjRyrcQoPQT7K0DGEPc7Ae6jzA=="
- }
- }
- },
- "node-fetch": {
- "version": "2.6.1",
- "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz",
- "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw=="
- },
- "ws": {
- "version": "6.1.4",
- "resolved": "https://registry.npmjs.org/ws/-/ws-6.1.4.tgz",
- "integrity": "sha512-eqZfL+NE/YQc1/ZynhojeV8q+H050oR8AZ2uIev7RU10svA9ZnJUddHcOUZTJLinZ9yEfdA2kSATS2qZK5fhJA==",
- "requires": {
- "async-limiter": "~1.0.0"
- }
- }
- }
- },
"discord-rpc": {
- "version": "3.0.1",
- "resolved": "https://registry.npmjs.org/discord-rpc/-/discord-rpc-3.0.1.tgz",
- "integrity": "sha512-PvkVpIlbFowih2mPIOAwUlX+w+9AGtpVUpQrGP6Mu7TPHDjfclsYoRuquIYiSHsS/n5EfhFgMZfsSTRPkvj22w==",
+ "version": "3.2.0",
+ "resolved": "https://registry.npmjs.org/discord-rpc/-/discord-rpc-3.2.0.tgz",
+ "integrity": "sha512-KJv0EVbGMlr04HoG6f5b3wD7X9kSHzQ2Ed2qfHSDvYJ1MkE8RbCQmMcQQrSvAxpfsqZgUjB/bsfi/mjyicCH+A==",
"requires": {
- "node-fetch": "^2.1.2",
- "ws": "^5.2.1"
+ "node-fetch": "^2.6.1",
+ "ws": "^7.3.1"
}
},
"dmg-builder": {
@@ -1812,9 +1775,9 @@
"integrity": "sha512-479Bjw9nTE5DdBSZZWprFryHGjUaQC31y1wHo19We/k0BZlrmhqQitWoUL0cD8+scljCbIUL+E58oRDEakdGGA=="
},
"node-fetch": {
- "version": "2.3.0",
- "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.3.0.tgz",
- "integrity": "sha512-MOd8pV3fxENbryESLgVIeaGKrdl+uaYhCSSVkjeOb/31/njTpcis5aWfdqgNlHIrKOLRbMnfPINPOML2CIFeXA=="
+ "version": "2.6.1",
+ "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz",
+ "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw=="
},
"normalize-url": {
"version": "4.5.0",
@@ -2798,12 +2761,9 @@
}
},
"ws": {
- "version": "5.2.2",
- "resolved": "https://registry.npmjs.org/ws/-/ws-5.2.2.tgz",
- "integrity": "sha512-jaHFD6PFv6UgoIVda6qZllptQsMlDEJkTQcybzzXDYM1XO9Y8em691FGMPmM46WGyLU4z9KMgQN+qrux/nhlHA==",
- "requires": {
- "async-limiter": "~1.0.0"
- }
+ "version": "7.4.3",
+ "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.3.tgz",
+ "integrity": "sha512-hr6vCR76GsossIRsr8OLR9acVVm1jyfEWvhbNjtgPOrfvAlKzvyeg/P6r8RuDjRyrcQoPQT7K0DGEPc7Ae6jzA=="
},
"xdg-basedir": {
"version": "3.0.0",
diff --git a/package.json b/package.json
index 8204fea..112260c 100644
--- a/package.json
+++ b/package.json
@@ -17,6 +17,7 @@
"author": "LawnCable",
"license": "GNU GPLv3",
"devDependencies": {
+ "@types/discord-rpc": "^3.0.4",
"@types/fs-extra": "^9.0.7",
"@types/node": "^14.14.31",
"electron": "^11.3.0",
@@ -35,8 +36,7 @@
},
"dependencies": {
"chmod": "^0.2.1",
- "discord-rich-presence": "0.0.8",
- "discord-rpc": "^3.0.1",
+ "discord-rpc": "^3.2.0",
"extract-zip": "^2.0.1",
"fs-extra": "^9.1.0",
"prettier": "^2.2.1",
diff --git a/src/main.ts b/src/main.ts
index 90164b0..70ceca5 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -100,7 +100,15 @@ ipcMain.on("debug", (event: any, arg: any) => {
import { Status, EventEmitter } from "./main/status";
-import { quit as drpcQuit } from "./main/richpresence";
+import { quit as drpcQuit, setup as setupRichPresence } from "./main/richpresence";
+
+app.on("ready", async ()=>{
+ try {
+ await setupRichPresence()
+ } catch (error) {
+ console.warn("could not connect to discord rich presence")
+ }
+})
app.on("quit", () => {
drpcQuit();
diff --git a/src/main/richpresence.ts b/src/main/richpresence.ts
index 75acfdf..c50c84f 100644
--- a/src/main/richpresence.ts
+++ b/src/main/richpresence.ts
@@ -1,7 +1,7 @@
import { Status } from "./status";
+import { Client, register } from "discord-rpc"
// Only for testing as of right now -> Experimental
const ClientId = "551884486351126528";
-const DiscordRPC = require("discord-rich-presence")(ClientId);
const slogans = [
"free OpenSource 2D MMORPG",
@@ -33,6 +33,8 @@ const dataSet: {
},
};
+let DiscordRPC_Client:Client = null;
+
async function setActivity() {
const status = Status.getStatus();
@@ -46,7 +48,9 @@ async function setActivity() {
: `🎮 ${data.name} 🎮`;
const logo = data && data.logo;
- DiscordRPC.updatePresence({
+ // IDEA maybe check if changed before updating to save traffic?
+
+ DiscordRPC_Client?.setActivity({
state: `»${slogan}«`,
details,
largeImageKey: logo,
@@ -60,38 +64,42 @@ async function setActivity() {
//joinSecret: 'string',
//spectateSecret: 'string',
//startTimestamp
- });
+ }).catch(console.error);
}
-DiscordRPC.on("connected", () => {
- setActivity();
+export async function setup(): Promise<void>{
+ register(ClientId)
+ DiscordRPC_Client = await (new Client({transport: 'ipc'})).connect(ClientId)
- // activity can only be set every 15 seconds
- setInterval(() => {
+ DiscordRPC_Client.on("ready", () => {
setActivity();
- }, 15e3);
-});
-
-DiscordRPC.on("error", console.log);
-
-DiscordRPC.on("join", (secret: string) => {
- console.log("we should join with", secret);
-});
+
+ // activity can only be set every 15 seconds
+ setInterval(() => {
+ setActivity();
+ }, 15e3);
+ });
-DiscordRPC.on("spectate", (secret: string) => {
- console.log("we should spectate with", secret);
-});
+ DiscordRPC_Client.subscribe("ACTIVITY_JOIN", (secret: string) => {
+ console.log("we should join with", secret);
+ });
+
+ DiscordRPC_Client.subscribe("ACTIVITY_SPECTATE", (secret: string) => {
+ console.log("we should spectate with", secret);
+ });
+
+ // client.subscribe('ACTIVITY_JOIN_REQUEST', (user) => {
+ // if (user.discriminator === '1337') {
+ // client.sendJoinInvite(user);
+ // } else {
+ // client.closeJoinRequest(user);
+ // }
+ // });
+}
-// DiscordRPC.on('joinRequest', (user) => {
-// if (user.discriminator === '1337') {
-// DiscordRPC.reply(user, 'YES');
-// } else {
-// DiscordRPC.reply(user, 'IGNORE');
-// }
-// });
export function quit() {
- DiscordRPC.disconnect();
+ DiscordRPC_Client?.destroy();
console.log("Shutting down Discord RPC integration");
}