-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.ts
141 lines (129 loc) · 2.92 KB
/
main.ts
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
const { app, BrowserWindow, Menu, dialog } = require("electron");
const url = require("url");
const path = require("path");
let mainWindow;
let ipcm = require("electron").ipcMain;
const isMac = process.platform === "darwin";
function createWindow() {
mainWindow = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true,
},
icon: __dirname + "/logo.png",
});
// mainWindow.setIcon("./logo.png");
mainWindow.maximize();
mainWindow.show();
mainWindow.loadURL(
url.format({
pathname: path.join(__dirname, "/dist/index.html"),
protocol: "file:",
slashes: true,
})
);
mainWindow.on("close", function (e) {
var choice = dialog.showMessageBoxSync(this, {
type: "question",
buttons: ["Yes", "No"],
title: "Confirm",
message: "Are you sure you want to quit?",
detail: "All you unsaved progress will be lost!",
});
if (choice === 1) {
e.preventDefault();
}
});
mainWindow.on("closed", function () {
mainWindow = null;
});
const menu = Menu.buildFromTemplate(menuTemplate);
Menu.setApplicationMenu(menu);
}
app.on("ready", createWindow);
app.on("window-all-closed", function () {
if (process.platform !== "darwin") {
app.quit();
}
});
app.on("activated", function () {
if (mainWindow === null) {
createWindow();
}
});
// TODO: extract to seperate file
const menuTemplate = [
// { 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: "Open File",
accelerator: "CmdOrCtrl+O",
click: () => {
mainWindow.webContents.send("openFile");
},
},
{
label: "Save File",
accelerator: "CmdOrCtrl+S",
click: () => {
mainWindow.webContents.send("saveFile");
},
},
{
label: "Save As",
click: () => {
mainWindow.webContents.send("saveAs");
},
},
],
},
// { role: 'viewMenu' }
{
label: "View",
submenu: [
{ role: "toggledevtools", enabled: true },
{ type: "separator" },
{ role: "resetzoom" },
{ role: "zoomin" },
{ role: "zoomout" },
{ type: "separator" },
{ role: "togglefullscreen" },
],
},
// { role: 'windowMenu' }
{
label: "Window",
submenu: [
{ role: "minimize" },
...(isMac
? [
{ type: "separator" },
{ role: "front" },
{ type: "separator" },
{ role: "window" },
]
: [{ role: "close" }]),
],
},
];