-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.js
More file actions
93 lines (73 loc) · 2.21 KB
/
index.js
File metadata and controls
93 lines (73 loc) · 2.21 KB
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
const {app, BrowserWindow, ipcMain} = require('electron');
const path = require('path');
const fs = require('fs');
const {startServer, stopServer} = require('./server');
const {menu} = require("./menu");
const {dialog} = require('electron');
const isWindows = process.platform === "win32";
let mainWindow;
const openDevTool = false;
function createWindow() {
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
enableRemoteModule: true,
nodeIntegration: true,
contextIsolation: false,
preload: path.join(__dirname, 'preload.js')
},
frame: false //Remove frame to hide default menu
});
mainWindow.loadFile('./web-page/index.html');
if(openDevTool)
mainWindow.webContents.openDevTools();
}
app.whenReady().then(() => {
createWindow();
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
});
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
});
ipcMain.on(`display-app-menu`, function (e, args) {
if (isWindows && mainWindow) {
menu.popup({
window: mainWindow,
x: args.x,
y: args.y
});
}
});
ipcMain.on(`select-3d-tile-folder`, (e, args) => {
if (isWindows && mainWindow) {
const options = {
title: 'Select a tileset json file',
properties: ['openFile'],
};
const tilesetPath = dialog.showOpenDialogSync(mainWindow, options);
if(!tilesetPath)
return;
const dir = path.dirname(tilesetPath[0]);
const baseName = path.basename(tilesetPath[0]);
const port = 3000;
stopServer();
startServer(port, dir);
const tilesetUrl = `http://localhost:${port}/${baseName}`;
mainWindow.webContents.executeJavaScript(`window.tilesetViewer.addTileset("${tilesetUrl}")`);
}
});
ipcMain.on('tileset-load-error', () => {
const messageBoxOptions = {
type: "error",
title: "Error",
message: "failed to load tileset!"
};
dialog.showMessageBoxSync(messageBoxOptions);
});