Skip to content

Commit

Permalink
fix: Try to avoid the dead lock in initial launch
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed Jun 9, 2023
1 parent d48788a commit 440bd04
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion xmcl-electron-app/main/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import zh from './locales/zh-CN.yaml'
import { createI18n } from './utils/i18n'
import { darkIcon } from './utils/icons'
import { trackWindowSize } from './utils/windowSizeTracker'
import { createPromiseSignal } from '@xmcl/runtime/lib/util/promiseSignal'

export default class Controller implements LauncherAppController {
protected windowsVersion?: { major: number; minor: number; build: number }
Expand Down Expand Up @@ -105,6 +106,9 @@ export default class Controller implements LauncherAppController {
}
}

private baseServiceSignal = createPromiseSignal()
private isFirstLaunch = false

constructor(protected app: ElectronLauncherApp) {
plugins.forEach(p => p.call(this))

Expand Down Expand Up @@ -366,7 +370,10 @@ export default class Controller implements LauncherAppController {
const minHeight = man.minHeight ?? 600

if (this.app.platform.name === 'linux') {
await this.app.serviceManager.get(BaseService).initialize()
if (!this.isFirstLaunch) {
this.baseServiceSignal.accept(this.app.serviceManager.get(BaseService).initialize())
await this.baseServiceSignal.promise.catch(() => { /* ignore */ })
}
}

const browser = new BrowserWindow({
Expand Down Expand Up @@ -473,6 +480,8 @@ export default class Controller implements LauncherAppController {
}

async processFirstLaunch(): Promise<{ path: string; instancePath: string; locale: string }> {
this.isFirstLaunch = true
this.baseServiceSignal.reject(new Error('Abort base service init waiting since this is first laucnh'))
return new Promise<{ path: string; instancePath: string; locale: string }>((resolve) => {
ipcMain.handleOnce('bootstrap', (_, path, instancePath, locale) => {
resolve({ path, instancePath, locale })
Expand Down

0 comments on commit 440bd04

Please sign in to comment.