Skip to content

Commit

Permalink
periodic cleanup:
Browse files Browse the repository at this point in the history
- update dependencies
- remove babel compilation of node-side code, use esm instead
- replace babel presets es2015 and stage-0 with babel-preset-env
- remove old config options to nwb/express which don't do anything anymore
- main/main.js is now executed after electron.app's 'ready' event fires
- other stuff :)
  • Loading branch information
brumm committed May 19, 2018
1 parent 3f35e43 commit 52a4434
Show file tree
Hide file tree
Showing 9 changed files with 2,936 additions and 2,817 deletions.
11 changes: 10 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
{
"presets": ["es2015", "stage-0"]
"presets": [
[
"env",
{
"targets": {
"electron": "current"
}
}
]
]
}
5 changes: 1 addition & 4 deletions dev-server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

let args = require('minimist')(process.argv.slice(2))
const args = require('minimist')(process.argv.slice(2))
const port = args.port || 8080
const express = require('express')
const app = express()
Expand All @@ -10,10 +10,7 @@ const nwbExpress = require('nwb/express')

app.use(
nwbExpress(express, {
info: false,
reload: true,
fallback: true,
// autoInstall: true
})
)

Expand Down
69 changes: 2 additions & 67 deletions main/index.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,2 @@
import { app, BrowserWindow, Menu, screen, ipcMain } from 'electron'
import template from './menu-template.js'
import windowStateKeeper from 'electron-window-state'
import installExtension, { REACT_DEVELOPER_TOOLS } from 'electron-devtools-installer'

const { DEV, PORT = '8080' } = process.env
const windowUrl = DEV ? `http://0.0.0.0:${PORT}/` : 'file://' + __dirname + '/index.html'

let mainWindow

function createWindow() {
installExtension(REACT_DEVELOPER_TOOLS)
.then(name => {
let { width, height } = screen.getPrimaryDisplay().workAreaSize

Menu.setApplicationMenu(Menu.buildFromTemplate(template))

let mainWindowState = windowStateKeeper({
defaultWidth: width * 0.9,
defaultHeight: height * 0.9,
})

mainWindow = new BrowserWindow({
width: mainWindowState.width,
height: mainWindowState.height,
x: mainWindowState.x,
y: mainWindowState.y,
minWidth: 1000,
minHeight: 700,
titleBarStyle: 'hidden-inset',
webPreferences: {
webSecurity: false,
},
show: false,
})

mainWindowState.manage(mainWindow)
mainWindow.loadURL(windowUrl)

if (DEV) {
mainWindow.webContents.openDevTools()
}

mainWindow.on('closed', () => {
mainWindow = null
})

mainWindow.once('ready-to-show', mainWindow.show)
})
.catch(err => console.log('An error occurred: ', err))
}

app.on('ready', createWindow)

app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})

app.on('activate', () => {
if (mainWindow === null) {
createWindow()
}
})

process.on('uncaughtException', ::console.log)
require = require('esm')(module)
require('electron').app.on('ready', () => require('./main.js'))
65 changes: 65 additions & 0 deletions main/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { app, BrowserWindow, screen, Menu, ipcMain } from 'electron'
import template from './menu-template.js'
import windowStateKeeper from 'electron-window-state'
import installExtension, { REACT_DEVELOPER_TOOLS } from 'electron-devtools-installer'

const { DEV, PORT = '8080' } = process.env
const windowUrl = DEV ? `http://0.0.0.0:${PORT}/` : `file://${app.getAppPath()}/dist/index.html`

let mainWindow

installExtension(REACT_DEVELOPER_TOOLS)
.then(name => {
let { width, height } = screen.getPrimaryDisplay().workAreaSize

Menu.setApplicationMenu(Menu.buildFromTemplate(template))

let mainWindowState = windowStateKeeper({
defaultWidth: width * 0.9,
defaultHeight: height * 0.9,
})

mainWindow = new BrowserWindow({
width: mainWindowState.width,
height: mainWindowState.height,
x: mainWindowState.x,
y: mainWindowState.y,
minWidth: 1000,
minHeight: 600,
titleBarStyle: 'hiddenInset',
webPreferences: {
webSecurity: false,
},
show: false,
})

mainWindowState.manage(mainWindow)
mainWindow.loadURL(windowUrl)

if (DEV) {
mainWindow.webContents.once('dom-ready', () => {
mainWindow.webContents.openDevTools()
})
}

mainWindow.on('closed', () => {
mainWindow = null
})

mainWindow.once('ready-to-show', mainWindow.show)
})
.catch(err => console.log('An error occurred: ', err))

app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})

app.on('activate', () => {
if (mainWindow === null) {
createWindow()
}
})

process.on('uncaughtException', console.log)
2 changes: 0 additions & 2 deletions nwb.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const path = require('path')
const webpack = require('webpack')
const package = require('./package.json')

const cssConfig = {
Expand All @@ -16,7 +15,6 @@ module.exports = {
extra: {
resolve: {
modules: [path.resolve('./src'), 'node_modules'],
extensions: ['.scss'],
},
output: {
publicPath: '',
Expand Down
Loading

0 comments on commit 52a4434

Please sign in to comment.