fixed startup event oder - fixes #6511

This commit is contained in:
Eugene Pankov
2022-05-30 23:27:01 +02:00
parent b3df681753
commit 7437aaffcf
2 changed files with 38 additions and 35 deletions

View File

@@ -6,28 +6,29 @@ import * as gracefulFS from 'graceful-fs'
import { app } from 'electron' import { app } from 'electron'
import { promisify } from 'util' import { promisify } from 'util'
export async function migrateConfig (): Promise<void> { export function migrateConfig (): void {
const configPath = path.join(app.getPath('userData'), 'config.yaml') const configPath = path.join(app.getPath('userData'), 'config.yaml')
const legacyConfigPath = path.join(app.getPath('userData'), '../terminus', 'config.yaml') const legacyConfigPath = path.join(app.getPath('userData'), '../terminus', 'config.yaml')
if (await fs.exists(legacyConfigPath) && ( if (fs.existsSync(legacyConfigPath) && (
!await fs.exists(configPath) || !fs.existsSync(configPath) ||
(await fs.stat(configPath)).mtime < (await fs.stat(legacyConfigPath)).mtime fs.statSync(configPath).mtime < fs.statSync(legacyConfigPath).mtime
)) { )) {
await fs.writeFile(configPath, await fs.readFile(legacyConfigPath)) fs.writeFileSync(configPath, fs.readFileSync(legacyConfigPath))
} }
} }
export async function loadConfig (): Promise<any> { export function loadConfig (): any {
await migrateConfig() migrateConfig()
const configPath = path.join(app.getPath('userData'), 'config.yaml') const configPath = path.join(app.getPath('userData'), 'config.yaml')
if (await fs.exists(configPath)) { if (fs.existsSync(configPath)) {
return yaml.load(await fs.readFile(configPath, 'utf8')) return yaml.load(fs.readFileSync(configPath, 'utf8'))
} else { } else {
return {} return {}
} }
} }
const configPath = path.join(app.getPath('userData'), 'config.yaml') const configPath = path.join(app.getPath('userData'), 'config.yaml')
let _configSaveInProgress = Promise.resolve() let _configSaveInProgress = Promise.resolve()

View File

@@ -15,43 +15,45 @@ if (!process.env.TABBY_PLUGINS) {
const argv = parseArgs(process.argv, process.cwd()) const argv = parseArgs(process.argv, process.cwd())
const application = loadConfig().catch(err => { // eslint-disable-next-line @typescript-eslint/init-declarations
let configStore: any
try {
configStore = loadConfig()
} catch (err) {
dialog.showErrorBox('Could not read config', err.message) dialog.showErrorBox('Could not read config', err.message)
app.exit(1) app.exit(1)
}).then(configStore => { }
const _application = new Application(configStore)
ipcMain.on('app:new-window', () => { const application = new Application(configStore)
_application.newWindow()
})
process.on('uncaughtException' as any, err => { ipcMain.on('app:new-window', () => {
application.newWindow()
})
process.on('uncaughtException' as any, err => {
console.log(err) console.log(err)
_application.broadcast('uncaughtException', err) application.broadcast('uncaughtException', err)
}) })
if (argv.d) { if (argv.d) {
electronDebug({ electronDebug({
isEnabled: true, isEnabled: true,
showDevTools: true, showDevTools: true,
devToolsMode: 'undocked', devToolsMode: 'undocked',
}) })
} }
return _application
})
app.on('activate', async () => { app.on('activate', async () => {
if (!(await application).hasWindows()) { if (!application.hasWindows()) {
(await application).newWindow() application.newWindow()
} else { } else {
(await application).focus() application.focus()
} }
}) })
app.on('second-instance', async (_event, newArgv, cwd) => { app.on('second-instance', async (_event, newArgv, cwd) => {
(await application).handleSecondInstance(newArgv, cwd) application.handleSecondInstance(newArgv, cwd)
}) })
if (!app.requestSingleInstanceLock()) { if (!app.requestSingleInstanceLock()) {
@@ -71,9 +73,9 @@ app.on('ready', async () => {
])) ]))
} }
(await application).init() application.init()
const window = await (await application).newWindow({ hidden: argv.hidden }) const window = await application.newWindow({ hidden: argv.hidden })
await window.ready await window.ready
window.passCliArguments(process.argv, process.cwd(), false) window.passCliArguments(process.argv, process.cwd(), false)
window.focus() window.focus()