-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmain.js
177 lines (160 loc) · 4.35 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
"use strict";
console.log("main process working");
const electron = require("electron");
const path = require("path");
const { app, BrowserWindow, Menu, shell } = electron;
let splash;
require("electron-reload")(__dirname, {
electron: path.join(__dirname, "node_modules", ".bin", "electron"),
hardResetMethod: "exit",
});
app.on("ready", () => {
// Main window properties
let mainWindow = new BrowserWindow({
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true,
},
height: 800,
width: 1500,
minWidth: 1100,
minHeight: 800,
show: false,
icon: __dirname + "/assets/logos/Image Lab Icon.png",
frame: false,
titleBarStyle: "hidden",
});
// Splash window properties
splash = new BrowserWindow({
width: 600,
height: 400,
transparent: true,
frame: false,
alwaysOnTop: true,
icon: __dirname + "/assets/logos/Image Lab Icon.png",
});
splash.loadURL(`file://${__dirname}/splash.html`);
mainWindow.loadURL(`file://${__dirname}/index.html`);
// This line needs to removed after the development
mainWindow.webContents.openDevTools();
// when main window is loaded and ready to be displayed, splash will end and main winndow appears
mainWindow.once("ready-to-show", () => {
setTimeout(function () {
splash.destroy();
mainWindow.show();
}, 3000);
});
mainWindow.on("closed", function () {
mainWindow = null;
});
// Saving window opens when user try to exit from application to warn him if he wants to save/don't save his work
mainWindow.on("close", function (e) {
const choice = require("electron").dialog.showMessageBoxSync(this, {
type: "question",
buttons: ["Save", "Don't save", "Cancel"],
title: "Image Lab",
message: "Do you want to save changes to ........ ?",
});
if (choice == 2) {
e.preventDefault();
}
});
});
// The new menu configuration
const isMac = process.platform === "darwin";
const template = [
// { role: 'appMenu' }
...(isMac
? [
{
label: app.name,
submenu: [
{ role: "about" },
{ type: "separator" },
{ role: "services" },
{ type: "separator" },
{ role: "hide" },
{ role: "hideothers" },
{ role: "unhide" },
{ type: "separator" },
{ role: "quit" },
],
},
]
: []),
// { role: 'fileMenu' }
{
label: "File",
submenu: [
{ label: "New File" },
{ label: "Open File" },
{ label: "Save" },
isMac ? { role: "close" } : { role: "quit" },
],
},
// { role: 'viewMenu' }
{
label: "View",
submenu: [
{ role: "reload" },
{ role: "forceReload" },
{ role: "toggleDevTools" },
{ label: "Zoom in" },
{ label: "Zoom out" },
{ label: "Center blocks" },
],
},
{
role: "help",
submenu: [
{ label: "Tutorials" },
{
label: "About",
click() {
aboutWindowPreview();
},
},
{
label: "Learn More",
click: async () => {
const { shell } = require("electron");
await shell.openExternal("https://github.com/scorelab/imagelab");
},
},
],
},
];
const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
// function called when we need to show about window
function aboutWindowPreview() {
// About-window properties
let aboutWindow = new BrowserWindow({
height: 520,
width: 600,
title: "About",
resizable: false,
minimizable: false,
fullscreenable: false,
show: false,
autoHideMenuBar: true,
icon: __dirname + "/assets/logos/Image Lab Icon.png",
});
aboutWindow.loadURL(`file://${__dirname}/about.html`);
aboutWindow.show();
aboutWindow.on("closed", function () {
aboutWindow = null;
});
// this part solves the problem of opening links in about window in the same window
// so when you click a link in about menu, it opens in an external user default browser
aboutWindow.webContents.on("new-window", function (e, url) {
// make sure local urls stay in electron perimeter
if ("file://" === url.substr(0, "file://".length)) {
return;
}
// and open every other protocols on the browser
e.preventDefault();
shell.openExternal(url);
});
}