index.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 } from 'electron'
  7. import { parseArgs } from './cli'
  8. import { Application } from './app'
  9. import electronDebug = require('electron-debug')
  10. if (!process.env.TABBY_PLUGINS) {
  11. process.env.TABBY_PLUGINS = ''
  12. }
  13. const application = new Application()
  14. ipcMain.on('app:new-window', () => {
  15. application.newWindow()
  16. })
  17. app.on('activate', () => {
  18. if (!application.hasWindows()) {
  19. application.newWindow()
  20. } else {
  21. application.focus()
  22. }
  23. })
  24. process.on('uncaughtException' as any, err => {
  25. console.log(err)
  26. application.broadcast('uncaughtException', err)
  27. })
  28. app.on('second-instance', (_event, argv, cwd) => {
  29. application.handleSecondInstance(argv, cwd)
  30. })
  31. const argv = parseArgs(process.argv, process.cwd())
  32. if (!app.requestSingleInstanceLock()) {
  33. app.quit()
  34. app.exit(0)
  35. }
  36. if (argv.d) {
  37. electronDebug({
  38. isEnabled: true,
  39. showDevTools: true,
  40. devToolsMode: 'undocked',
  41. })
  42. }
  43. app.on('ready', async () => {
  44. if (process.platform === 'darwin') {
  45. app.dock.setMenu(Menu.buildFromTemplate([
  46. {
  47. label: 'New window',
  48. click () {
  49. this.app.newWindow()
  50. },
  51. },
  52. ]))
  53. }
  54. application.init()
  55. const window = await application.newWindow({ hidden: argv.hidden })
  56. await window.ready
  57. window.passCliArguments(process.argv, process.cwd(), false)
  58. })