mirror of
https://github.com/dream-pep/koring-launcher.git
synced 2026-09-12 05:45:18 +08:00
Replace the Tauri/sidecar architecture with an Electron main process. Adds an electron/ directory (main, preload, handlers, core integrations for @xmcl/*), electron-builder.yml, TypeScript electron config and declarations, and updated IPC utilities (ipc.ts) so frontend uses ipcRenderer/ipcMain. Removes Tauri sidecar and src-tauri artifacts, deletes sidecar sources and keys, updates .gitignore, VSCode recommendations, package scripts and icons, and updates documentation (README, AGENTS, DEV) and frontend stores/apis to reflect the Electron-based architecture and config/auth persistence changes.
153 lines
5.7 KiB
JavaScript
153 lines
5.7 KiB
JavaScript
"use strict";
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
}
|
|
Object.defineProperty(o, k2, desc);
|
|
}) : (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
o[k2] = m[k];
|
|
}));
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
}) : function(o, v) {
|
|
o["default"] = v;
|
|
});
|
|
var __importStar = (this && this.__importStar) || (function () {
|
|
var ownKeys = function(o) {
|
|
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
var ar = [];
|
|
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
return ar;
|
|
};
|
|
return ownKeys(o);
|
|
};
|
|
return function (mod) {
|
|
if (mod && mod.__esModule) return mod;
|
|
var result = {};
|
|
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
__setModuleDefault(result, mod);
|
|
return result;
|
|
};
|
|
})();
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.launchMinecraft = launchMinecraft;
|
|
exports.diagnoseVersion = diagnoseVersion;
|
|
const child_process_1 = require("child_process");
|
|
const fs = __importStar(require("fs"));
|
|
const path = __importStar(require("path"));
|
|
const runningProcesses = new Map();
|
|
async function launchMinecraft(options) {
|
|
const versionJsonPath = path.join(options.gamePath, 'versions', options.version, `${options.version}.json`);
|
|
if (!fs.existsSync(versionJsonPath)) {
|
|
throw new Error(`Version JSON not found: ${versionJsonPath}`);
|
|
}
|
|
const versionJson = JSON.parse(fs.readFileSync(versionJsonPath, 'utf-8'));
|
|
const mainClass = versionJson.mainClass;
|
|
if (!mainClass) {
|
|
throw new Error('Main class not found in version JSON');
|
|
}
|
|
const args = [];
|
|
// Memory
|
|
const minMem = options.memory?.min || '512M';
|
|
const maxMem = options.memory?.max || '4G';
|
|
args.push(`-Xms${minMem}`);
|
|
args.push(`-Xmx${maxMem}`);
|
|
// JVM args
|
|
if (options.jvmArgs) {
|
|
args.push(...options.jvmArgs);
|
|
}
|
|
// Native libraries path
|
|
const nativesDir = path.join(options.gamePath, 'versions', options.version, `${options.version}-natives`);
|
|
if (fs.existsSync(nativesDir)) {
|
|
args.push(`-Djava.library.path=${nativesDir}`);
|
|
}
|
|
// Classpath
|
|
const libraries = versionJson.libraries || [];
|
|
const classpath = libraries
|
|
.filter((lib) => lib.downloads?.artifact?.path)
|
|
.map((lib) => path.join(options.gamePath, 'libraries', lib.downloads.artifact.path));
|
|
const clientJar = path.join(options.gamePath, 'versions', options.version, `${options.version}.jar`);
|
|
if (fs.existsSync(clientJar)) {
|
|
classpath.push(clientJar);
|
|
}
|
|
args.push('-cp');
|
|
args.push(classpath.join(path.delimiter));
|
|
args.push(mainClass);
|
|
// Game args
|
|
args.push(`--username`, options.username);
|
|
args.push(`--version`, options.version);
|
|
args.push(`--gameDir`, options.gamePath);
|
|
args.push(`--assetsDir`, path.join(options.gamePath, 'assets'));
|
|
args.push(`--assetIndex`, versionJson.assetIndex?.id || options.version);
|
|
args.push(`--uuid`, options.uuid);
|
|
if (options.accessToken) {
|
|
args.push(`--accessToken`, options.accessToken);
|
|
}
|
|
if (options.server) {
|
|
args.push(`--server`, options.server.ip);
|
|
if (options.server.port) {
|
|
args.push(`--port`, String(options.server.port));
|
|
}
|
|
}
|
|
if (options.gameArgs) {
|
|
args.push(...options.gameArgs);
|
|
}
|
|
const javaPath = options.javaPath || 'java';
|
|
return new Promise((resolve, reject) => {
|
|
const child = (0, child_process_1.spawn)(javaPath, args, {
|
|
cwd: options.gamePath,
|
|
detached: options.detached,
|
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
});
|
|
const requestId = `mc-${Date.now()}`;
|
|
runningProcesses.set(requestId, child);
|
|
child.stdout?.on('data', (data) => {
|
|
const line = data.toString().trim();
|
|
if (line) {
|
|
options.onEvent?.({ event: 'stdout', message: line });
|
|
}
|
|
});
|
|
child.stderr?.on('data', (data) => {
|
|
const line = data.toString().trim();
|
|
if (line) {
|
|
options.onEvent?.({ event: 'stderr', message: line });
|
|
}
|
|
});
|
|
child.on('error', (err) => {
|
|
runningProcesses.delete(requestId);
|
|
options.onEvent?.({ event: 'error', error: String(err) });
|
|
reject(err);
|
|
});
|
|
child.on('exit', (code) => {
|
|
runningProcesses.delete(requestId);
|
|
options.onEvent?.({ event: 'exit', code });
|
|
});
|
|
resolve({
|
|
pid: child.pid || 0,
|
|
version: options.version,
|
|
username: options.username,
|
|
});
|
|
});
|
|
}
|
|
async function diagnoseVersion(gamePath, version) {
|
|
const issues = [];
|
|
const versionDir = path.join(gamePath, 'versions', version);
|
|
const versionJsonPath = path.join(versionDir, `${version}.json`);
|
|
const jarPath = path.join(versionDir, `${version}.jar`);
|
|
if (!fs.existsSync(versionJsonPath)) {
|
|
issues.push(`Version JSON not found: ${versionJsonPath}`);
|
|
}
|
|
if (!fs.existsSync(jarPath)) {
|
|
issues.push(`Client JAR not found: ${jarPath}`);
|
|
}
|
|
return {
|
|
version,
|
|
gamePath,
|
|
healthy: issues.length === 0,
|
|
issues,
|
|
};
|
|
}
|