index.ts 1.4 KB

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