-
Notifications
You must be signed in to change notification settings - Fork 1
/
electron.js
66 lines (55 loc) · 1.67 KB
/
electron.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
// eslint-disable-next-line
const { app, Menu, BrowserWindow, ipcMain, dialog } = require('electron');
// eslint-disable-next-line
const path = require('path');
app.commandLine.appendSwitch('enable-features','SharedArrayBuffer')
function createWindow() {
const win = new BrowserWindow({
show: false,
height: 600,
width: 900,
minWidth: 560,
minHeight: 250,
autoHideMenuBar: true,
webPreferences: {
// eslint-disable-next-line
preload: path.join(__dirname, 'preloader', 'index.js'),
nodeIntegration: true,
contextIsolation: true
}
})
if(app.isPackaged) {
// eslint-disable-next-line
win.loadFile(path.join(__dirname, 'dist/index.html'))
Menu.setApplicationMenu(null);
} else {
win.loadURL("http://localhost:3000");
}
win.once("ready-to-show", ()=>{
win.show();
})
}
app.whenReady().then(() => {
createWindow();
app.on('window-all-closed', () => {
// eslint-disable-next-line
process.platform !== 'darwin' && app.quit()
});
app.on('activate', () => {
BrowserWindow.getAllWindows().length === 0 && createWindow()
})
})
ipcMain.handle('electron-settings', ()=>{
return { userDataPath: app.getPath("userData"), isPackaged: app.isPackaged }
})
ipcMain.handle('os-settings', ()=>{
return {
downloads_path: app.getPath("downloads")
}
})
ipcMain.handle('show-save-dialog', async (event, ...args) => {
return await dialog.showSaveDialog(...args);
})
ipcMain.handle('show-open-dialog', async (event, ...args) => {
return await dialog.showOpenDialog(...args);
})