-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
100 lines (80 loc) · 2.28 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
const {app, BrowserWindow, ipcMain, Menu, session, dialog} = require('electron')
const path = require("path");
const fs = require("fs");
const {promisify} = require("util");
let mainWindow;
const createWindow = () => {
const win = new BrowserWindow({
width: 1920,
height: 1080,
show: false,
title: 'osb!cad',
webPreferences: {
nodeIntegration: true,
contextIsolation: true,
devTools: true,
preload: path.join(__dirname, 'preload.js')
},
})
mainWindow = win;
win.maximize()
win.show()
win.setMenu(createMenu(win))
win.loadURL('http://localhost:8080')
//win.loadFile(path.join(__dirname, 'dist/index.html'), )
}
app.whenReady().then(async () => {
if (fs.existsSync(path.join(__dirname, 'vue-devtools')))
await session.defaultSession.loadExtension(path.join(__dirname, 'vue-devtools'))
createWindow()
})
ipcMain.on('loadProject', async (evt, path) => {
try {
const contents = await promisify(fs.readFile)(path, {
encoding: 'UTF-8'
})
const project = JSON.parse(contents)
evt.sender.send('projectLoaded', {
project,
})
} catch (e) {
}
})
ipcMain.handle('select-directory', (evt, defaultPath) => {
return dialog.showOpenDialog(mainWindow, {
defaultPath,
properties: ['openDirectory']
})
})
ipcMain.handle('open-file-dialog', (evt, opts) => {
return dialog.showOpenDialog(mainWindow, {
...opts,
properties: ['openFile']
})
})
ipcMain.handle('save-file-dialog', (evt, opts) => {
return dialog.showSaveDialog(mainWindow, {
...opts
})
})
function createMenu(window) {
return Menu.buildFromTemplate([
{
label: 'Edit',
submenu: [
{
label: 'Undo',
accelerator: 'ctrl+z',
click: () => window.webContents.send('undo')
},
{
label: 'Redo',
accelerator: 'ctrl+y',
click: () => window.webContents.send('redo')
},
{role: 'separator'},
{role: 'toggleDevTools'},
]
}
])
}