2019-11-26 17:51:31 +03:00
|
|
|
import './sentry'
|
2018-08-31 16:41:28 +03:00
|
|
|
import './lru'
|
|
|
|
import { app, ipcMain, Menu } from 'electron'
|
|
|
|
import { parseArgs } from './cli'
|
|
|
|
import { Application } from './app'
|
2019-05-24 21:46:44 +03:00
|
|
|
import electronDebug = require('electron-debug')
|
2018-08-31 16:41:28 +03: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 14:02:07 +03:00
|
|
|
app.on('window-all-closed', () => {
|
|
|
|
app.quit()
|
|
|
|
})
|
|
|
|
|
2018-08-31 16:41:28 +03:00
|
|
|
process.on('uncaughtException' as any, err => {
|
|
|
|
console.log(err)
|
|
|
|
application.broadcast('uncaughtException', err)
|
|
|
|
})
|
|
|
|
|
|
|
|
app.on('second-instance', (_event, argv, cwd) => {
|
2018-09-20 14:01:42 +03:00
|
|
|
application.send('host:second-instance', parseArgs(argv, cwd), cwd)
|
2018-08-31 16:41:28 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
const argv = parseArgs(process.argv, process.cwd())
|
|
|
|
|
|
|
|
if (!app.requestSingleInstanceLock()) {
|
|
|
|
app.quit()
|
2019-08-07 16:10:00 +03:00
|
|
|
app.exit(0)
|
2018-08-31 16:41:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (argv.d) {
|
2019-05-24 22:19:08 +03:00
|
|
|
electronDebug({
|
|
|
|
isEnabled: true,
|
|
|
|
showDevTools: true,
|
2019-11-26 17:51:31 +03:00
|
|
|
devToolsMode: 'undocked',
|
2019-05-24 22:19:08 +03:00
|
|
|
})
|
2018-08-31 16:41:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
app.on('ready', () => {
|
2018-09-05 11:24:16 +03:00
|
|
|
if (process.platform === 'darwin') {
|
|
|
|
app.dock.setMenu(Menu.buildFromTemplate([
|
|
|
|
{
|
|
|
|
label: 'New window',
|
|
|
|
click () {
|
|
|
|
this.app.newWindow()
|
|
|
|
}
|
2018-08-31 16:41:28 +03:00
|
|
|
}
|
2018-09-05 11:24:16 +03:00
|
|
|
]))
|
|
|
|
}
|
2019-02-10 02:23:49 +03:00
|
|
|
application.init()
|
2018-11-11 15:24:27 +03:00
|
|
|
application.newWindow({ hidden: argv.hidden })
|
2018-08-31 16:41:28 +03:00
|
|
|
})
|