2019-02-17 17:46:50 +00:00
|
|
|
const { app, BrowserWindow } = require('electron');
|
2018-07-29 11:50:44 +00:00
|
|
|
const setupMenu = require('./menu');
|
|
|
|
|
2018-10-24 17:08:51 +00:00
|
|
|
let mainWindow
|
|
|
|
let winURL
|
2018-07-29 11:50:44 +00:00
|
|
|
|
|
|
|
if (process.env.NODE_ENV !== 'development') {
|
2018-10-24 17:08:51 +00:00
|
|
|
global.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\')
|
2018-07-29 11:50:44 +00:00
|
|
|
}
|
|
|
|
|
2018-10-24 17:08:51 +00:00
|
|
|
if (process.env.NODE_ENV === 'development') {
|
2019-02-17 17:46:50 +00:00
|
|
|
const { getAppConfig } = require('frappejs/webpack/utils');
|
2018-10-24 17:08:51 +00:00
|
|
|
const appConfig = getAppConfig();
|
|
|
|
winURL = `http://localhost:${appConfig.dev.devServerPort}`;
|
|
|
|
} else {
|
|
|
|
winURL = `file://${__dirname}/index.html`;
|
|
|
|
}
|
2018-07-29 11:50:44 +00:00
|
|
|
|
|
|
|
function createWindow() {
|
|
|
|
/**
|
|
|
|
* Initial window options
|
|
|
|
*/
|
|
|
|
mainWindow = new BrowserWindow({
|
|
|
|
width: 1024,
|
|
|
|
height: 768,
|
2018-10-24 17:08:51 +00:00
|
|
|
useContentSize: true,
|
|
|
|
webPreferences: {
|
|
|
|
webSecurity: false
|
|
|
|
}
|
2018-07-29 11:50:44 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
mainWindow.loadURL(winURL)
|
|
|
|
|
|
|
|
mainWindow.on('closed', () => {
|
|
|
|
mainWindow = null
|
|
|
|
})
|
|
|
|
|
|
|
|
setupMenu();
|
|
|
|
}
|
|
|
|
|
|
|
|
app.on('ready', createWindow)
|
|
|
|
|
|
|
|
app.on('window-all-closed', () => {
|
|
|
|
if (process.platform !== 'darwin') {
|
|
|
|
app.quit()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
app.on('activate', () => {
|
|
|
|
if (mainWindow === null) {
|
|
|
|
createWindow()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
// TODO:
|
|
|
|
// Enable Auto Update
|
|
|
|
// https://www.electron.build/auto-update/
|