-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
89 lines (78 loc) · 1.83 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
const electron = require("electron");
const { app, BrowserWindow, Tray } = electron;
const path = require("path");
const width = 600;
const height = 600;
var window, tray;
function createWindow(url) {
window = new BrowserWindow({
width: width,
height: height,
frame: false,
alwaysOnTop: true,
webPreferences: {
backgroundThrottling: false,
},
});
window.loadURL(url);
window.hide();
window.on("blur", () => {
window.hide();
});
}
function trayOnClick() {
if (window.isVisible()) {
window.hide();
} else {
showWindow();
}
}
function alignWindow() {
const position = calculateWindowPosition();
window.setBounds({
width: width,
height: height,
x: position.x,
y: position.y,
});
}
function showWindow() {
alignWindow();
window.show();
}
function calculateWindowPosition() {
const windowBounds = window.getBounds();
const trayBounds = tray.getBounds();
// Mac OS: set window position below the tray icon
if (process.platform === "darwin") {
return {
x: trayBounds.x + trayBounds.width / 2 - window.getBounds().width / 2,
y: trayBounds.y,
};
}
// others: return its default position
return windowBounds;
}
app.setAboutPanelOptions({
applicationName: "Go Playtime",
applicationVersion: "0.0.1",
version: "1",
});
app.on("ready", () => {
createWindow("https://play.golang.org");
tray = new Tray(path.join(__dirname, "/assets/icon.png"));
tray.on("click", trayOnClick);
});
// Quit when all windows are closed.
app.on("window-all-closed", () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== "darwin") {
app.quit();
}
});
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length !== 0) {
showWindow();
}
});