|
| 1 | +/* |
| 2 | +** Nuxt |
| 3 | +*/ |
| 4 | +const http = require('http') |
| 5 | +const { Nuxt, Builder } = require('nuxt') |
| 6 | +let config = require('./nuxt.config.js') |
| 7 | +config.rootDir = __dirname // for electron-builder |
| 8 | +// Init Nuxt.js |
| 9 | +const nuxt = new Nuxt(config) |
| 10 | +const builder = new Builder(nuxt) |
| 11 | +const server = http.createServer(nuxt.render) |
| 12 | +// Build only in dev mode |
| 13 | +if (config.dev) { |
| 14 | + builder.build().catch(err => { |
| 15 | + console.error(err) // eslint-disable-line no-console |
| 16 | + process.exit(1) |
| 17 | + }) |
| 18 | +} |
| 19 | +// Listen the server |
| 20 | +server.listen() |
| 21 | +const _NUXT_URL_ = `http://localhost:${server.address().port}` |
| 22 | +console.log(`Nuxt working on ${_NUXT_URL_}`) |
| 23 | +/* |
| 24 | +** Electron |
| 25 | +*/ |
1 | 26 | const { app, BrowserWindow } = require('electron')
|
2 |
| - |
| 27 | +let win = null // Current window |
| 28 | +const path = require('path') |
3 | 29 | function createWindow () {
|
4 | 30 | // Erstelle das Browser-Fenster.
|
5 |
| - let win = new BrowserWindow({ |
6 |
| - width: 800, |
7 |
| - height: 600, |
| 31 | + win = new BrowserWindow({ |
8 | 32 | webPreferences: {
|
9 |
| - nodeIntegration: false |
10 |
| - } |
| 33 | + nodeIntegration: true |
| 34 | + }, |
| 35 | + icon: path.join(__dirname, 'static/icon.png') |
11 | 36 | })
|
12 |
| - |
13 |
| - // und lade die index.html der App. |
14 |
| - win.loadFile('index.html') |
| 37 | + win.maximize() |
| 38 | + win.on('closed', () => win = null) |
| 39 | + if (config.dev) { |
| 40 | + // Install vue dev tool and open chrome dev tools |
| 41 | + const { default: installExtension, VUEJS_DEVTOOLS } = require('electron-devtools-installer') |
| 42 | + installExtension(VUEJS_DEVTOOLS.id).then(name => { |
| 43 | + console.log(`Added Extension: ${name}`) |
| 44 | + win.webContents.openDevTools() |
| 45 | + }).catch(err => console.log('An error occurred: ', err)) |
| 46 | + // Wait for nuxt to build |
| 47 | + const pollServer = () => { |
| 48 | + http.get(_NUXT_URL_, (res) => { |
| 49 | + if (res.statusCode === 200) { win.loadURL(_NUXT_URL_) } else { setTimeout(pollServer, 300) } |
| 50 | + }).on('error', pollServer) |
| 51 | + } |
| 52 | + pollServer() |
| 53 | + } else { |
| 54 | + return win.loadURL(_NUXT_URL_) |
| 55 | + } |
15 | 56 | }
|
16 | 57 |
|
17 | 58 | app.whenReady().then(createWindow)
|
| 59 | +app.on('window-all-closed', () => app.quit()) |
| 60 | +app.on('activate', () => win === null && newWin()) |
0 commit comments