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' 'use strict'
import { app, BrowserWindow } from 'electron' 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' const isDevelopment = process.env.NODE_ENV !== 'production'
// Global reference to mainWindow // global reference to mainWindow (necessary to prevent window from being garbage collected)
// Necessary to prevent win from being garbage collected
let mainWindow let mainWindow
function createMainWindow() { function createMainWindow() {
// Construct new BrowserWindow
const window = 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) { if (isDevelopment) {
window.webContents.openDevTools() 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', () => { window.on('closed', () => {
mainWindow = null mainWindow = null
@ -47,20 +41,22 @@ function createMainWindow() {
return window return window
} }
// Quit application when all windows are closed // quit application when all windows are closed
app.on('window-all-closed', () => { app.on('window-all-closed', () => {
// On macOS it is common for applications to stay open // on macOS it is common for applications to stay open until the user explicitly quits
// until the user explicitly quits if (process.platform !== 'darwin') {
if (process.platform !== 'darwin') app.quit() app.quit()
}
}) })
app.on('activate', () => { app.on('activate', () => {
// On macOS it is common to re-create a window // on macOS it is common to re-create a window even after all windows have been closed
// even after all windows have been closed if (mainWindow === null) {
if (mainWindow === null) mainWindow = createMainWindow() mainWindow = createMainWindow()
}
}) })
// Create main BrowserWindow when electron is ready // create main BrowserWindow when electron is ready
app.on('ready', () => { app.on('ready', () => {
mainWindow = createMainWindow() mainWindow = createMainWindow()
}) })