|
@@ -1,33 +1,35 @@
|
|
|
-const {app, BrowserWindow, Menu, shell} = require('electron')
|
|
|
|
|
|
|
+const {app, BrowserWindow, Menu} = require('electron')
|
|
|
const path = require('path')
|
|
const path = require('path')
|
|
|
const eggLauncher = require('./electron/lanucher')
|
|
const eggLauncher = require('./electron/lanucher')
|
|
|
const setup = require('./electron/setup')
|
|
const setup = require('./electron/setup')
|
|
|
const electronConfig = require('./electron/config')
|
|
const electronConfig = require('./electron/config')
|
|
|
const storage = require('./electron/storage')
|
|
const storage = require('./electron/storage')
|
|
|
-const autoUpdater = require('./electron/autoUpdater')
|
|
|
|
|
|
|
+const is = require('electron-is')
|
|
|
|
|
+const setTray = require('./electron/tray')
|
|
|
|
|
|
|
|
// main window
|
|
// main window
|
|
|
global.MAIN_WINDOW = null
|
|
global.MAIN_WINDOW = null
|
|
|
|
|
+global.APP_TRAY = null;
|
|
|
|
|
+global.CAN_QUIT = false;
|
|
|
|
|
|
|
|
// Initialize
|
|
// Initialize
|
|
|
setup()
|
|
setup()
|
|
|
-// return
|
|
|
|
|
|
|
+//return
|
|
|
|
|
|
|
|
-if (process.mas) app.setName('electron-egg')
|
|
|
|
|
|
|
+// argv
|
|
|
|
|
+let ENV = 'prod'
|
|
|
|
|
+for (let i = 0; i < process.argv.length; i++) {
|
|
|
|
|
+ const tmpArgv = process.argv[i]
|
|
|
|
|
+ if (tmpArgv.indexOf('--env=') !== -1) {
|
|
|
|
|
+ ENV = tmpArgv.substr(6)
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+const eggConfig = electronConfig.get('egg', ENV)
|
|
|
|
|
+eggConfig.env = ENV
|
|
|
|
|
|
|
|
-// Open url with the default browser
|
|
|
|
|
-app.on('web-contents-created', (e, webContents) => {
|
|
|
|
|
- webContents.on('new-window', (event, url) => {
|
|
|
|
|
- event.preventDefault()
|
|
|
|
|
- shell.openExternal(url)
|
|
|
|
|
- });
|
|
|
|
|
-});
|
|
|
|
|
|
|
+if (process.mas) app.setName('electron-egg')
|
|
|
|
|
|
|
|
async function initialize () {
|
|
async function initialize () {
|
|
|
-
|
|
|
|
|
- // dynamic port
|
|
|
|
|
- await storage.setDynamicPort();
|
|
|
|
|
-
|
|
|
|
|
app.whenReady().then(() => {
|
|
app.whenReady().then(() => {
|
|
|
createWindow()
|
|
createWindow()
|
|
|
app.on('activate', function () {
|
|
app.on('activate', function () {
|
|
@@ -43,18 +45,17 @@ async function initialize () {
|
|
|
app.quit()
|
|
app.quit()
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
|
|
+
|
|
|
|
|
+ // Open url with the default browser
|
|
|
|
|
+ // app.on('web-contents-created', (e, webContents) => {
|
|
|
|
|
+ // webContents.on('new-window', (event, url) => {
|
|
|
|
|
+ // event.preventDefault()
|
|
|
|
|
+ // shell.openExternal(url)
|
|
|
|
|
+ // });
|
|
|
|
|
+ // });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async function createWindow () {
|
|
async function createWindow () {
|
|
|
- // argv
|
|
|
|
|
- const eggConfig = electronConfig.get('egg')
|
|
|
|
|
- for (let i = 0; i < process.argv.length; i++) {
|
|
|
|
|
- const tmpArgv = process.argv[i]
|
|
|
|
|
- if (tmpArgv.indexOf('--env=') !== -1) {
|
|
|
|
|
- eggConfig.env = tmpArgv.substr(6)
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
MAIN_WINDOW = new BrowserWindow(electronConfig.get('windowsOption'))
|
|
MAIN_WINDOW = new BrowserWindow(electronConfig.get('windowsOption'))
|
|
|
|
|
|
|
|
// if (process.platform === 'linux') {
|
|
// if (process.platform === 'linux') {
|
|
@@ -64,36 +65,63 @@ async function createWindow () {
|
|
|
if (eggConfig.env === 'prod') {
|
|
if (eggConfig.env === 'prod') {
|
|
|
// hidden menu
|
|
// hidden menu
|
|
|
Menu.setApplicationMenu(null)
|
|
Menu.setApplicationMenu(null)
|
|
|
|
|
+
|
|
|
|
|
+ // dynamic port
|
|
|
|
|
+ await storage.setDynamicPort()
|
|
|
|
|
+ eggConfig.port = electronConfig.get('egg', eggConfig.env).port
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// loding page
|
|
// loding page
|
|
|
MAIN_WINDOW.loadURL(path.join('file://', __dirname, '/app/public/loading.html'))
|
|
MAIN_WINDOW.loadURL(path.join('file://', __dirname, '/app/public/loading.html'))
|
|
|
|
|
|
|
|
|
|
+ // tray
|
|
|
|
|
+ setTray();
|
|
|
|
|
+
|
|
|
// egg server
|
|
// egg server
|
|
|
- setTimeout(function(){
|
|
|
|
|
- startServer(eggConfig)
|
|
|
|
|
- }, 100)
|
|
|
|
|
|
|
+ await startServer(eggConfig)
|
|
|
|
|
|
|
|
// check update
|
|
// check update
|
|
|
const updateConfig = electronConfig.get('autoUpdate')
|
|
const updateConfig = electronConfig.get('autoUpdate')
|
|
|
- if (updateConfig.enable) {
|
|
|
|
|
- autoUpdater.checkUpdate()
|
|
|
|
|
|
|
+ if ((is.windows() && updateConfig.windows) || (is.macOS() && updateConfig.macOS)
|
|
|
|
|
+ || (is.linux() && updateConfig.linux)) {
|
|
|
|
|
+ const autoUpdater = require('./electron/autoUpdater');
|
|
|
|
|
+ autoUpdater.checkUpdate();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return MAIN_WINDOW
|
|
return MAIN_WINDOW
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async function startServer (options) {
|
|
async function startServer (options) {
|
|
|
- let startRes = null
|
|
|
|
|
ELog.info('[main] [startServer] options', options)
|
|
ELog.info('[main] [startServer] options', options)
|
|
|
|
|
+ const protocol = 'http://'
|
|
|
|
|
+ let startRes = null
|
|
|
|
|
+ let url = null
|
|
|
|
|
+ if (ENV === 'prod') {
|
|
|
|
|
+ url = protocol + options.hostname + ':' + options.port
|
|
|
|
|
+ } else {
|
|
|
|
|
+ const developmentModeConfig = electronConfig.get('developmentMode', ENV)
|
|
|
|
|
+ const selectMode = developmentModeConfig.default
|
|
|
|
|
+ const modeInfo = developmentModeConfig.mode[selectMode]
|
|
|
|
|
+ switch (selectMode) {
|
|
|
|
|
+ case 'vue' :
|
|
|
|
|
+ url = protocol + modeInfo.hostname + ':' + modeInfo.port
|
|
|
|
|
+ break
|
|
|
|
|
+ case 'react' :
|
|
|
|
|
+ url = protocol + modeInfo.hostname + ':' + modeInfo.port
|
|
|
|
|
+ break
|
|
|
|
|
+ case 'ejs' :
|
|
|
|
|
+ url = protocol + modeInfo.hostname + ':' + modeInfo.port
|
|
|
|
|
+ break
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ ELog.info('[main] [url]:', url)
|
|
|
startRes = await eggLauncher.start(options).then((res) => res, (err) => err)
|
|
startRes = await eggLauncher.start(options).then((res) => res, (err) => err)
|
|
|
ELog.info('[main] [startServer] startRes:', startRes)
|
|
ELog.info('[main] [startServer] startRes:', startRes)
|
|
|
if (startRes === 'success') {
|
|
if (startRes === 'success') {
|
|
|
- let url = 'http://localhost:' + options.port
|
|
|
|
|
MAIN_WINDOW.loadURL(url)
|
|
MAIN_WINDOW.loadURL(url)
|
|
|
-
|
|
|
|
|
return true
|
|
return true
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
app.relaunch()
|
|
app.relaunch()
|
|
|
}
|
|
}
|
|
|
|
|
|