Small changes, non breaking this time

Removed getPid in favor of returning the child process instead. Added OS detection as well!
This commit is contained in:
Pierce 2019-06-08 14:21:15 -04:00
parent 62d02dccba
commit e5e1d68883
4 changed files with 24 additions and 22 deletions

View file

@ -45,8 +45,7 @@ launcher.on('error', (e) => console.log(e));
| Function | Type | Description | | Function | Type | Description |
|----------|---------|-----------------------------------------------------------------------------------------| |----------|---------|-----------------------------------------------------------------------------------------|
| `launch` | Promise | Launches the client with the specified `options` as a parameter | | `launch` | Promise | Launches the client with the specified `options` as a parameter. Returns child the process |
| `getPid` | Integer | Returns the Minecraft client's PID |
##### launch ##### launch
@ -54,7 +53,7 @@ launcher.on('error', (e) => console.log(e));
|--------------------------|----------|-------------------------------------------------------------------------------------------|----------| |--------------------------|----------|-------------------------------------------------------------------------------------------|----------|
| `options.clientPackage` | String | Path to the client package zip file. | False | | `options.clientPackage` | String | Path to the client package zip file. | False |
| `options.root` | String | Path where you want the launcher to work in. like `C:/Users/user/AppData/Roaming/.mc`, | True | | `options.root` | String | Path where you want the launcher to work in. like `C:/Users/user/AppData/Roaming/.mc`, | True |
| `options.os` | String | windows, osx or linux, | True | | `options.os` | String | windows, osx or linux. MCLC with auto determine the OS if this field isn't provided. | False |
| `options.version.number` | String | Minecraft version that is going to be launched. | True | | `options.version.number` | String | Minecraft version that is going to be launched. | True |
| `options.version.type` | String | Any string. The actual Minecraft launcher uses `release` and `snapshot`. | True | | `options.version.type` | String | Any string. The actual Minecraft launcher uses `release` and `snapshot`. | True |
| `options.memory.max` | String | Max amount of memory being used by Minectaft. | True | | `options.memory.max` | String | Max amount of memory being used by Minectaft. | True |

View file

@ -171,7 +171,7 @@ class Handler {
await Promise.all(this.version.libraries.map(async (lib) => { await Promise.all(this.version.libraries.map(async (lib) => {
if (!lib.downloads.classifiers) return; if (!lib.downloads.classifiers) return;
const type = `natives-${this.options.os}`; const type = `natives-${this.getOS()}`;
const native = lib.downloads.classifiers[type]; const native = lib.downloads.classifiers[type];
if (native) { if (native) {
@ -354,15 +354,24 @@ class Handler {
} }
async getJVM() { async getJVM() {
switch(this.options.os) { const opts = {
case "windows": { "windows": "-XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump",
return "-XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump" "osx": "-XstartOnFirstThread",
} "linux": "-Xss1M"
case "osx": { };
return "-XstartOnFirstThread" return opts[this.getOS()]
} }
case "linux": {
return "-Xss1M" getOS() {
if(this.options.os) {
return this.options.os;
} else {
switch(process.platform) {
case "win32": return "windows";
case "darwin": return "osx";
case "freebsd": return "linux";
case "sunos": return "linux";
default: throw Error("[MCLC Error] Couldn't set OS specific JVM argument!")
} }
} }
} }

View file

@ -8,8 +8,6 @@ const EventEmitter = require('events').EventEmitter;
class MCLCore extends EventEmitter { class MCLCore extends EventEmitter {
constructor() { constructor() {
super(); super();
this.pid = null;
} }
async launch(options) { async launch(options) {
@ -69,7 +67,7 @@ class MCLCore extends EventEmitter {
const classes = await this.handler.getClasses(); const classes = await this.handler.getClasses();
let classPaths = ['-cp']; let classPaths = ['-cp'];
const separator = this.options.os === "windows" ? ";" : ":"; const separator = this.handler.getOS() === "windows" ? ";" : ":";
this.emit('debug', `[MCLC]: Using ${separator} to separate class paths`); this.emit('debug', `[MCLC]: Using ${separator} to separate class paths`);
if(forge) { if(forge) {
this.emit('debug', '[MCLC]: Setting Forge class paths'); this.emit('debug', '[MCLC]: Setting Forge class paths');
@ -99,11 +97,7 @@ class MCLCore extends EventEmitter {
minecraft.stderr.on('data', (data) => this.emit('error', data)); minecraft.stderr.on('data', (data) => this.emit('error', data));
minecraft.on('close', (code) => this.emit('close', code)); minecraft.on('close', (code) => this.emit('close', code));
this.pid = minecraft.pid; return minecraft;
}
getPid() {
return this.pid;
} }
} }

View file

@ -1,6 +1,6 @@
{ {
"name": "minecraft-launcher-core", "name": "minecraft-launcher-core",
"version": "3.4.0", "version": "3.5.0",
"description": "Lightweight module that downloads and runs Minecraft using javascript / NodeJS", "description": "Lightweight module that downloads and runs Minecraft using javascript / NodeJS",
"main": "index.js", "main": "index.js",
"dependencies": { "dependencies": {