1 Star 0 Fork 13

main2018/aweb-helper

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.js 2.52 KB
一键复制 编辑 原始数据 按行查看 历史
gaoshuaixing 提交于 2020-12-03 15:21 . 1
const {app, BrowserWindow, Menu, shell} = require('electron')
const path = require('path')
const eggLauncher = require('./electron/lanucher')
const setup = require('./electron/setup')
const electronConfig = require('./electron/config')
const storage = require('./electron/storage')
const autoUpdater = require('./electron/autoUpdater')
// main window
global.MAIN_WINDOW = null
// Initialize
setup()
// return
if (process.mas) app.setName('网站助手')
// 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 initialize () {
// 如果前端使用的是vue,那么调试的时候,关闭动态服务端口,走固定端口就避免每次启动后,需要手动跟换vue的端口了
await storage.setDynamicPort();
app.whenReady().then(() => {
createWindow()
app.on('activate', function () {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
})
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
console.log('window-all-closed quit')
app.quit()
}
})
}
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'))
// if (process.platform === 'linux') {
// windowOptions.icon = path.join(__dirname, '/assets/app-icon/png/512.png')
// }
if (eggConfig.env === 'prod') {
// hidden menu
Menu.setApplicationMenu(null)
}
// loding page
MAIN_WINDOW.loadURL(path.join('file://', __dirname, '/app/public/loading.html'))
// egg server
setTimeout(function(){
startServer(eggConfig)
}, 100)
// check update
const updateConfig = electronConfig.get('autoUpdate')
if (updateConfig.enable) {
autoUpdater.checkUpdate()
}
return MAIN_WINDOW
}
async function startServer (options) {
let startRes = null
ELog.info('[main] [startServer] options', options)
startRes = await eggLauncher.start(options).then((res) => res, (err) => err)
ELog.info('[main] [startServer] startRes:', startRes)
if (startRes === 'success') {
let url = 'http://localhost:' + options.port
MAIN_WINDOW.loadURL(url)
return true
}
app.relaunch()
}
initialize()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/main1118/aweb-helper.git
[email protected]:main1118/aweb-helper.git
main1118
aweb-helper
aweb-helper
master

搜索帮助