forked from Night-N3twork/Umbra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
83 lines (67 loc) · 1.77 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
import { app, BrowserWindow } from "electron";
import server from "./src/server.js";
import DiscordRPC from 'discord-rpc';
// Start the server
server.start();
let mainWindow;
function createWindow() {
mainWindow = new BrowserWindow({
width: 1200,
height: 700,
name: "Umbra MP3 Player",
icon: './public/assets/imgs/main.png',
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
},
});
mainWindow.loadURL("http://localhost:8080");
mainWindow.on("closed", function () {
mainWindow = null;
});
// Handle window resize
mainWindow.on("resize", function () {
let [x, y] = mainWindow.getSize();
mainWindow.setSize(x, y);
});
}
app.on("ready", createWindow);
app.on("window-all-closed", function () {
if (process.platform !== "darwin") {
app.quit();
}
});
app.on("activate", function () {
if (mainWindow === null) {
createWindow();
}
});
const clientId = '1260399266510405745';
// Only needed if you want to use spectate, join, or ask to join
DiscordRPC.register(clientId);
const rpc = new DiscordRPC.Client({ transport: 'ipc' });
const startTimestamp = new Date();
async function setActivity() {
if (!rpc || !mainWindow) {
return;
}
// You'll need to have snek_large and snek_small assets uploaded to
// https://discord.com/developers/applications/<application_id>/rich-presence/assets
rpc.setActivity({
details: `Vibing to Music`,
state: 'Listening to Music',
startTimestamp,
largeImageKey: 'index',
largeImageText: 'Umbra',
smallImageText: 'Umbra',
instance: false,
});
}
rpc.on('ready', () => {
setActivity();
// activity can only be set every 15 seconds
setInterval(() => {
setActivity();
}, 15e3);
});
rpc.login({ clientId }).catch(console.error);