2023-09-30 22:05:57 +03:00
|
|
|
import { app, ipcMain, Menu, dialog } from 'electron'
|
|
|
|
|
|
|
|
// set defaults of environment variables
|
|
|
|
import 'dotenv/config'
|
|
|
|
process.env.TABBY_PLUGINS ??= ''
|
2023-10-03 09:06:16 +03:00
|
|
|
process.env.TABBY_CONFIG_DIRECTORY ??= app.getPath('userData')
|
2023-09-30 22:05:57 +03:00
|
|
|
|
|
|
|
|
2021-07-27 10:59:35 +03:00
|
|
|
import 'v8-compile-cache'
|
2020-02-03 15:59:46 +03:00
|
|
|
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'
|
2018-08-31 16:41:28 +03:00
|
|
|
import './lru'
|
|
|
|
import { parseArgs } from './cli'
|
|
|
|
import { Application } from './app'
|
2019-05-24 21:46:44 +03:00
|
|
|
import electronDebug = require('electron-debug')
|
2022-05-28 13:35:32 +03:00
|
|
|
import { loadConfig } from './config'
|
2018-08-31 16:41:28 +03:00
|
|
|
|
|
|
|
|
2022-05-28 13:35:32 +03:00
|
|
|
const argv = parseArgs(process.argv, process.cwd())
|
2018-08-31 16:41:28 +03:00
|
|
|
|
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
|
|
|
}
|
2018-08-31 16:41:28 +03:00
|
|
|
|
2022-05-31 00:27:01 +03:00
|
|
|
const application = new Application(configStore)
|
2018-08-31 16:41:28 +03:00
|
|
|
|
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 13:35:32 +03:00
|
|
|
},
|
2022-05-28 14:56:49 +03:00
|
|
|
},
|
|
|
|
]))
|
|
|
|
}
|
2022-05-28 13:35:32 +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()
|
2022-05-28 13:35:32 +03:00
|
|
|
})
|