tabby/app/lib/index.ts

83 lines
1.8 KiB
TypeScript
Raw Normal View History

2021-07-27 07:59:35 +00:00
import 'v8-compile-cache'
import './portable'
2021-01-01 17:25:54 +00:00
import 'source-map-support/register'
2019-11-26 14:51:31 +00:00
import './sentry'
import './lru'
import { app, ipcMain, Menu, dialog } from 'electron'
import { parseArgs } from './cli'
import { Application } from './app'
2019-05-24 18:46:44 +00:00
import electronDebug = require('electron-debug')
import { loadConfig } from './config'
2021-06-29 21:57:04 +00:00
if (!process.env.TABBY_PLUGINS) {
process.env.TABBY_PLUGINS = ''
}
const argv = parseArgs(process.argv, process.cwd())
2022-05-30 21:27:01 +00:00
// eslint-disable-next-line @typescript-eslint/init-declarations
let configStore: any
try {
configStore = loadConfig()
} catch (err) {
2022-05-28 11:56:49 +00:00
dialog.showErrorBox('Could not read config', err.message)
app.exit(1)
2022-05-30 21:27:01 +00:00
}
2022-05-30 21:27:01 +00:00
const application = new Application(configStore)
2022-05-30 21:27:01 +00:00
ipcMain.on('app:new-window', () => {
application.newWindow()
})
2022-05-28 11:15:13 +00:00
2022-05-30 21:27:01 +00:00
process.on('uncaughtException' as any, err => {
console.log(err)
application.broadcast('uncaughtException', err)
2022-05-28 11:56:49 +00:00
})
2022-05-30 21:27:01 +00:00
if (argv.d) {
electronDebug({
isEnabled: true,
showDevTools: true,
devToolsMode: 'undocked',
})
}
2022-05-28 11:56:49 +00:00
app.on('activate', async () => {
2022-05-30 21:27:01 +00:00
if (!application.hasWindows()) {
application.newWindow()
2022-05-28 11:56:49 +00:00
} else {
2022-05-30 21:27:01 +00:00
application.focus()
2022-05-28 11:56:49 +00:00
}
})
app.on('second-instance', async (_event, newArgv, cwd) => {
2022-05-30 21:27:01 +00:00
application.handleSecondInstance(newArgv, cwd)
2022-05-28 11:56:49 +00:00
})
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()
},
2022-05-28 11:56:49 +00:00
},
]))
}
2022-05-30 21:27:01 +00:00
application.init()
2022-05-28 11:56:49 +00:00
2022-05-30 21:27:01 +00:00
const window = await application.newWindow({ hidden: argv.hidden })
2022-05-28 11:56:49 +00:00
await window.ready
window.passCliArguments(process.argv, process.cwd(), false)
window.focus()
})