index.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import 'v8-compile-cache'
  2. import './portable'
  3. import 'source-map-support/register'
  4. import './sentry'
  5. import './lru'
  6. import { app, ipcMain, Menu, dialog } from 'electron'
  7. import { parseArgs } from './cli'
  8. import { Application } from './app'
  9. import electronDebug = require('electron-debug')
  10. import { loadConfig } from './config'
  11. if (!process.env.TABBY_PLUGINS) {
  12. process.env.TABBY_PLUGINS = ''
  13. }
  14. const argv = parseArgs(process.argv, process.cwd())
  15. // eslint-disable-next-line @typescript-eslint/init-declarations
  16. let configStore: any
  17. try {
  18. configStore = loadConfig()
  19. } catch (err) {
  20. dialog.showErrorBox('Could not read config', err.message)
  21. app.exit(1)
  22. }
  23. const application = new Application(configStore)
  24. ipcMain.on('app:new-window', () => {
  25. application.newWindow()
  26. })
  27. process.on('uncaughtException' as any, err => {
  28. console.log(err)
  29. application.broadcast('uncaughtException', err)
  30. })
  31. if (argv.d) {
  32. electronDebug({
  33. isEnabled: true,
  34. showDevTools: true,
  35. devToolsMode: 'undocked',
  36. })
  37. }
  38. app.on('activate', async () => {
  39. if (!application.hasWindows()) {
  40. application.newWindow()
  41. } else {
  42. application.focus()
  43. }
  44. })
  45. app.on('second-instance', async (_event, newArgv, cwd) => {
  46. application.handleSecondInstance(newArgv, cwd)
  47. })
  48. if (!app.requestSingleInstanceLock()) {
  49. app.quit()
  50. app.exit(0)
  51. }
  52. app.on('ready', async () => {
  53. if (process.platform === 'darwin') {
  54. app.dock.setMenu(Menu.buildFromTemplate([
  55. {
  56. label: 'New window',
  57. click () {
  58. this.app.newWindow()
  59. },
  60. },
  61. ]))
  62. }
  63. application.init()
  64. const window = await application.newWindow({ hidden: argv.hidden })
  65. await window.ready
  66. window.passCliArguments(process.argv, process.cwd(), false)
  67. window.focus()
  68. })