-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
60 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
/*
** Nuxt
*/
const http = require('http')
const { Nuxt, Builder } = require('nuxt')
let config = require('./nuxt.config.js')
config.rootDir = __dirname // for electron-builder
// Init Nuxt.js
const nuxt = new Nuxt(config)
const builder = new Builder(nuxt)
const server = http.createServer(nuxt.render)
// Build only in dev mode
if (config.dev) {
builder.build().catch(err => {
console.error(err) // eslint-disable-line no-console
process.exit(1)
})
}
// Listen the server
server.listen()
const _NUXT_URL_ = `http://localhost:${server.address().port}`
console.log(`Nuxt working on ${_NUXT_URL_}`)
/*
** Electron
*/
const { app, BrowserWindow } = require('electron')
let win = null // Current window
const path = require('path')
function createWindow () {
// Erstelle das Browser-Fenster.
win = new BrowserWindow({
webPreferences: {
nodeIntegration: true
},
icon: path.join(__dirname, 'static/icon.png')
})
win.maximize()
win.on('closed', () => win = null)
if (config.dev) {
// Install vue dev tool and open chrome dev tools
const { default: installExtension, VUEJS_DEVTOOLS } = require('electron-devtools-installer')
installExtension(VUEJS_DEVTOOLS.id).then(name => {
console.log(`Added Extension: ${name}`)
win.webContents.openDevTools()
}).catch(err => console.log('An error occurred: ', err))
// Wait for nuxt to build
const pollServer = () => {
http.get(_NUXT_URL_, (res) => {
if (res.statusCode === 200) { win.loadURL(_NUXT_URL_) } else { setTimeout(pollServer, 300) }
}).on('error', pollServer)
}
pollServer()
} else {
return win.loadURL(_NUXT_URL_)
}
}
app.whenReady().then(createWindow)
app.on('window-all-closed', () => app.quit())
app.on('activate', () => win === null && newWin())