Skip to content

Commit

Permalink
fix: Correctly handle the fail to spawn process error
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed Jan 3, 2024
1 parent d41acd5 commit b03492d
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 8 deletions.
8 changes: 8 additions & 0 deletions xmcl-keystone-ui/locales/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,14 @@ launchBlocked:
Kann die Version von <span class="highlight">{version}</span> nicht
ermitteln, um ausführen.
title: Version nicht ausgewählt
launchSpawnProcessFailed:
description: >-
Bitte überprüfen Sie Ihr Java oder erteilen Sie dem Launcher weitere
Berechtigungen und versuchen Sie es erneut.
Sollte dies immer noch nicht funktionieren, wenden Sie sich bitte an die
Entwickler.
title: Spielvorgang konnte nicht gestartet werden
launchUserStatusRefreshFailed:
description: Der aktuelle Benutzerstatus kann nicht aktualisiert werden.
title: Benutzerstatus kann nicht überprüft werden
Expand Down
5 changes: 5 additions & 0 deletions xmcl-keystone-ui/locales/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,11 @@ launchBlocked:
launchNoVersionInstalled:
description: Cannot resolve version <span class="highlight">{version}</span> to launch.
title: No version selected
launchSpawnProcessFailed:
description: >-
Please check your java, or give more permissions tothe launcher and retry.
If this still doesn't work, please contact the developers.
title: Fail to start game process
launchUserStatusRefreshFailed:
description: Cannot refresh current selected user status.
title: Fail to validate user status
Expand Down
8 changes: 8 additions & 0 deletions xmcl-keystone-ui/locales/es-ES.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,14 @@ items:
java:
allocatedLong: Usar Java predeterminada del sistema
allocatedShort: Asignación Automática
launchBlocked:
launchSpawnProcessFailed:
description: >-
Verifique su Java o otorgue más permisos al iniciador y vuelva a
intentarlo.
Si esto aún no funciona, comuníquese con los desarrolladores.
title: No se puede iniciar el proceso del juego
launchStatus:
refreshingUser: Actualizar token de usuario
spawningProcess: ''
Expand Down
7 changes: 7 additions & 0 deletions xmcl-keystone-ui/locales/fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,13 @@ launchBlocked:
Impossible de résoudre la version <span class="highlight">{version}</span>
à lancer.
title: Aucune version sélectionnée
launchSpawnProcessFailed:
description: >-
Veuillez vérifier votre Java ou accorder plus d'autorisations au lanceur
et réessayer.
Si cela ne fonctionne toujours pas, veuillez contacter les développeurs.
title: Impossible de démarrer le processus de jeu
launchUserStatusRefreshFailed:
description: Impossible d'actualiser l'état actuel de l'utilisateur sélectionné.
title: Échec de la validation du statut de l'utilisateur
Expand Down
6 changes: 6 additions & 0 deletions xmcl-keystone-ui/locales/gl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@ diagnosis:
name: Falta o arquivo de índice de activos de {version}.
instances:
addServerDescription: Isto creará un xogo que se lanzará directamente ao servidor.
launchBlocked:
launchSpawnProcessFailed:
description: |-
Comproba o teu java ou dálle máis permisos ao iniciador e téntao de novo.
Se isto aínda non funciona, póñase en contacto cos desenvolvedores.
title: Non se puido iniciar o proceso de xogo
mod:
searchOnCurseforge: Busca {name} en curseforge
setting:
Expand Down
7 changes: 7 additions & 0 deletions xmcl-keystone-ui/locales/ru.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,13 @@ launchBlocked:
Невозможно определить версию <span class="highlight">{version}</span> для
запуска.
title: Версия не выбрана
launchSpawnProcessFailed:
description: >-
Пожалуйста, проверьте свою Java или предоставьте дополнительные разрешения
программе запуска и повторите попытку.
Если это по-прежнему не работает, обратитесь к разработчикам.
title: Не могу запустить игровой процесс
launchUserStatusRefreshFailed:
description: Невозможно обновить текущий выбранный статус пользователя.
title: Не удалось проверить статус пользователя
Expand Down
7 changes: 7 additions & 0 deletions xmcl-keystone-ui/locales/uk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,13 @@ launchBlocked:
Неможливо визначити версію <span class="highlight">{version}</span> для
запуску.
title: Версія не обрана
launchSpawnProcessFailed:
description: >-
Будь ласка, перевірте свою Java або надайте додаткові дозволи програмі
запуску та повторіть спробу.
Якщо це все одно не працює, зв’яжіться з розробниками.
title: Не вдається запустити процес гри
launchUserStatusRefreshFailed:
description: Неможливо оновити поточний статус користувача.
title: Неможливо перевірити статус користувача
Expand Down
7 changes: 6 additions & 1 deletion xmcl-keystone-ui/locales/zh-CN.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,11 @@ launchBlocked:
launchNoVersionInstalled:
description: 找不到 Minecraft 启动。当前版本是 <span class="highlight">{version}</span>。
title: 无法找到安装的 Minecraft
launchSpawnProcessFailed:
description: |-
请检查您的 java,或向启动器授予更多权限,然后重试。
如果仍然无法解决问题,请联系开发人员。
title: 无法启动游戏进程
launchUserStatusRefreshFailed:
description: 无法验证当前账户信息
title: 验证账户失败
Expand Down Expand Up @@ -1183,9 +1188,9 @@ tag:
newTag: 新标签
task:
cancelled: 已取消
clear: 清除已完成的任务
empty: 目前没有运行中的任务
failed: 失败
clear: 清除已完成的任务
manager: 任务管理器
nTaskRunning: '{count} 个任务运行中'
name: 任务 | 任务
Expand Down
3 changes: 3 additions & 0 deletions xmcl-keystone-ui/src/views/AppLaunchBlockedDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ function onException(e: LaunchExceptions) {
} else if (e.userException.type === 'userLoginMinecraftByXboxFailed') {
description.value += t('launchBlocked.userLoginMinecraftByXboxFailed')
}
} else if (e.type === 'launchSpawnProcessFailed') {
title.value = t('launchBlocked.launchSpawnProcessFailed.title')
description.value = t('launchBlocked.launchSpawnProcessFailed.description')
}
isShown.value = true
}
Expand Down
5 changes: 5 additions & 0 deletions xmcl-runtime-api/src/services/LaunchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ export type LaunchExceptions = {
*/
type: 'launchGeneralException'
error: unknown
} | {
/**
* Spawn process failed
*/
type: 'launchSpawnProcessFailed'
} | {
/**
* Unknown java error. Might be empty java path
Expand Down
27 changes: 20 additions & 7 deletions xmcl-runtime/launch/LaunchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { UserTokenStorage, kUserTokenStorage } from '~/user'
import { LauncherApp } from '../app/LauncherApp'
import { UTF8 } from '../util/encoding'
import { LaunchMiddleware } from './LaunchMiddleware'
import { offline } from '@xmcl/user'

@ExposeServiceKey(LaunchServiceKey)
export class LaunchService extends AbstractService implements ILaunchService {
Expand All @@ -35,7 +36,7 @@ export class LaunchService extends AbstractService implements ILaunchService {

#generateOptions(options: LaunchOptions, version: ResolvedVersion, accessToken?: string) {
const user = options.user
const gameProfile = user.profiles[user.selectedProfile]
const gameProfile = user.profiles[user.selectedProfile] ?? offline('Steve').selectedProfile
const javaPath = options.java
const yggdrasilAgent = options.yggdrasilAgent

Expand All @@ -44,6 +45,7 @@ export class LaunchService extends AbstractService implements ILaunchService {
const minMemory: number | undefined = options.maxMemory
const maxMemory: number | undefined = options.minMemory

const launcherName = `X Minecraft Launcher (${this.app.version})`
/**
* Build launch condition
*/
Expand All @@ -63,8 +65,8 @@ export class LaunchService extends AbstractService implements ILaunchService {
},
extraJVMArgs: options.vmOptions?.filter(v => !!v),
extraMCArgs: options.mcOptions?.filter(v => !!v),
launcherBrand: options?.launcherBrand ?? '',
launcherName: options?.launcherName ?? 'XMCL',
launcherBrand: options?.launcherBrand ?? launcherName,
launcherName: options?.launcherName ?? launcherName,
yggdrasilAgent,
prechecks: [],
}
Expand Down Expand Up @@ -216,13 +218,24 @@ export class LaunchService extends AbstractService implements ILaunchService {

// Launch
const process = await this.#track(launch(launchOptions), 'spawn-minecraft-process', operationId)
if (typeof process.pid !== 'number') {
process.once('error', (e) => {
if (e.name === 'Error') {
Object.assign(e, {
name: 'LaunchSpawnProcessError',
})
}
this.error(e)
})
throw new LaunchException({ type: 'launchSpawnProcessFailed' })
}
const processData = {
pid: process.pid!,
pid: process.pid,
options,
process,
ready: false,
}
this.processes[process.pid!] = processData
this.processes[process.pid] = processData

const watcher = createMinecraftProcessWatcher(process)
const errorLogs = [] as string[]
Expand Down Expand Up @@ -288,10 +301,10 @@ export class LaunchService extends AbstractService implements ILaunchService {
errorLog: errorLogs.join('\n'),
})
})
delete this.processes[process.pid!]
delete this.processes[processData.pid]
}).on('minecraft-window-ready', () => {
processData.ready = true
this.emit('minecraft-window-ready', { pid: process.pid, ...options })
this.emit('minecraft-window-ready', { pid: processData.pid, ...options })
})
process.unref()

Expand Down

0 comments on commit b03492d

Please sign in to comment.