-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
101 lines (85 loc) · 2.75 KB
/
index.js
File metadata and controls
101 lines (85 loc) · 2.75 KB
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
const { app, BrowserWindow, screen, Menu, shell } = require("electron");
const { autoUpdater } = require("electron-updater")
const fs = require("fs");
const template = require("./menu");
const DiscordRPC = require("discord-rpc");
var window;
const clientId = "693476070229409874";
var rpcReady = false;
var activity = {
details: "Idle",
state: `In Menu`,
startTimestamp: Date.now(),
largeImageKey: "hordes_icon",
largeImageText: "Hordes.io",
instance: false
};
function createWindow() {
autoUpdater.checkForUpdatesAndNotify()
const { width, height } = screen.getPrimaryDisplay().workAreaSize;
window = new BrowserWindow({
width,
height,
useContentSize: true,
webPreferences: {
nodeIntegration: true
}
});
const menu = Menu.buildFromTemplate(template(app, window));
Menu.setApplicationMenu(menu);
window.loadURL("https://hordes.io/login", {
userAgent:
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36"
});
window.webContents.on("did-finish-load", function() {
fs.readFile(__dirname + "/style.css", function(e, d) {
window.webContents.insertCSS(d.toString());
});
});
window.webContents.on("did-start-navigation", function(e, u) {
if (u == "https://hordes.io/play") {
activity.state = "Playing";
activity.details = "Guardstone";
activity.startTimestamp = Date.now();
} else if (u == "https://hordes.io/") {
activity.state = "Idle";
activity.details = "In Menu";
activity.startTimestamp = Date.now();
} else if (u == "https://hordes.io/worldeditor") {
activity.state = "Making Maps";
activity.details = "World Editor";
activity.startTimestamp = Date.now();
}
if (rpcReady) {
setActivity();
}
});
window.webContents.on("new-window", function(e, url) {
e.preventDefault();
shell.openExternal(url);
});
window.on("closed", () => {
window = null;
});
}
app.on("ready", createWindow);
app.on("window-all-closed", () => {
// if (process.platform !== "darwin") {
app.quit();
// }
});
app.on("activate", () => {
if (window === null) {
createWindow();
}
});
DiscordRPC.register(clientId);
const rpc = new DiscordRPC.Client({ transport: "ipc" });
async function setActivity() {
rpc.setActivity(activity);
}
rpc.on("ready", () => {
rpcReady = true;
setActivity();
});
rpc.login({ clientId }).catch(console.error);