-
Notifications
You must be signed in to change notification settings - Fork 32
/
index.js
119 lines (99 loc) · 2.49 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//config
let production = true;
let version = 4;
//dependencies
const rpc = require('discord-rich-presence')('387406899739623426');
const request = require('request');
const { app, BrowserWindow, ipcMain } = require('electron');
const url = require('url');
const path = require('path');
let mainWindow;
let data;
function createWindow() {
mainWindow = new BrowserWindow({
width: 900,
height: 600,
frame: false,
webPreferences: {
nodeIntegration: true
}
});
mainWindow.setMenu(null);
request('http://nintenbot.js.org/rpc.json', function(err, res, body) {
if (err || !body) {
mainWindow.loadFile('no-server.html');
}
try {
data = JSON.parse(body);
mainWindow.loadFile('index.html')
}
catch(e) {
mainWindow.loadFile('no-server.html')
}
});
}
app.whenReady().then(createWindow);
ipcMain.on('getGameData', function(event) {
let gameArray = [];
data.gameLibrary.forEach(function(game) {
gameArray.push(game.name);
});
gameArray.sort();
event.sender.send('sendingGameData', gameArray);
});
ipcMain.on('x', function() {
app.quit();
});
ipcMain.on('max', function () {
if (!mainWindow) return;
if (mainWindow.isMaximized()) return mainWindow.unmaximize();
else return mainWindow.maximize();
});
ipcMain.on('min', function() {
if (!mainWindow) return;
mainWindow.minimize();
});
let name;
let desc;
//catch values
ipcMain.on('game:value', function(e, value) {
name = value;
});
ipcMain.on('desc:value', function (e, value) {
desc = value;
findGame();
});
let status = "online";
ipcMain.on("online", function() {
status = "online";
findGame();
});
ipcMain.on("away", function() {
status = "away";
findGame();
});
//RPC
function findGame() {
let gotGame = name;
let pic = "switch";
if (!name || !desc) return;
data.gameLibrary.forEach(function(game) {
game.aliases.forEach(function(alias) {
if (alias === name.toLowerCase()) {
gotGame = game.name;
pic = game.pic;
}
});
});
setPresence(gotGame, desc, pic, status);
}
function setPresence(game, desc, pic, status) {
rpc.updatePresence({
state: desc,
details: game,
largeImageKey: pic,
largeImageText: game,
smallImageKey: status,
smallImageText: status.charAt(0).toUpperCase() + status.slice(1)
})
}