index.ts 1.5 KB

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