This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
76 lines (60 loc) · 1.55 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
const { app, BrowserWindow } = require('electron');
const path = require('path');
const url = require('url');
const { Client } = require('discord-rpc');
const config = require('./config.json');
let mainWindow;
function createWindow() {
mainWindow = new BrowserWindow({
width: 650,
height: 650,
resizable: false,
titleBarStyle: 'hidden',
});
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'mainWindow', 'index.html'),
protocol: 'file:',
slashes: true,
}));
mainWindow.on('closed', () => {
mainWindow = null;
});
}
app.on('ready', createWindow);
app.on('window-all-closed', () => {
app.quit();
});
app.on('activate', () => {
if (mainWindow === null) {
createWindow();
}
});
const clientId = config.clientId;
const rpc = new Client({ transport: 'ipc' });
let startedTimestamp = new Date();
async function setActivity() {
if (!rpc || !mainWindow) {
return;
}
const values = await mainWindow.webContents.executeJavaScript('window.values');
if(!values.timestamp)
startedTimestamp = undefined;
rpc.setActivity({
details: values.title,
state: values.state,
startTimestamp: startedTimestamp,
largeImageKey: values.largeImageKey,
largeImageText: values.largeImageText,
smallImageKey: values.smallImageKey,
smallImageText: values.smallImageText,
instance: false
});
}
rpc.on('ready', () => {
setActivity();
console.log('Ready')
setInterval(() => {
setActivity();
}, 15e3);
});
rpc.login(clientId).catch(console.error);