Skip to content

Commit

Permalink
fixed event listener order
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugeny committed May 28, 2022
1 parent 524ccd0 commit b3df681
Showing 1 changed file with 44 additions and 39 deletions.
83 changes: 44 additions & 39 deletions app/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
},
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()
},
]))
}
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)
(await application).init()

const window = await (await application).newWindow({ hidden: argv.hidden })
await window.ready
window.passCliArguments(process.argv, process.cwd(), false)
window.focus()
})

0 comments on commit b3df681

Please sign in to comment.