fix: imports for url & path which were breaking the app (#21)

This commit is contained in:
Ryan 2018-02-06 08:24:35 -06:00 committed by Vladimir Krivosheev
parent 427ff959db
commit 71215e3311

View file

@ -1,37 +1,31 @@
'use strict'
import { app, BrowserWindow } from 'electron'
import { path } from 'path'
import * as path from 'path'
import { format as formatUrl } from 'url'
const isDevelopment = process.env.NODE_ENV !== 'production'
// Global reference to mainWindow
// Necessary to prevent win from being garbage collected
// global reference to mainWindow (necessary to prevent window from being garbage collected)
let mainWindow
function createMainWindow() {
// Construct new BrowserWindow
const window = new BrowserWindow()
// Path to index file in production environment
const productionIndexPath = url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file',
slashes: true
})
// Set url for `win`
// points to `webpack-dev-server` in development
// points to `index.html` in production
const url = isDevelopment
? `http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}`
: productionIndexPath
if (isDevelopment) {
window.webContents.openDevTools()
}
window.loadURL(url)
if (isDevelopment) {
window.loadURL(`http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}`)
}
else {
window.loadURL(formatUrl({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file',
slashes: true
}))
}
window.on('closed', () => {
mainWindow = null
@ -47,20 +41,22 @@ function createMainWindow() {
return window
}
// Quit application when all windows are closed
// quit application when all windows are closed
app.on('window-all-closed', () => {
// On macOS it is common for applications to stay open
// until the user explicitly quits
if (process.platform !== 'darwin') app.quit()
// on macOS it is common for applications to stay open until the user explicitly quits
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
// On macOS it is common to re-create a window
// even after all windows have been closed
if (mainWindow === null) mainWindow = createMainWindow()
// on macOS it is common to re-create a window even after all windows have been closed
if (mainWindow === null) {
mainWindow = createMainWindow()
}
})
// Create main BrowserWindow when electron is ready
// create main BrowserWindow when electron is ready
app.on('ready', () => {
mainWindow = createMainWindow()
})