-
Notifications
You must be signed in to change notification settings - Fork 30
/
main.js
77 lines (59 loc) · 1.88 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
const isDev = process.env.NODE_ENV === 'DEV'
const path = require('path')
/*
** Nuxt
*/
const { fork } = require('child_process');
const forked = fork(path.join(__dirname,'./nuxtService.js'));
/*
** Electron
*/
forked.on('message',(message)=>{
if( message.status != 'done')
return
const _NUXT_URL_ = `http://localhost:${message.port}`
if(isDev)
console.log(`Nuxt working on ${_NUXT_URL_}`)
let win = null // Current window
const { app, BrowserWindow } = require('electron')
const createWindow = async () => {
win = new BrowserWindow({
width: 800,
height: 600,
webSecurity: false,
// uncommect for node integration
//webPreferences:{
// nodeIntegration: true,
// contextIsolation: false,
// enableRemoteModule: true,
//}
})
if(isDev)
{
// Install vue dev tool and open chrome dev tools
const { default: installExtension, VUEJS_DEVTOOLS } = require('electron-devtools-installer')
await installExtension(VUEJS_DEVTOOLS,{
loadExtensionOptions: {
allowFileAccess: true,
}
})
win.webContents.openDevTools()
win.maximize()
//Load Content
await win.loadURL(_NUXT_URL_)
}
else
return win.loadURL(_NUXT_URL_)
}
app.whenReady().then(async () => {
await createWindow()
// If in macOS, Open a window when there are none
app.on('activate', function () {
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
})
//If not in macOS, Quit Application when all windows are closed
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit()
})
})