fixed event listener order

This commit is contained in:
Eugene Pankov 2022-05-28 13:56:49 +02:00
parent 524ccd06f3
commit b3df681753
No known key found for this signature in database
GPG Key ID: 5896FCBBDD1CF4F4

View File

@ -15,35 +15,21 @@ if (!process.env.TABBY_PLUGINS) {
const argv = parseArgs(process.argv, process.cwd())
loadConfig().then(configStore => {
const application = new Application(configStore)
const application = loadConfig().catch(err => {
dialog.showErrorBox('Could not read config', err.message)
app.exit(1)
}).then(configStore => {
const _application = new Application(configStore)
ipcMain.on('app:new-window', () => {
application.newWindow()
})
app.on('activate', () => {
if (!application.hasWindows()) {
application.newWindow()
} else {
application.focus()
}
_application.newWindow()
})
process.on('uncaughtException' as any, err => {
console.log(err)
application.broadcast('uncaughtException', err)
_application.broadcast('uncaughtException', err)
})
app.on('second-instance', (_event, newArgv, cwd) => {
application.handleSecondInstance(newArgv, cwd)
})
if (!app.requestSingleInstanceLock()) {
app.quit()
app.exit(0)
}
if (argv.d) {
electronDebug({
isEnabled: true,
@ -52,24 +38,43 @@ loadConfig().then(configStore => {
})
}
app.on('ready', async () => {
if (process.platform === 'darwin') {
app.dock.setMenu(Menu.buildFromTemplate([
{
label: 'New window',
click () {
this.app.newWindow()
},
},
]))
}
application.init()
const window = await application.newWindow({ hidden: argv.hidden })
await window.ready
window.passCliArguments(process.argv, process.cwd(), false)
window.focus()
})
}).catch(err => {
dialog.showErrorBox('Could not read config', err.message)
return _application
})
app.on('activate', async () => {
if (!(await application).hasWindows()) {
(await application).newWindow()
} else {
(await application).focus()
}
})
app.on('second-instance', async (_event, newArgv, cwd) => {
(await application).handleSecondInstance(newArgv, cwd)
})
if (!app.requestSingleInstanceLock()) {
app.quit()
app.exit(0)
}
app.on('ready', async () => {
if (process.platform === 'darwin') {
app.dock.setMenu(Menu.buildFromTemplate([
{
label: 'New window',
click () {
this.app.newWindow()
},
},
]))
}
(await application).init()
const window = await (await application).newWindow({ hidden: argv.hidden })
await window.ready
window.passCliArguments(process.argv, process.cwd(), false)
window.focus()
})