-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
91 lines (78 loc) · 1.88 KB
/
app.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
const { app, BrowserWindow, globalShortcut, Tray, Menu, shell } = require("electron");
const config = require("./config");
const clipboard = require("./clipboard");
const path = require("path");
let friday = null;
let tray = null;
let isActive = true;
var configValid = config.initialise();
app.on("ready", () => {
friday = new BrowserWindow({
width: 720,
height: 540,
backgroundColor: null,
show: true,
frame: false,
resizable: false,
transparent: true,
center: true,
webPreferences: {
enableRemoteModule: true,
nodeIntegration: true,
},
});
tray = new Tray(path.join(__dirname, "./icons/tray.ico"));
var contextMenu = Menu.buildFromTemplate([
{
label: "Show Friday",
click: function () {
friday.show();
},
},
{
label: "Quit",
click: function () {
app.quit();
},
},
]);
tray.setContextMenu(contextMenu);
friday.on("hide", () => {
isActive = false;
friday.webContents.send("clear-state");
});
friday.on("show", () => {
isActive = true;
});
friday.on("blur", () => {
isActive = false;
if (process.env.NODE_ENV !== "development") {
friday.hide();
}
});
friday.webContents.on("new-window", function (e, url) {
e.preventDefault();
shell.openExternal(url);
});
globalShortcut.register("Control+Space", () => {
if (isActive) {
friday.hide();
} else {
friday.show();
}
});
friday.loadURL(path.join(__dirname, "src/index.html"));
friday.webContents.once("dom-ready", () => {
friday.webContents.send("config-validation", configValid);
});
friday.webContents.on("did-finish-load", () => {
clipboard.watch((items) => {
if (items) {
friday.webContents.send("clipboard-update", items);
}
});
});
friday.once("ready-to-show", () => {
friday.show();
});
});