-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
74 lines (59 loc) · 1.6 KB
/
main.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
const { app, BrowserWindow } = require("electron");
const path = require('path');
let win;
function createWindow() {
win = new BrowserWindow({
width: 1000,
height: 820,
icon: __dirname + "/app/resources/icons/logo.png",
webPreferences: {
nodeIntegration: true
}
});
console.log(win.setThumbarButtons([
{
tooltip: 'prev',
icon: path.join(__dirname, 'prev.png'),
click () { console.log('prev') },
},
{
tooltip: 'play',
icon: path.join(__dirname, 'play.png'),
click () { console.log('play') },
},
{
tooltip: 'next',
icon: path.join(__dirname, 'next.png'),
click () { console.log('next') },
}
]));
win.loadFile("app/index.html");
}
app.whenReady().then(createWindow);
const DiscordRPC = require('discord-rpc');
// myyrelin vanha id tms. const clientId = '764187560418344980';
const clientId = "1017170358610174004"; // hillon uus id, toimiva
const rpc = new DiscordRPC.Client({ transport: 'ipc' });
const startTimestamp = new Date();
async function setActivity() {
if (!rpc || !win) {
return;
}
const title = await win.webContents.executeJavaScript('window.playing');
const time = await win.webContents.executeJavaScript('window.time');
rpc.setActivity({
details: `Listening to music (${time})`,
state: title,
startTimestamp,
instance: false,
largeImageKey: 'https://i.imgur.com/nvUMVHt.png',
});
}
rpc.on('ready', () => {
setActivity();
// activity can only be set every 15 seconds
setInterval(() => {
setActivity();
}, 15e3);
});
rpc.login({ clientId }).catch(console.error);