summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlawncable.gitlab@simonlaux.de <lawncable.gitlab@simonlaux.de>2019-03-16 07:34:53 +0100
committerlawncable.gitlab@simonlaux.de <lawncable.gitlab@simonlaux.de>2019-03-16 07:34:53 +0100
commit25b567314d42a1906836cf7dc9fe0e38c3996996 (patch)
tree6b5df3ec2220795aac19b7d60d8ccc8ad95545f2
parent477f017eb25308c3bdcea148245457c296b7fb2f (diff)
downloadelectron-25b567314d42a1906836cf7dc9fe0e38c3996996.tar.gz
electron-25b567314d42a1906836cf7dc9fe0e38c3996996.tar.bz2
electron-25b567314d42a1906836cf7dc9fe0e38c3996996.tar.xz
electron-25b567314d42a1906836cf7dc9fe0e38c3996996.zip
add experimental rich presence
-rw-r--r--package-lock.json123
-rw-r--r--package.json4
-rw-r--r--src/main.ts8
-rw-r--r--src/main/manaplus/manaplus.ts1
-rw-r--r--src/main/richpresence.ts99
-rw-r--r--src/main/status.ts10
6 files changed, 165 insertions, 80 deletions
diff --git a/package-lock.json b/package-lock.json
index 2f43e32..8d948b8 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
{
"name": "mana-launcher",
- "version": "1.0.1",
+ "version": "1.0.2",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@@ -149,6 +149,14 @@
"chainsaw": "~0.1.0"
}
},
+ "bindings": {
+ "version": "1.5.0",
+ "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz",
+ "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==",
+ "requires": {
+ "file-uri-to-path": "1.0.0"
+ }
+ },
"bluebird": {
"version": "3.5.1",
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.1.tgz",
@@ -340,9 +348,9 @@
"dev": true
},
"decompress-zip": {
- "version": "0.3.0",
- "resolved": "https://registry.npmjs.org/decompress-zip/-/decompress-zip-0.3.0.tgz",
- "integrity": "sha1-rjvLfjTGWHmt/nfhnDD4ZgK0vbA=",
+ "version": "0.3.2",
+ "resolved": "https://registry.npmjs.org/decompress-zip/-/decompress-zip-0.3.2.tgz",
+ "integrity": "sha512-Ab1QY4LrWMrUuo53lLnmGOby7v8ryqxJ+bKibKSiPisx+25mhut1dScVBXAYx14i/PqSrFZvR2FRRazhLbvL+g==",
"dev": true,
"requires": {
"binary": "^0.3.0",
@@ -365,33 +373,41 @@
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk="
},
- "discord-rpc": {
- "version": "3.0.0-beta.10",
- "resolved": "https://registry.npmjs.org/discord-rpc/-/discord-rpc-3.0.0-beta.10.tgz",
- "integrity": "sha512-b0G6O0WJkxoLQSopyNRqByXCrpBL68HXPMULVZXLjRgj+sStwOmbABM+HwBDJWF6s/uhkB/+cAgq+19x4w0SPA==",
+ "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.js": "github:discordjs/discord.js#25b654d49428c9c93841f0680022bc73869ec724",
- "snekfetch": "^3.5.8"
- }
- },
- "discord.js": {
- "version": "github:discordjs/discord.js#25b654d49428c9c93841f0680022bc73869ec724",
- "from": "discord.js@github:discordjs/discord.js#25b654d49428c9c93841f0680022bc73869ec724",
- "requires": {
- "pako": "^1.0.0",
- "prism-media": "^0.2.0",
- "snekfetch": "^3.6.0",
- "tweetnacl": "^1.0.0",
- "ws": "^4.0.0"
+ "discord-rpc": "github:discordjs/rpc#60ddddc38d2bd3ffe6df91e518ac7974239562b5"
},
"dependencies": {
- "tweetnacl": {
- "version": "1.0.0",
- "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.0.tgz",
- "integrity": "sha1-cT2LgY2kIGh0C/aDhtBHnmb8ins="
+ "discord-rpc": {
+ "version": "github:discordjs/rpc#60ddddc38d2bd3ffe6df91e518ac7974239562b5",
+ "from": "github:discordjs/rpc",
+ "requires": {
+ "node-fetch": "^2.3.0",
+ "ws": "^6.1.1"
+ }
+ },
+ "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==",
+ "requires": {
+ "node-fetch": "^2.1.2",
+ "ws": "^5.2.1"
+ }
+ },
"ecc-jsbn": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.1.tgz",
@@ -694,6 +710,11 @@
"pend": "~1.2.0"
}
},
+ "file-uri-to-path": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz",
+ "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw=="
+ },
"find-up": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/find-up/-/find-up-1.1.2.tgz",
@@ -1216,14 +1237,14 @@
"dev": true
},
"mksnapshot": {
- "version": "0.3.1",
- "resolved": "https://registry.npmjs.org/mksnapshot/-/mksnapshot-0.3.1.tgz",
- "integrity": "sha1-JQHAVldDbXQs6Vik/5LHfkDdN+Y=",
+ "version": "0.3.5",
+ "resolved": "https://registry.npmjs.org/mksnapshot/-/mksnapshot-0.3.5.tgz",
+ "integrity": "sha512-PSBoZaj9h9myC3uRRW62RxmX8mrN3XbOkMEyURUD7v5CeJgtYTar50XU738t7Q0LtG1pBPtp5n5QwDGggRnEvw==",
"dev": true,
"requires": {
- "decompress-zip": "0.3.0",
+ "decompress-zip": "0.3.x",
"fs-extra": "0.26.7",
- "request": "^2.79.0"
+ "request": "2.x"
},
"dependencies": {
"fs-extra": {
@@ -1261,6 +1282,16 @@
"integrity": "sha1-GVoh1sRuNh0vsSgbo4uR6d9727M=",
"dev": true
},
+ "node-addon-api": {
+ "version": "1.6.2",
+ "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-1.6.2.tgz",
+ "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=="
+ },
"nodeify": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/nodeify/-/nodeify-1.0.1.tgz",
@@ -1380,11 +1411,6 @@
"integrity": "sha1-y8ec26+P1CKOE/Yh8rGiN8GyB7M=",
"dev": true
},
- "pako": {
- "version": "1.0.6",
- "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.6.tgz",
- "integrity": "sha512-lQe48YPsMJAig+yngZ87Lus+NF+3mtu7DVOBu6b/gHO1YpKwIj5AWjZ/TOS7i46HD/UixzWb1zeWDZfGZ3iYcg=="
- },
"parse-author": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/parse-author/-/parse-author-2.0.0.tgz",
@@ -1487,11 +1513,6 @@
"meow": "^3.1.0"
}
},
- "prism-media": {
- "version": "0.2.1",
- "resolved": "https://registry.npmjs.org/prism-media/-/prism-media-0.2.1.tgz",
- "integrity": "sha512-Kfp1+6gzjY6X8mqKHa6D3brX+BtMUPFwzAkz4zgtVPgbkA2XxhITROdfQXVurU4fuJsylFRwqo7ciQlQCm9hAw=="
- },
"process-nextick-args": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz",
@@ -1593,6 +1614,14 @@
"strip-indent": "^1.0.1"
}
},
+ "register-scheme": {
+ "version": "github:devsnek/node-register-scheme#e7cc9a63a1f512565da44cb57316d9fb10750e17",
+ "from": "github:devsnek/node-register-scheme",
+ "requires": {
+ "bindings": "^1.3.0",
+ "node-addon-api": "^1.3.0"
+ }
+ },
"repeating": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/repeating/-/repeating-2.0.1.tgz",
@@ -1702,11 +1731,6 @@
"string-width": "^1.0.1"
}
},
- "snekfetch": {
- "version": "3.6.4",
- "resolved": "https://registry.npmjs.org/snekfetch/-/snekfetch-3.6.4.tgz",
- "integrity": "sha512-NjxjITIj04Ffqid5lqr7XdgwM7X61c/Dns073Ly170bPQHLm6jkmelye/eglS++1nfTWktpP6Y2bFXjdPlQqdw=="
- },
"spdx-correct": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.0.0.tgz",
@@ -1983,12 +2007,11 @@
"dev": true
},
"ws": {
- "version": "4.1.0",
- "resolved": "https://registry.npmjs.org/ws/-/ws-4.1.0.tgz",
- "integrity": "sha512-ZGh/8kF9rrRNffkLFV4AzhvooEclrOH0xaugmqGsIfFgOE/pIz4fMc4Ef+5HSQqTEug2S9JZIWDR47duDSLfaA==",
+ "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",
- "safe-buffer": "~5.1.0"
+ "async-limiter": "~1.0.0"
}
},
"xml2js": {
diff --git a/package.json b/package.json
index 7eb8bef..4555cb8 100644
--- a/package.json
+++ b/package.json
@@ -30,9 +30,11 @@
"@types/extract-zip": "^1.6.2",
"@types/fs-extra": "^5.0.2",
"chmod": "^0.2.1",
- "discord-rpc": "^3.0.0-beta.10",
+ "discord-rich-presence": "0.0.8",
+ "discord-rpc": "^3.0.1",
"extract-zip": "^1.6.6",
"fs-extra": "^6.0.1",
+ "register-scheme": "github:devsnek/node-register-scheme",
"request": "^2.87.0",
"request-progress": "^3.0.0",
"xml2js": "^0.4.19"
diff --git a/src/main.ts b/src/main.ts
index 5200d0b..9009b6f 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -1,3 +1,4 @@
+import * as path from 'path';
import { app, BrowserWindow, ipcMain, remote, Tray, Menu, dialog } from 'electron';
// Keep a global reference of the window object, if you don't, the window will
@@ -80,10 +81,10 @@ import {Status, EventEmitter} from './main/status';
-//import {quit as drpcQuit} from './main/richpresence';
+import {quit as drpcQuit} from './main/richpresence';
app.on('quit', () => {
- //drpcQuit();
+ drpcQuit();
if (appIcon) appIcon.destroy()
});
@@ -158,14 +159,13 @@ ManaPlus.init();
ipcMain.on('play', async (event:any, arg:any) => {
if(Status.getStatus().playing)return;
//console.log("play", arg);
+ Status.setGameStatus({server: arg.address})
Status.setPlaying(true);
await ManaPlus.start(arg);
//Status.showError("Failed To Launch Mana Plus","Not implemented yet!","Launch Manaplus faild: Not Implemented");
return false;
});
-import * as path from 'path';
-
ipcMain.on('dragFileOut', (event:any, filepath:any) => {
event.sender.startDrag({
file: filepath,
diff --git a/src/main/manaplus/manaplus.ts b/src/main/manaplus/manaplus.ts
index 5de7d01..7573c84 100644
--- a/src/main/manaplus/manaplus.ts
+++ b/src/main/manaplus/manaplus.ts
@@ -90,6 +90,7 @@ please check you network connection first.", e.message, "Launch preparation fail
EventEmitter.emit('openTray');
await runManaProgram(params,ManaPlusInstance.startCommand,args.address);
// On Close
+ Status.setGameStatus({server: "Launcher"})
Status.setGameRunning(false);
Status.setPlaying(false);
Status.removeActivity();
diff --git a/src/main/richpresence.ts b/src/main/richpresence.ts
index 4ef8f42..93d9f9a 100644
--- a/src/main/richpresence.ts
+++ b/src/main/richpresence.ts
@@ -1,32 +1,65 @@
-// Only for testing as of right now
-const DiscordRPC = require('discord-rpc');
+import {Status} from './status';
+// Only for testing as of right now -> Experimental
+const ClientId = '551884486351126528';
+const DiscordRPC = require('discord-rich-presence')(ClientId);
-const ClientId = '447258715586822154';
+const slogans = [
+ 'free OpenSource 2D MMORPG',
+ 'Community made',
+ 'Join a Server or start your own'
+]
+const dataSet:
+{[key:string]:{name:string, logo:string, description:string}} = {
+ 'server.tmw2.org':{
+ name: 'Moubootaur Legends',
+ logo: 'tmw2',
+ description: 'Playing on Moubootaur Legends ⎛tmw2.org⎠'
+ },
+ 'world.evolonline.org':{
+ name: 'Evol Online',
+ logo: 'evol',
+ description: 'Playing on Evol Online ⎛evolonline.org⎠'
+ },
+ 'server.themanaworld.org':{
+ name: 'The Mana World',
+ logo: 'tmw',
+ description: 'Playing on The Mana World ⎛themanaworld.org⎠'
+ },
+ 'noServer':{
+ name: 'Manaplus',
+ logo: 'manaplus',
+ description: 'Playing on any of the M+ servers'
+ }
+ }
-DiscordRPC.register(ClientId);
+async function setActivity() {
+ const status = Status.getStatus()
-const rpc = new DiscordRPC.Client({ transport: 'ipc' });
-const startTimestamp = new Date();
+ const slogan = slogans[Math.floor(Math.random() * slogans.length)]
-async function setActivity() {
- if (!rpc)
- return false;
-
- rpc.setActivity({
- details: `booped times`,
- startTimestamp,
- largeImageKey: 'connect',
- largeImageText: 'Currently on map xy',
- // smallImageKey: 'snek_small',
- // smallImageText: 'i am my own pillows',
- partySize:2, //TODO get online players
- partyMax:999,
- partyId:"ae488379-351d-4a4f-ad32-2b9b01c91657",
- joinSecret:"MTI4NzM0OjFpMmhuZToxMjMxMjM="
+ const data = dataSet[status.gameStatus.server]
+
+ const details = status.gameStatus.server === 'Launcher' ? 'in Launcher Menu' : `🎮 ${data.name} 🎮`
+ const logo = data && data.logo
+
+ DiscordRPC.updatePresence({
+ state: `»${slogan}«`,
+ details,
+ largeImageKey: logo,
+ largeImageText: data && data.description,
+ //smallImageKey: ,
+ //smallImageText: 'string',
+ //partyId: 'ae488379-351d-4a4f-ad32-2b9b01c91657',
+ //partySize: 1,
+ //partyMax: 999,
+ //matchSecret: 'string',
+ //joinSecret: 'string',
+ //spectateSecret: 'string',
+ //startTimestamp
});
}
-rpc.on('ready', () => {
+DiscordRPC.on('connected', () => {
setActivity();
// activity can only be set every 15 seconds
@@ -35,11 +68,27 @@ rpc.on('ready', () => {
}, 15e3);
});
-rpc.login(ClientId).catch(console.error);
+DiscordRPC.on("error", console.log);
-rpc.subscribe("",console.log);
+DiscordRPC.on('join', (secret:string) => {
+ console.log('we should join with', secret);
+});
+
+DiscordRPC.on('spectate', (secret:string) => {
+ console.log('we should spectate with', secret);
+});
+
+// DiscordRPC.on('joinRequest', (user) => {
+// if (user.discriminator === '1337') {
+// DiscordRPC.reply(user, 'YES');
+// } else {
+// DiscordRPC.reply(user, 'IGNORE');
+// }
+// });
export function quit(){
- rpc.destroy();
+ DiscordRPC.disconnect();
console.log("Shutting down Discord RPC integration");
}
+
+process.on('unhandledRejection', console.error); \ No newline at end of file
diff --git a/src/main/status.ts b/src/main/status.ts
index fb99b35..2e59d0f 100644
--- a/src/main/status.ts
+++ b/src/main/status.ts
@@ -7,6 +7,9 @@ type STATUS = {
ActivityIsError:boolean,
playing:boolean,
gameRunning:boolean,
+ gameStatus:{
+ server: string
+ }
}
const status:STATUS = {
@@ -15,6 +18,9 @@ const status:STATUS = {
playing:false, //Is manaplus starting or started
ActivityIsError:false,
gameRunning:false,
+ gameStatus: {
+ server: "Launcher"
+ }
}
export namespace Status {
@@ -50,6 +56,10 @@ export namespace Status {
status.playing=playing;
updateStatus();
}
+ export function setGameStatus(gameStatus:{ server: string }){
+ status.gameStatus=gameStatus;
+ updateStatus();
+ }
export function getStatus():STATUS{
return status;
}