feat: add some funcs
This commit is contained in:
+16
-6
@@ -4,6 +4,9 @@ import { paths } from './paths'
|
||||
import { config } from '../shared/config'
|
||||
import { fetchText } from './download'
|
||||
import { emit } from './events'
|
||||
import type { PackMeta } from '../shared/ipc'
|
||||
|
||||
export type { PackMeta }
|
||||
|
||||
/**
|
||||
* Gestion du modpack côté launcher :
|
||||
@@ -15,11 +18,17 @@ import { emit } from './events'
|
||||
* comportement "pas de re-download complet à chaque update" recherché.
|
||||
*/
|
||||
|
||||
export interface PackMeta {
|
||||
name: string
|
||||
version: string
|
||||
minecraft: string
|
||||
neoforge: string
|
||||
/** Dernière PackMeta lue avec succès (pour l'affichage UI, y compris hors flux Jouer). */
|
||||
let lastMeta: PackMeta | null = null
|
||||
|
||||
/** Renvoie la dernière PackMeta connue, ou la récupère si jamais lue. Tolérant au offline. */
|
||||
export async function getPackMetaCached(): Promise<PackMeta | null> {
|
||||
if (lastMeta) return lastMeta
|
||||
try {
|
||||
return await fetchPackMeta()
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
/** Télécharge et parse le pack.toml distant. */
|
||||
@@ -47,12 +56,13 @@ export async function fetchPackMeta(): Promise<PackMeta> {
|
||||
)
|
||||
}
|
||||
|
||||
return {
|
||||
lastMeta = {
|
||||
name: data.name ?? 'Modpack',
|
||||
version: data.version ?? '0',
|
||||
minecraft,
|
||||
neoforge
|
||||
}
|
||||
return lastMeta
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user