-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.ts
127 lines (111 loc) · 3.65 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
import { app, BrowserWindow, ipcMain, protocol, screen } from 'electron';
import * as path from 'path';
import * as url from 'url';
let mainWindow: BrowserWindow = null;
const args = process.argv.slice(1);
const serve = args.some((val) => val === '--serve');
let wizardSettings;
function createWindow(): BrowserWindow {
const size = screen.getPrimaryDisplay().workAreaSize;
wizardSettings = {
x: Math.floor(size.width / 2 - 700 / 2),
y: Math.floor(size.height / 2 - 510 / 2),
width: 700,
height: 510,
resizable: true, // This prevents maximize minimize events so dont use it
maximizable: true, // This prevents maximize minimize events so dont use it
fullscreenable: true // This prevents maximize minimize events so dont use it
}
// Create the browser window.
mainWindow = new BrowserWindow({
x: wizardSettings.x,
y: wizardSettings.y,
width: wizardSettings.width,
height: wizardSettings.height,
maximizable: wizardSettings.maximizable,
resizable: wizardSettings.resizable,
fullscreenable: wizardSettings.fullscreenable,
backgroundColor: '#1a1a1a',
frame: false,
titleBarStyle: 'hiddenInset',
autoHideMenuBar: true,
webPreferences: {
webSecurity: !serve, // Used to load monaco files
enableRemoteModule: true,
nodeIntegration: true,
nodeIntegrationInWorker: true,
allowRunningInsecureContent: serve
}
});
if (serve) {
// Timeout is required so fs async apis work
setTimeout(() => {
mainWindow.loadURL('http://localhost:4200');
}, 100);
} else {
mainWindow.loadURL(
url.format({
pathname: path.join(__dirname, 'dist/main_renderer/index.html'),
protocol: 'file:',
slashes: true
})
);
}
if (!serve) {
// Fail operational
// Reload window if the render error crashes in production build
mainWindow.webContents.on('crashed', () => {
mainWindow.destroy();
createWindow();
});
}
mainWindow.on('closed', () => {
mainWindow = null;
});
return mainWindow;
}
ipcMain.on('main-window-home', (event, arg) => {
const display = screen.getPrimaryDisplay();
const maxSize = display.workAreaSize;
const w = Math.floor(maxSize.width * 0.9);
const h = Math.floor(maxSize.height - (maxSize.width * 0.1));
mainWindow.setPosition(Math.floor(maxSize.width / 2 - w / 2), Math.floor(maxSize.height / 2 - h / 2));
mainWindow.setSize(w, h);
mainWindow.setResizable(true);
mainWindow.setMaximizable(true);
mainWindow.setFullScreenable(true);
})
ipcMain.on('main-window-wizard', (event, arg) => {
mainWindow.setPosition(wizardSettings.x, wizardSettings.y);
mainWindow.setSize(wizardSettings.width, wizardSettings.height);
mainWindow.setResizable(wizardSettings.resizable);
mainWindow.setMaximizable(wizardSettings.maximizable);
mainWindow.setFullScreenable(wizardSettings.fullscreenable);
})
try {
app.on('ready', () => {
if(serve) {
// Monaco editor is loaded from files and needs access
protocol.registerFileProtocol('file', (request, callback) => {
const pathname = request.url.replace('file:///', '');
callback(pathname);
});
}
createWindow();
});
app.on('window-all-closed', () => {
// On OS X 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', () => {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
createWindow();
}
});
} catch (e) {
}