feat: add some funcs

This commit is contained in:
lucasdpt
2026-06-14 14:23:37 +02:00
parent 48fa508540
commit 4756420f8d
11 changed files with 240 additions and 44 deletions
+15 -3
View File
@@ -7,6 +7,8 @@ import { syncModpack } from './modpack'
import { launchGame } from './launch'
import { getSettings } from './settings'
import { emit } from './events'
import * as logger from './logger'
import type { PlayOptions } from '../shared/ipc'
/** Process de jeu courant (un seul à la fois). */
let gameProcess: ChildProcess | null = null
@@ -20,7 +22,7 @@ let gameProcess: ChildProcess | null = null
* idempotentes, donc à partir du 2e lancement seules les nouveautés du modpack
* sont téléchargées.
*/
export async function play(): Promise<void> {
export async function play(opts?: PlayOptions): Promise<void> {
if (gameProcess) {
throw new Error('Le jeu est déjà en cours.')
}
@@ -30,11 +32,14 @@ export async function play(): Promise<void> {
throw new Error('Non connecté. Connecte-toi avec ton compte Microsoft dabord.')
}
const repair = opts?.repair ?? false
logger.startSession()
try {
const meta = await fetchPackMeta()
const javaPath = await ensureJava()
await installMinecraft(meta.minecraft)
const versionId = await installNeoForge(meta.neoforge, meta.minecraft, javaPath)
await installMinecraft(meta.minecraft, repair)
const versionId = await installNeoForge(meta.neoforge, meta.minecraft, javaPath, repair)
await syncModpack(javaPath)
const settings = await getSettings()
@@ -48,3 +53,10 @@ export async function play(): Promise<void> {
throw e
}
}
/** Tue le process de jeu courant. Renvoie true si un process tournait. */
export function stopGame(): boolean {
if (!gameProcess) return false
gameProcess.kill()
return true
}