mirror of
https://github.com/artegoser/pimi-launcher-core.git
synced 2025-02-23 20:51:30 +03:00
small but major changes again. Pretty much done now
Removed: close restart. setting options in constructor. Added: getPid and new gif Reformatted: options now go back into the launch function. `authorization` still accepts either an json object or a promise. Better docs v2
This commit is contained in:
parent
845fac3767
commit
62d02dccba
4 changed files with 33 additions and 44 deletions
|
@ -301,7 +301,7 @@ class Handler {
|
|||
}
|
||||
|
||||
getLaunchOptions(modification) {
|
||||
return new Promise(resolve => {
|
||||
return new Promise(async resolve => {
|
||||
let type = modification || this.version;
|
||||
|
||||
let args = type.minecraftArguments ? type.minecraftArguments.split(' ') : type.arguments.game;
|
||||
|
@ -309,6 +309,10 @@ class Handler {
|
|||
|
||||
if(args.length < 5) args = args.concat(this.version.minecraftArguments ? this.version.minecraftArguments.split(' ') : this.version.arguments.game);
|
||||
|
||||
if({}.toString.call(this.options.authorization) === "[object Promise]") {
|
||||
this.options.authorization = await this.options.authorization;
|
||||
}
|
||||
|
||||
const fields = {
|
||||
'${auth_access_token}': this.options.authorization.access_token,
|
||||
'${auth_session}': this.options.authorization.access_token,
|
||||
|
@ -364,4 +368,4 @@ class Handler {
|
|||
}
|
||||
}
|
||||
|
||||
module.exports = Handler;
|
||||
module.exports = Handler;
|
||||
|
|
|
@ -6,24 +6,17 @@ const fs = require('fs');
|
|||
const EventEmitter = require('events').EventEmitter;
|
||||
|
||||
class MCLCore extends EventEmitter {
|
||||
constructor(options) {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.options = options;
|
||||
this.handler = new handler(this);
|
||||
this.pid = null;
|
||||
}
|
||||
|
||||
async launch(authorization) {
|
||||
if(!authorization) throw Error('No authorization to launch the client with!');
|
||||
|
||||
if({}.toString.call(authorization) === "[object Promise]") {
|
||||
this.options.authorization = await authorization;
|
||||
} else {
|
||||
this.options.authorization = authorization
|
||||
}
|
||||
|
||||
async launch(options) {
|
||||
this.options = options;
|
||||
this.options.root = path.resolve(this.options.root);
|
||||
this.handler = new handler(this);
|
||||
|
||||
if(!fs.existsSync(this.options.root)) {
|
||||
this.emit('debug', '[MCLC]: Attempting to create root folder');
|
||||
fs.mkdirSync(this.options.root);
|
||||
|
@ -109,14 +102,9 @@ class MCLCore extends EventEmitter {
|
|||
this.pid = minecraft.pid;
|
||||
}
|
||||
|
||||
async close() {
|
||||
child.exec(`taskkill /PID ${this.pid}`, (err, out, error) => {return {err, out, error}})
|
||||
}
|
||||
|
||||
async restart() {
|
||||
await this.close();
|
||||
await this.launch()
|
||||
getPid() {
|
||||
return this.pid;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MCLCore;
|
||||
module.exports = MCLCore;
|
||||
|
|
Loading…
Add table
Reference in a new issue