tabby/app/lib/index.ts

67 lines
1.4 KiB
TypeScript
Raw Normal View History

import './lru'
import { app, ipcMain, Menu } from 'electron'
import { parseArgs } from './cli'
import { Application } from './app'
2019-05-24 18:46:44 +00:00
import electronDebug = require('electron-debug')
if (!process.env.TERMINUS_PLUGINS) {
process.env.TERMINUS_PLUGINS = ''
}
const application = new Application()
ipcMain.on('app:new-window', () => {
application.newWindow()
})
app.on('activate', () => {
if (!application.hasWindows()) {
application.newWindow()
} else {
application.focus()
}
})
2018-09-20 11:02:07 +00:00
app.on('window-all-closed', () => {
app.quit()
})
process.on('uncaughtException' as any, err => {
console.log(err)
application.broadcast('uncaughtException', err)
})
app.on('second-instance', (_event, argv, cwd) => {
application.send('host:second-instance', parseArgs(argv, cwd), cwd)
})
const argv = parseArgs(process.argv, process.cwd())
if (!app.requestSingleInstanceLock()) {
app.quit()
process.exit(0)
}
if (argv.d) {
2019-05-24 19:19:08 +00:00
electronDebug({
isEnabled: true,
showDevTools: true,
devToolsMode: 'undocked'
})
}
app.on('ready', () => {
2018-09-05 08:24:16 +00:00
if (process.platform === 'darwin') {
app.dock.setMenu(Menu.buildFromTemplate([
{
label: 'New window',
click () {
this.app.newWindow()
}
}
2018-09-05 08:24:16 +00:00
]))
}
application.init()
application.newWindow({ hidden: argv.hidden })
})