-
Notifications
You must be signed in to change notification settings - Fork 0
/
window.js
76 lines (63 loc) · 1.91 KB
/
window.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
const { app, BrowserWindow, Menu, nativeImage, ipcMain } = require('electron');
const path = require('path');
const ejs = require('ejs');
let mainWindow;
function createWindow() {
const logoPath = path.join(__dirname, 'logo.png');
const logoImage = nativeImage.createFromPath(logoPath);
mainWindow = new BrowserWindow({
width: 950,
height: 600,
show: false,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
},
icon: logoImage,
});
mainWindow.loadFile(path.join(__dirname, 'views', 'loading.html'));
mainWindow.webContents.on('did-finish-load', () => {
mainWindow.show();
});
mainWindow.webContents.on('will-attach-webview', (event, webPreferences, params) => {
webPreferences.webSecurity = false;
delete webPreferences.preload;
webPreferences.nodeIntegration = false;
webPreferences.contextIsolation = true;
});
mainWindow.once('ready-to-show', async () => {
mainWindow.show();
const data = {};
setTimeout(() => {
ejs.renderFile(path.join(__dirname, 'views', 'index.ejs'), data, (err, html) => {
if (err) {
console.error(err);
return;
}
mainWindow.loadURL(`data:text/html;charset=UTF-8,${encodeURIComponent(html)}`);
});
}, 5000);
});
Menu.setApplicationMenu(null);
}
app.whenReady().then(() => {
createWindow();
});
ipcMain.on('navigate-to-3dmodel', () => {
ejs.renderFile(path.join(__dirname, 'views', '3dmodel.ejs'), {}, (err, html) => {
if (err) {
console.error(err);
return;
}
mainWindow.loadURL(`data:text/html;charset=UTF-8,${encodeURIComponent(html)}`);
});
});
ipcMain.on('navigate-to-home', () => {
ejs.renderFile(path.join(__dirname, 'views', 'index.ejs'), {}, (err, html) => {
if (err) {
console.error(err);
return;
}
mainWindow.loadURL(`data:text/html;charset=UTF-8,${encodeURIComponent(html)}`);
});
});