-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
100 lines (82 loc) · 2.28 KB
/
main.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
const { app, BrowserWindow } = require("electron");
const colors = require("colors");
const bcrypt = require("bcryptjs");
console.log(colors.rainbow("ciao ciao"));
bcrypt.hash("myPassword", 10, (err, hash) =>
console.log("myPassword hashed:", hash)
);
console.log("App is ready:", app.isReady());
setTimeout(() => {
console.log("App is ready after 2s:", app.isReady());
}, 2000);
// prevent garbage collector
let mainWindow, secondaryWindow;
const createWindow = () => {
// main window properties
mainWindow = new BrowserWindow({
width: 1000,
heoght: 800,
webPreferences: { nodeIntegration: true },
//show: false // set true when ready to show
backgroundColor: "#2c92f9"
});
// main window properties
secondaryWindow = new BrowserWindow({
width: 600,
heoght: 300,
webPreferences: { nodeIntegration: true },
//show: false // set true when ready to show
backgroundColor: "#2c92f9",
parent: mainWindow,
modal: false,
frame: false
});
// load index file in main window
mainWindow.loadFile("index.html");
secondaryWindow.loadFile("secondary.html");
// load url (deprecated)
//mainWindow.loadURL("https://mariolazzari.it");
// open dev tools
//mainWindow.webContents.openDevTools();
// subscribe ready to show event
//mainWindow.once("ready-to-show", mainWindow.show);
// subscribe close event
mainWindow.on("close", () => (mainWindow = null));
secondaryWindow.on("close", () => (mainWindow = null));
};
// before quit event
/*
app.on("before-quit", e => {
console.log("prevent default quit");
e.preventDefault();
console.log("save data and manual quit.");
app.quit();
});
*/
// window blur
app.on("browser-window-blur", () => {
console.log("App unfocused");
});
app.on("browser-window-focus", () => {
console.log("App focused.");
});
// window focused
// app is ready
app.on("ready", () => {
console.log("App is ready.", app.isReady());
console.log("desktop", app.getPath("desktop"));
console.log("user data", app.getPath("userData"));
console.log("temp", app.getPath("temp"));
createWindow();
});
// quit on all windows closed
app.on("window-all-closed", () => {
if (process.platform === "darwin") {
app.quit();
}
});
app.on("activate", () => {
if (mainWindow === null) {
createWindow();
}
});