diff options
author | lawncable.gitlab@simonlaux.de <lawncable.gitlab@simonlaux.de> | 2019-03-16 07:34:53 +0100 |
---|---|---|
committer | lawncable.gitlab@simonlaux.de <lawncable.gitlab@simonlaux.de> | 2019-03-16 07:34:53 +0100 |
commit | 25b567314d42a1906836cf7dc9fe0e38c3996996 (patch) | |
tree | 6b5df3ec2220795aac19b7d60d8ccc8ad95545f2 /src | |
parent | 477f017eb25308c3bdcea148245457c296b7fb2f (diff) | |
download | electron-25b567314d42a1906836cf7dc9fe0e38c3996996.tar.gz electron-25b567314d42a1906836cf7dc9fe0e38c3996996.tar.bz2 electron-25b567314d42a1906836cf7dc9fe0e38c3996996.tar.xz electron-25b567314d42a1906836cf7dc9fe0e38c3996996.zip |
add experimental rich presence
Diffstat (limited to 'src')
-rw-r--r-- | src/main.ts | 8 | ||||
-rw-r--r-- | src/main/manaplus/manaplus.ts | 1 | ||||
-rw-r--r-- | src/main/richpresence.ts | 99 | ||||
-rw-r--r-- | src/main/status.ts | 10 |
4 files changed, 89 insertions, 29 deletions
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; } |