2020-02-03 12:59:46 +00:00
|
|
|
import './portable'
|
2021-01-01 17:25:54 +00:00
|
|
|
import 'source-map-support/register'
|
2019-11-26 14:51:31 +00:00
|
|
|
import './sentry'
|
2018-08-31 13:41:28 +00:00
|
|
|
import './lru'
|
|
|
|
import { app, ipcMain, Menu } from 'electron'
|
|
|
|
import { parseArgs } from './cli'
|
|
|
|
import { Application } from './app'
|
2019-05-24 18:46:44 +00:00
|
|
|
import electronDebug = require('electron-debug')
|
2018-08-31 13:41:28 +00:00
|
|
|
|
|
|
|
if (!process.env.TERMINUS_PLUGINS) {
|
|
|
|
process.env.TERMINUS_PLUGINS = ''
|
|
|
|
}
|
|
|
|
|
|
|
|
const application = new Application()
|
|
|
|
|
|
|
|
ipcMain.on('app:new-window', () => {
|
|
|
|
application.newWindow()
|
|
|
|
})
|
|
|
|
|
|
|
|
app.on('activate', () => {
|
|
|
|
if (!application.hasWindows()) {
|
|
|
|
application.newWindow()
|
|
|
|
} else {
|
|
|
|
application.focus()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-09-20 11:02:07 +00:00
|
|
|
app.on('window-all-closed', () => {
|
|
|
|
app.quit()
|
|
|
|
})
|
|
|
|
|
2018-08-31 13:41:28 +00:00
|
|
|
process.on('uncaughtException' as any, err => {
|
|
|
|
console.log(err)
|
|
|
|
application.broadcast('uncaughtException', err)
|
|
|
|
})
|
|
|
|
|
|
|
|
app.on('second-instance', (_event, argv, cwd) => {
|
2020-05-02 15:23:35 +00:00
|
|
|
application.handleSecondInstance(argv, cwd)
|
2018-08-31 13:41:28 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
const argv = parseArgs(process.argv, process.cwd())
|
|
|
|
|
|
|
|
if (!app.requestSingleInstanceLock()) {
|
|
|
|
app.quit()
|
2019-08-07 13:10:00 +00:00
|
|
|
app.exit(0)
|
2018-08-31 13:41:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (argv.d) {
|
2019-05-24 19:19:08 +00:00
|
|
|
electronDebug({
|
|
|
|
isEnabled: true,
|
|
|
|
showDevTools: true,
|
2019-11-26 14:51:31 +00:00
|
|
|
devToolsMode: 'undocked',
|
2019-05-24 19:19:08 +00:00
|
|
|
})
|
2018-08-31 13:41:28 +00:00
|
|
|
}
|
|
|
|
|
2021-01-24 18:06:41 +00:00
|
|
|
app.on('ready', async () => {
|
2018-09-05 08:24:16 +00:00
|
|
|
if (process.platform === 'darwin') {
|
|
|
|
app.dock.setMenu(Menu.buildFromTemplate([
|
|
|
|
{
|
|
|
|
label: 'New window',
|
|
|
|
click () {
|
|
|
|
this.app.newWindow()
|
2020-02-05 12:16:31 +00:00
|
|
|
},
|
|
|
|
},
|
2018-09-05 08:24:16 +00:00
|
|
|
]))
|
|
|
|
}
|
2019-02-09 23:23:49 +00:00
|
|
|
application.init()
|
2021-01-24 18:06:41 +00:00
|
|
|
|
|
|
|
const window = await application.newWindow({ hidden: argv.hidden })
|
|
|
|
await window.ready
|
|
|
|
window.passCliArguments(process.argv, process.cwd(), false)
|
2018-08-31 13:41:28 +00:00
|
|
|
})
|