-
Notifications
You must be signed in to change notification settings - Fork 13
/
index.js
executable file
·107 lines (83 loc) · 2.38 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
const electron = require("electron");
const filesystem = require("fs");
const path = require("path");
const Menu = require("./modules/Menu");
const Storage = require("./modules/Storage");
// require("electron-debug");
require("electron-dl")();
let mainWindow = null;
let isQuitting = false;
if (!electron.app.requestSingleInstanceLock()) {
electron.app.quit();
return;
}
electron.app.on("second-instance", () => {
if (!mainWindow)
return;
if (mainWindow.isMinimized())
mainWindow.restore();
mainWindow.show();
});
electron.ipcMain.on("count-badges-result", (event, data) => {
if (typeof electron.app.setBadgeCount === "function")
electron.app.setBadgeCount(isNaN(data) ? 0 : data);
});
function createMainWindow() {
const lastWindowState = Storage.get("lastWindowState") || {width: 900, height: 675};
const browser = new electron.BrowserWindow({
width: lastWindowState.width,
height: lastWindowState.height,
x: lastWindowState.x,
y: lastWindowState.y,
minWidth: 600,
minHeight: 450,
title: electron.app.getName(),
show: false,
autoHideMenuBar: true,
titleBarStyle: "hiddenInset",
webPreferences: {
nodeIntegration: false,
preload: path.join(__dirname, "inject/app.js")
}
});
browser.on("page-title-updated", (event, title) => {
if (!title.includes("New message"))
return;
browser.webContents.send("count-badges");
});
browser.on("close", event => {
if (isQuitting)
return;
event.preventDefault();
if (process.platform === "darwin")
electron.app.hide();
else
electron.app.quit();
});
browser.loadURL("https://web.groupme.com/signin", {userAgent: "Chrome"});
browser.webContents.on("dom-ready", () => {
browser.webContents.insertCSS(filesystem.readFileSync(path.join(__dirname, "inject/app.css"), "utf8"));
browser.show();
});
browser.webContents.on("new-window", (event, url) => {
event.preventDefault();
electron.shell.openExternal(url);
});
return browser;
}
electron.app.on("ready", () => {
electron.Menu.setApplicationMenu(Menu);
if (!mainWindow)
mainWindow = createMainWindow();
});
electron.app.on("activate", () => {
if (!mainWindow)
mainWindow = createMainWindow();
mainWindow.show();
mainWindow.send("count-badges");
});
electron.app.on("before-quit", () => {
isQuitting = true;
if (mainWindow && !mainWindow.isFullScreen())
Storage.set("lastWindowState", mainWindow.getBounds());
});