Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7d57ea0ca9 | |||
| 4756420f8d | |||
| 48fa508540 | |||
| 5214d042af | |||
| 073f0b2349 |
@@ -21,7 +21,7 @@ on:
|
||||
options: [none, patch, minor, major]
|
||||
|
||||
jobs:
|
||||
publish-win:
|
||||
publish:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: electronuserland/builder:20-wine
|
||||
@@ -45,6 +45,9 @@ jobs:
|
||||
- name: Build Windows installer
|
||||
run: npm run build:win
|
||||
|
||||
- name: Build Linux installers
|
||||
run: npm run build:linux
|
||||
|
||||
- name: Publish to Gitea release
|
||||
run: node scripts/publish-gitea.mjs
|
||||
env:
|
||||
|
||||
@@ -113,21 +113,24 @@ Publier une nouvelle version :
|
||||
```bash
|
||||
npm version patch # bump 0.1.0 -> 0.1.1 (la version EST la source de vérité)
|
||||
export GITEA_TOKEN=xxxxx # token Gitea (scope write:repository)
|
||||
npm run publish:win # build l'installeur + upload latest.yml/installeur/.blockmap
|
||||
npm run publish # build Windows + Linux puis upload de tous les artefacts
|
||||
```
|
||||
|
||||
`scripts/publish-gitea.mjs` crée la release `latest` si besoin, supprime les
|
||||
anciens assets puis uploade les nouveaux. URL/owner/repo/tag sont surchargeables
|
||||
via les variables `GITEA_URL` / `GITEA_OWNER` / `GITEA_REPO` / `GITEA_TAG`.
|
||||
`scripts/publish-gitea.mjs` crée la release `latest` si besoin, supprime **tous**
|
||||
les anciens assets puis uploade les nouveaux (Windows + Linux). C'est pourquoi on
|
||||
build les deux plateformes avant de publier (`build:all`) : une publication ne
|
||||
contenant qu'une plateforme effacerait l'autre. URL/owner/repo/tag sont
|
||||
surchargeables via `GITEA_URL` / `GITEA_OWNER` / `GITEA_REPO` / `GITEA_TAG`.
|
||||
|
||||
**Publier via Gitea Actions (CI, déclenchement manuel)** — au lieu de builder en
|
||||
local, tu peux lancer le workflow `.gitea/workflows/publish.yml` depuis l'onglet
|
||||
*Actions* du repo (bouton « Run workflow »). Il build l'installeur Windows sous
|
||||
Linux via Wine (image `electronuserland/builder`) puis publie sur la release
|
||||
*Actions* du repo (bouton « Run workflow »). Sur un runner Linux (image
|
||||
`electronuserland/builder`), il build l'**installeur Windows** (NSIS, via Wine) et
|
||||
les **paquets Linux** (AppImage + .deb), puis publie le tout sur la release
|
||||
`latest`. Optionnellement, l'input `bump` (patch/minor/major) incrémente la
|
||||
version et pousse le commit avant le build. Pré-requis : Gitea Actions activé +
|
||||
un act_runner enregistré (label `ubuntu-latest`, à adapter) ; le token auto
|
||||
`secrets.GITEA_TOKEN` suffit s'il a le droit d'écrire les releases.
|
||||
un act_runner enregistré (label `ubuntu-latest`, à adapter) ; un secret repo
|
||||
`RELEASE_TOKEN` (scope `write:repository`) pour publier la release.
|
||||
|
||||
> Tester le flux en dev : `dev-app-update.yml` (déjà présent) pointe sur la même
|
||||
> URL ; avec une version distante > version locale, le bandeau de maj apparaît
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 31 KiB |
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 8.6 KiB |
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "oflauncher",
|
||||
"version": "1.0.0",
|
||||
"version": "2.0.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "oflauncher",
|
||||
"version": "1.0.0",
|
||||
"version": "2.0.0",
|
||||
"hasInstallScript": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
|
||||
+4
-2
@@ -1,10 +1,11 @@
|
||||
{
|
||||
"name": "oflauncher",
|
||||
"version": "1.0.0",
|
||||
"version": "2.0.0",
|
||||
"description": "Launcher Minecraft custom pour le modpack ATM10 (1.21.1 / NeoForge)",
|
||||
"main": "./out/main/index.js",
|
||||
"author": "OFLauncher",
|
||||
"license": "MIT",
|
||||
"homepage": "https://gitea.ldpt.fr/zertus/OFLauncher",
|
||||
"scripts": {
|
||||
"dev": "electron-vite dev",
|
||||
"build": "electron-vite build",
|
||||
@@ -14,7 +15,8 @@
|
||||
"start": "electron-vite preview",
|
||||
"build:win": "npm run build && electron-builder --win --config electron-builder.yml",
|
||||
"build:linux": "npm run build && electron-builder --linux --config electron-builder.yml",
|
||||
"publish:win": "npm run build:win && node scripts/publish-gitea.mjs",
|
||||
"build:all": "npm run build && electron-builder --win --linux --config electron-builder.yml",
|
||||
"publish": "npm run build:all && node scripts/publish-gitea.mjs",
|
||||
"postinstall": "electron-builder install-app-deps"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* Génère le logo/icône du launcher : monogramme "OF" en style voxel (blocs
|
||||
* biseautés façon Minecraft) sur un badge sombre arrondi, accent vert du thème.
|
||||
*
|
||||
* node scripts/gen-logo.mjs -> build/icon.svg
|
||||
* node scripts/gen-logo.mjs --png -> + build/icon.png (1024px) via @resvg/resvg-js
|
||||
*
|
||||
* electron-builder dérive ensuite l'ICO Windows et les PNG Linux depuis
|
||||
* build/icon.png (directories.buildResources = build).
|
||||
*/
|
||||
import { writeFile } from 'node:fs/promises'
|
||||
import { join } from 'node:path'
|
||||
|
||||
const SIZE = 512
|
||||
const OUT = join(process.cwd(), 'build')
|
||||
|
||||
// Palette (cohérente avec src/renderer/src/index.css).
|
||||
const C = {
|
||||
bgTop: '#1b2330',
|
||||
bgBottom: '#0d1014',
|
||||
border: '#2b3444',
|
||||
base: '#3fb950', // vert accent
|
||||
light: '#74e08a', // arête haut/gauche (lumière)
|
||||
dark: '#218a3b' // arête bas/droite (ombre)
|
||||
}
|
||||
|
||||
// Matrices pixel des lettres (1 = bloc plein).
|
||||
const O = ['01110', '10001', '10001', '10001', '10001', '10001', '01110']
|
||||
const F = ['1111', '1000', '1000', '1110', '1000', '1000', '1000']
|
||||
|
||||
const ROWS = 7
|
||||
const GAP_COLS = 1
|
||||
const COLS = O[0].length + GAP_COLS + F[0].length // 5 + 1 + 4 = 10
|
||||
|
||||
const cell = 40 // pas de la grille
|
||||
const blockGap = 6 // espace entre blocs (effet grille pixel)
|
||||
const bs = cell - blockGap // taille d'un bloc
|
||||
const bevel = Math.round(bs * 0.18) // épaisseur du biseau
|
||||
|
||||
const gridW = COLS * cell
|
||||
const gridH = ROWS * cell
|
||||
const x0 = (SIZE - gridW) / 2
|
||||
const y0 = (SIZE - gridH) / 2
|
||||
|
||||
/** Un bloc voxel : base + arêtes claires (haut/gauche) et sombres (bas/droite). */
|
||||
function block(col, row) {
|
||||
const x = x0 + col * cell + blockGap / 2
|
||||
const y = y0 + row * cell + blockGap / 2
|
||||
const t = bevel
|
||||
return [
|
||||
`<rect x="${x}" y="${y}" width="${bs}" height="${bs}" fill="${C.base}"/>`,
|
||||
`<rect x="${x}" y="${y}" width="${bs}" height="${t}" fill="${C.light}"/>`,
|
||||
`<rect x="${x}" y="${y}" width="${t}" height="${bs}" fill="${C.light}"/>`,
|
||||
`<rect x="${x}" y="${y + bs - t}" width="${bs}" height="${t}" fill="${C.dark}"/>`,
|
||||
`<rect x="${x + bs - t}" y="${y}" width="${t}" height="${bs}" fill="${C.dark}"/>`
|
||||
].join('')
|
||||
}
|
||||
|
||||
/** Rend une matrice à un décalage de colonnes donné. */
|
||||
function letter(matrix, colOffset) {
|
||||
const out = []
|
||||
matrix.forEach((line, r) => {
|
||||
;[...line].forEach((px, c) => {
|
||||
if (px === '1') out.push(block(colOffset + c, r))
|
||||
})
|
||||
})
|
||||
return out.join('')
|
||||
}
|
||||
|
||||
const blocks = letter(O, 0) + letter(F, O[0].length + GAP_COLS)
|
||||
|
||||
const radius = 112
|
||||
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${SIZE}" height="${SIZE}" viewBox="0 0 ${SIZE} ${SIZE}">
|
||||
<defs>
|
||||
<linearGradient id="bg" x1="0" y1="0" x2="0" y2="1">
|
||||
<stop offset="0" stop-color="${C.bgTop}"/>
|
||||
<stop offset="1" stop-color="${C.bgBottom}"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<rect x="6" y="6" width="${SIZE - 12}" height="${SIZE - 12}" rx="${radius}" ry="${radius}" fill="url(#bg)" stroke="${C.border}" stroke-width="6"/>
|
||||
<g shape-rendering="crispEdges">
|
||||
${blocks}
|
||||
</g>
|
||||
</svg>
|
||||
`
|
||||
|
||||
async function main() {
|
||||
await writeFile(join(OUT, 'icon.svg'), svg)
|
||||
console.log('✓ build/icon.svg')
|
||||
|
||||
if (process.argv.includes('--png')) {
|
||||
const { Resvg } = await import('@resvg/resvg-js')
|
||||
const png = new Resvg(svg, { fitTo: { mode: 'width', value: 1024 } })
|
||||
.render()
|
||||
.asPng()
|
||||
await writeFile(join(OUT, 'icon.png'), png)
|
||||
console.log('✓ build/icon.png (1024px)')
|
||||
}
|
||||
}
|
||||
|
||||
main().catch((e) => {
|
||||
console.error(e.message)
|
||||
process.exit(1)
|
||||
})
|
||||
@@ -31,12 +31,22 @@ if (!TOKEN) {
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
/** Fichiers de dist/ à publier pour l'auto-update Windows. */
|
||||
/**
|
||||
* Fichiers de dist/ à publier pour l'auto-update.
|
||||
* - Windows : latest.yml + l'installeur NSIS (+ .blockmap)
|
||||
* - Linux : latest-linux.yml + l'AppImage (+ .blockmap) ; le .deb est publié
|
||||
* pour téléchargement manuel (electron-updater ne l'utilise pas).
|
||||
* electron-updater choisit le bon latest*.yml selon la plateforme.
|
||||
*/
|
||||
function isUpdateArtifact(name) {
|
||||
return (
|
||||
name === 'latest.yml' ||
|
||||
name === 'latest-linux.yml' ||
|
||||
name.endsWith('-setup.exe') ||
|
||||
name.endsWith('-setup.exe.blockmap')
|
||||
name.endsWith('-setup.exe.blockmap') ||
|
||||
name.endsWith('.AppImage') ||
|
||||
name.endsWith('.AppImage.blockmap') ||
|
||||
name.endsWith('.deb')
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+9
-2
@@ -6,6 +6,7 @@ import {
|
||||
type DeviceCodeInfo,
|
||||
type UpdateStatus
|
||||
} from '../shared/ipc'
|
||||
import * as logger from './logger'
|
||||
|
||||
/** Fenêtre principale, définie au démarrage (src/main/index.ts). */
|
||||
let mainWindow: BrowserWindow | null = null
|
||||
@@ -21,8 +22,14 @@ function send(channel: string, payload: unknown): void {
|
||||
}
|
||||
|
||||
export const emit = {
|
||||
progress: (e: ProgressEvent): void => send(IPC_EVENT.progress, e),
|
||||
gameLog: (l: GameLogLine): void => send(IPC_EVENT.gameLog, l),
|
||||
progress: (e: ProgressEvent): void => {
|
||||
if (e.phase === 'error') logger.write(`[ERREUR] ${e.message}`)
|
||||
send(IPC_EVENT.progress, e)
|
||||
},
|
||||
gameLog: (l: GameLogLine): void => {
|
||||
logger.write(l.line)
|
||||
send(IPC_EVENT.gameLog, l)
|
||||
},
|
||||
gameClosed: (code: number | null): void => send(IPC_EVENT.gameClosed, code),
|
||||
authCode: (info: DeviceCodeInfo): void => send(IPC_EVENT.authCode, info),
|
||||
updateStatus: (s: UpdateStatus): void => send(IPC_EVENT.updateStatus, s)
|
||||
|
||||
+7
-3
@@ -1,9 +1,10 @@
|
||||
import { app, shell, BrowserWindow, ipcMain } from 'electron'
|
||||
import { join } from 'path'
|
||||
import { setMainWindow } from './events'
|
||||
import { IPC, type UserSettings } from '../shared/ipc'
|
||||
import { IPC, type UserSettings, type PlayOptions } from '../shared/ipc'
|
||||
import { login, logout, restoreSession, getCurrent } from './auth'
|
||||
import { play } from './play'
|
||||
import { play, stopGame } from './play'
|
||||
import { getPackMetaCached } from './modpack'
|
||||
import { getSettings, setSettings } from './settings'
|
||||
import { paths } from './paths'
|
||||
import { initUpdater, quitAndInstallUpdate } from './updater'
|
||||
@@ -50,11 +51,14 @@ function registerIpc(): void {
|
||||
ipcMain.handle(IPC.authGetProfile, async () => {
|
||||
return getCurrent()?.profile ?? (await restoreSession())
|
||||
})
|
||||
ipcMain.handle(IPC.play, () => play())
|
||||
ipcMain.handle(IPC.play, (_e, opts: PlayOptions | undefined) => play(opts))
|
||||
ipcMain.handle(IPC.playStop, () => stopGame())
|
||||
ipcMain.handle(IPC.packGet, () => getPackMetaCached())
|
||||
ipcMain.handle(IPC.settingsGet, () => getSettings())
|
||||
ipcMain.handle(IPC.settingsSet, (_e, s: UserSettings) => setSettings(s))
|
||||
ipcMain.handle(IPC.appVersion, () => app.getVersion())
|
||||
ipcMain.handle(IPC.openInstanceDir, () => shell.openPath(paths.instanceDir))
|
||||
ipcMain.handle(IPC.openLogsDir, () => shell.openPath(paths.logsDir))
|
||||
ipcMain.handle(IPC.updateInstall, () => quitAndInstallUpdate())
|
||||
}
|
||||
|
||||
|
||||
+49
-19
@@ -1,8 +1,10 @@
|
||||
import { existsSync } from 'fs'
|
||||
import { join } from 'path'
|
||||
import { getVersionList, install, installNeoForged } from '@xmcl/installer'
|
||||
import { getVersionList, installTask, installNeoForgedTask } from '@xmcl/installer'
|
||||
import type { Task } from '@xmcl/task'
|
||||
import { paths } from './paths'
|
||||
import { emit } from './events'
|
||||
import { type LaunchPhase } from '../shared/ipc'
|
||||
import { downloadDispatcher, DOWNLOAD_CONCURRENCY, withRetries } from './net'
|
||||
|
||||
/** Options de téléchargement communes : dispatcher tolérant + concurrence bridée. */
|
||||
@@ -12,6 +14,25 @@ const downloadOptions = {
|
||||
librariesDownloadConcurrency: DOWNLOAD_CONCURRENCY
|
||||
}
|
||||
|
||||
/**
|
||||
* Exécute une task @xmcl en émettant sa progression réelle (0..1) vers le
|
||||
* renderer. On lit la progression cumulée de la task racine ; on n'émet qu'au
|
||||
* changement de pourcentage entier pour ne pas inonder l'IPC.
|
||||
*/
|
||||
async function runWithProgress<T>(phase: LaunchPhase, message: string, task: Task<T>): Promise<T> {
|
||||
let lastPct = -1
|
||||
return task.startAndWait({
|
||||
onUpdate() {
|
||||
if (task.total <= 0) return
|
||||
const ratio = task.progress / task.total
|
||||
const pct = Math.floor(ratio * 100)
|
||||
if (pct === lastPct) return
|
||||
lastPct = pct
|
||||
emit.progress({ phase, message, progress: Math.min(1, ratio) })
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Installe le runtime Minecraft (vanilla 1.21.1) puis NeoForge dans
|
||||
* paths.gameRoot. Les deux étapes sont idempotentes : si la version est déjà
|
||||
@@ -25,25 +46,27 @@ function versionInstalled(id: string): boolean {
|
||||
return existsSync(join(paths.gameRoot, 'versions', id, `${id}.json`))
|
||||
}
|
||||
|
||||
/** Installe Minecraft vanilla <version> (json + jar + assets + libraries). */
|
||||
export async function installMinecraft(version: string): Promise<void> {
|
||||
if (versionInstalled(version)) return
|
||||
/**
|
||||
* Installe Minecraft vanilla <version> (json + jar + assets + libraries).
|
||||
* `force` saute le court-circuit "déjà installé" pour revalider/réparer les
|
||||
* fichiers (l'install @xmcl ignore les fichiers déjà valides par checksum).
|
||||
*/
|
||||
export async function installMinecraft(version: string, force = false): Promise<void> {
|
||||
if (!force && versionInstalled(version)) return
|
||||
|
||||
emit.progress({ phase: 'minecraft', message: `Minecraft ${version} : métadonnées…`, progress: undefined })
|
||||
const list = await getVersionList()
|
||||
const meta = list.versions.find((v) => v.id === version)
|
||||
if (!meta) throw new Error(`Version Minecraft introuvable : ${version}`)
|
||||
|
||||
emit.progress({
|
||||
phase: 'minecraft',
|
||||
message: `Installation de Minecraft ${version} (assets + libs)…`,
|
||||
progress: undefined
|
||||
})
|
||||
const label = force
|
||||
? `Vérification de Minecraft ${version}…`
|
||||
: `Installation de Minecraft ${version} (assets + libs)…`
|
||||
|
||||
// ~3700 assets : on réessaie l'install entière plusieurs fois. Chaque passe
|
||||
// ignore les fichiers déjà valides et ne reprend que les manquants.
|
||||
await withRetries(
|
||||
() => install(meta, paths.gameRoot, downloadOptions),
|
||||
() => runWithProgress('minecraft', label, installTask(meta, paths.gameRoot, downloadOptions)),
|
||||
5,
|
||||
(attempt) =>
|
||||
emit.progress({
|
||||
@@ -61,26 +84,33 @@ export async function installMinecraft(version: string): Promise<void> {
|
||||
export async function installNeoForge(
|
||||
neoforge: string,
|
||||
minecraft: string,
|
||||
javaPath: string
|
||||
javaPath: string,
|
||||
force = false
|
||||
): Promise<string> {
|
||||
// @xmcl nomme la version installée "neoforge-<version>" (ex. neoforge-21.1.224).
|
||||
// Si elle est déjà présente, on saute l'install (idempotent, comme Minecraft).
|
||||
const expectedId = `neoforge-${neoforge}`
|
||||
if (versionInstalled(expectedId)) {
|
||||
if (!force && versionInstalled(expectedId)) {
|
||||
void minecraft
|
||||
return expectedId
|
||||
}
|
||||
|
||||
emit.progress({ phase: 'neoforge', message: `Installation de NeoForge ${neoforge}…`, progress: undefined })
|
||||
const label = force
|
||||
? `Vérification de NeoForge ${neoforge}…`
|
||||
: `Installation de NeoForge ${neoforge}…`
|
||||
|
||||
// installNeoForged retourne l'id de version installée à lancer.
|
||||
// installNeoForgedTask retourne l'id de version installée à lancer.
|
||||
const versionId = await withRetries(
|
||||
() =>
|
||||
installNeoForged('neoforge', neoforge, paths.gameRoot, {
|
||||
java: javaPath,
|
||||
dispatcher: downloadDispatcher,
|
||||
librariesDownloadConcurrency: DOWNLOAD_CONCURRENCY
|
||||
}),
|
||||
runWithProgress(
|
||||
'neoforge',
|
||||
label,
|
||||
installNeoForgedTask('neoforge', neoforge, paths.gameRoot, {
|
||||
java: javaPath,
|
||||
dispatcher: downloadDispatcher,
|
||||
librariesDownloadConcurrency: DOWNLOAD_CONCURRENCY
|
||||
})
|
||||
),
|
||||
3,
|
||||
(attempt) =>
|
||||
emit.progress({
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import { createWriteStream, type WriteStream } from 'fs'
|
||||
import { paths } from './paths'
|
||||
|
||||
/**
|
||||
* Journalisation sur disque du launcher (logs/launcher.log).
|
||||
*
|
||||
* Capture tout ce qui transite par `events.ts` (sortie jeu + packwiz + messages
|
||||
* de phase + erreurs), pour pouvoir dépanner un joueur à distance. Le fichier
|
||||
* est tronqué au début de chaque session "Jouer".
|
||||
*/
|
||||
|
||||
let stream: WriteStream | null = null
|
||||
|
||||
function ts(): string {
|
||||
return new Date().toISOString()
|
||||
}
|
||||
|
||||
/** Ouvre (en tronquant) un nouveau fichier de log et écrit un en-tête. */
|
||||
export function startSession(): void {
|
||||
stream?.end()
|
||||
stream = createWriteStream(paths.launcherLogFile, { flags: 'w' })
|
||||
stream.write(`=== Session OFLauncher ${ts()} ===\n`)
|
||||
}
|
||||
|
||||
/** Ajoute une ligne au log courant (no-op si aucune session ouverte). */
|
||||
export function write(line: string): void {
|
||||
if (!stream) return
|
||||
const text = line.endsWith('\n') ? line : `${line}\n`
|
||||
stream.write(text)
|
||||
}
|
||||
+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
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,6 +41,16 @@ class LauncherPaths {
|
||||
return join(this.root, 'settings.json')
|
||||
}
|
||||
|
||||
/** Dossier des logs du launcher (install/Java/packwiz/jeu). */
|
||||
get logsDir(): string {
|
||||
return this.ensure(join(this.root, 'logs'))
|
||||
}
|
||||
|
||||
/** Fichier de log courant du launcher. */
|
||||
get launcherLogFile(): string {
|
||||
return join(this.logsDir, 'launcher.log')
|
||||
}
|
||||
|
||||
/** jar packwiz-installer-bootstrap embarqué dans les resources. */
|
||||
get packwizBootstrapJar(): string {
|
||||
// En prod, electron-builder copie resources/ via extraResources.
|
||||
|
||||
+15
-3
@@ -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 d’abord.')
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -7,7 +7,9 @@ import {
|
||||
type GameLogLine,
|
||||
type UserSettings,
|
||||
type DeviceCodeInfo,
|
||||
type UpdateStatus
|
||||
type UpdateStatus,
|
||||
type PlayOptions,
|
||||
type PackMeta
|
||||
} from '../shared/ipc'
|
||||
|
||||
/** API typée exposée au renderer via window.api. */
|
||||
@@ -18,7 +20,9 @@ const api = {
|
||||
getProfile: (): Promise<PlayerProfile | null> => ipcRenderer.invoke(IPC.authGetProfile),
|
||||
|
||||
// --- Jouer (install + sync + launch) ---
|
||||
play: (): Promise<void> => ipcRenderer.invoke(IPC.play),
|
||||
play: (opts?: PlayOptions): Promise<void> => ipcRenderer.invoke(IPC.play, opts),
|
||||
stopGame: (): Promise<boolean> => ipcRenderer.invoke(IPC.playStop),
|
||||
getPackMeta: (): Promise<PackMeta | null> => ipcRenderer.invoke(IPC.packGet),
|
||||
|
||||
// --- Réglages ---
|
||||
getSettings: (): Promise<UserSettings> => ipcRenderer.invoke(IPC.settingsGet),
|
||||
@@ -29,6 +33,9 @@ const api = {
|
||||
/** Ouvre le dossier d'instance (mods/config/saves) dans l'explorateur. */
|
||||
openInstanceDir: (): Promise<string> => ipcRenderer.invoke(IPC.openInstanceDir),
|
||||
|
||||
/** Ouvre le dossier des logs du launcher. */
|
||||
openLogsDir: (): Promise<string> => ipcRenderer.invoke(IPC.openLogsDir),
|
||||
|
||||
/** Quitte et installe la mise à jour téléchargée. */
|
||||
installUpdate: (): Promise<void> => ipcRenderer.invoke(IPC.updateInstall),
|
||||
|
||||
|
||||
@@ -4,9 +4,15 @@ import type {
|
||||
ProgressEvent,
|
||||
GameLogLine,
|
||||
DeviceCodeInfo,
|
||||
UpdateStatus
|
||||
UpdateStatus,
|
||||
PackMeta
|
||||
} from '../../shared/ipc'
|
||||
|
||||
/** Découpe une chaîne d'args JVM en tableau (espaces, vides ignorés). */
|
||||
function parseArgs(s: string): string[] {
|
||||
return s.split(/\s+/).filter(Boolean)
|
||||
}
|
||||
|
||||
type Status = 'loading' | 'logged-out' | 'logged-in' | 'working' | 'running'
|
||||
|
||||
export default function App(): JSX.Element {
|
||||
@@ -17,8 +23,10 @@ export default function App(): JSX.Element {
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [authCode, setAuthCode] = useState<DeviceCodeInfo | null>(null)
|
||||
const [maxMemoryMb, setMaxMemoryMb] = useState(8192)
|
||||
const [jvmArgs, setJvmArgs] = useState('')
|
||||
const [appVersion, setAppVersion] = useState('')
|
||||
const [update, setUpdate] = useState<UpdateStatus | null>(null)
|
||||
const [pack, setPack] = useState<PackMeta | null>(null)
|
||||
const consoleRef = useRef<HTMLDivElement>(null)
|
||||
|
||||
// Restaure la session + réglages au démarrage.
|
||||
@@ -30,10 +38,13 @@ export default function App(): JSX.Element {
|
||||
window.api.getAppVersion()
|
||||
])
|
||||
setMaxMemoryMb(s.maxMemoryMb)
|
||||
setJvmArgs(s.extraJvmArgs.join(' '))
|
||||
setAppVersion(v)
|
||||
setProfile(p)
|
||||
setStatus(p ? 'logged-in' : 'logged-out')
|
||||
})()
|
||||
// Récupère le nom/version réels du pack (tolérant au offline).
|
||||
void window.api.getPackMeta().then((m) => m && setPack(m))
|
||||
}, [])
|
||||
|
||||
// Abonnements aux événements main -> renderer.
|
||||
@@ -97,13 +108,21 @@ export default function App(): JSX.Element {
|
||||
void window.api.openInstanceDir()
|
||||
}
|
||||
|
||||
async function handlePlay(): Promise<void> {
|
||||
function handleOpenLogs(): void {
|
||||
void window.api.openLogsDir()
|
||||
}
|
||||
|
||||
function handleStop(): void {
|
||||
void window.api.stopGame()
|
||||
}
|
||||
|
||||
async function handlePlay(opts?: { repair?: boolean }): Promise<void> {
|
||||
setError(null)
|
||||
setLogs([])
|
||||
setStatus('working')
|
||||
await window.api.setSettings({ maxMemoryMb, extraJvmArgs: [] })
|
||||
await window.api.setSettings({ maxMemoryMb, extraJvmArgs: parseArgs(jvmArgs) })
|
||||
try {
|
||||
await window.api.play()
|
||||
await window.api.play(opts)
|
||||
} catch (e) {
|
||||
setError(`Échec du lancement : ${(e as Error).message}`)
|
||||
setStatus('logged-in')
|
||||
@@ -178,7 +197,9 @@ export default function App(): JSX.Element {
|
||||
<div className="topbar">
|
||||
<div className="brand">
|
||||
OFLauncher
|
||||
<span className="pack">All The Mods 10 · 1.21.1</span>
|
||||
<span className="pack">
|
||||
{pack ? `${pack.name} · MC ${pack.minecraft}` : 'All The Mods 10 · 1.21.1'}
|
||||
</span>
|
||||
</div>
|
||||
<div className="profile">
|
||||
<img src={`https://mc-heads.net/avatar/${profile?.uuid}`} alt="" />
|
||||
@@ -220,14 +241,34 @@ export default function App(): JSX.Element {
|
||||
onChange={(e) => setMaxMemoryMb(Number(e.target.value))}
|
||||
/>
|
||||
Mo
|
||||
<input
|
||||
className="jvm"
|
||||
type="text"
|
||||
placeholder="Args JVM (avancé)"
|
||||
value={jvmArgs}
|
||||
disabled={busy}
|
||||
onChange={(e) => setJvmArgs(e.target.value)}
|
||||
/>
|
||||
<button className="linkbtn" onClick={() => void handlePlay({ repair: true })} disabled={busy}>
|
||||
Vérifier les fichiers
|
||||
</button>
|
||||
<button className="linkbtn" onClick={handleOpenInstance}>
|
||||
Ouvrir le dossier de l'instance
|
||||
Ouvrir l'instance
|
||||
</button>
|
||||
<button className="linkbtn" onClick={handleOpenLogs}>
|
||||
Ouvrir les logs
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<button className="play" onClick={handlePlay} disabled={busy}>
|
||||
{status === 'running' ? 'En jeu…' : busy ? 'Patiente…' : 'Jouer'}
|
||||
</button>
|
||||
{status === 'running' ? (
|
||||
<button className="play stop" onClick={handleStop}>
|
||||
Arrêter le jeu
|
||||
</button>
|
||||
) : (
|
||||
<button className="play" onClick={() => void handlePlay()} disabled={busy}>
|
||||
{busy ? 'Patiente…' : 'Jouer'}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{error && <div className="error">{error}</div>}
|
||||
</div>
|
||||
|
||||
@@ -123,6 +123,20 @@ body {
|
||||
|
||||
.progress {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
/* Fenêtre réduite : la barre de progression passe sur sa propre ligne
|
||||
(sinon les réglages la compriment jusqu'à la rendre invisible). */
|
||||
@media (max-width: 1200px) {
|
||||
.footer {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.progress {
|
||||
order: -1;
|
||||
flex-basis: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.progress .label {
|
||||
@@ -180,6 +194,15 @@ button.play:disabled {
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
button.play.stop {
|
||||
background: var(--danger);
|
||||
color: #2a0606;
|
||||
}
|
||||
|
||||
button.play.stop:hover:not(:disabled) {
|
||||
background: #ff6258;
|
||||
}
|
||||
|
||||
.center {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
@@ -214,6 +237,7 @@ button.play:disabled {
|
||||
.settings {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
font-size: 13px;
|
||||
color: var(--text-dim);
|
||||
@@ -228,6 +252,10 @@ button.play:disabled {
|
||||
padding: 4px 6px;
|
||||
}
|
||||
|
||||
.settings input.jvm {
|
||||
width: 200px;
|
||||
}
|
||||
|
||||
.error {
|
||||
color: var(--danger);
|
||||
font-size: 13px;
|
||||
|
||||
@@ -67,6 +67,20 @@ export interface UpdateStatus {
|
||||
message?: string
|
||||
}
|
||||
|
||||
/** Métadonnées du modpack lues depuis le pack.toml packwiz distant. */
|
||||
export interface PackMeta {
|
||||
name: string
|
||||
version: string
|
||||
minecraft: string
|
||||
neoforge: string
|
||||
}
|
||||
|
||||
/** Options de la séquence "Jouer". */
|
||||
export interface PlayOptions {
|
||||
/** Force la revérification/redownload des fichiers (réparation). */
|
||||
repair?: boolean
|
||||
}
|
||||
|
||||
/** Réglages utilisateur persistés localement. */
|
||||
export interface UserSettings {
|
||||
/** RAM max allouée à la JVM, en Mo. */
|
||||
@@ -90,6 +104,9 @@ export const IPC = {
|
||||
settingsSet: 'settings:set',
|
||||
appVersion: 'app:version',
|
||||
openInstanceDir: 'instance:open',
|
||||
openLogsDir: 'logs:open',
|
||||
playStop: 'play:stop',
|
||||
packGet: 'pack:get',
|
||||
updateInstall: 'update:install'
|
||||
} as const
|
||||
|
||||
|
||||
Reference in New Issue
Block a user