1
1
mirror of https://github.com/Eugeny/tabby.git synced 2024-11-29 09:18:26 +03:00
tabby/app/lib/index.ts

87 lines
1.9 KiB
TypeScript
Raw Normal View History

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