Skip to content

Commit

Permalink
Fixed port mismach after the client restarts
Browse files Browse the repository at this point in the history
  • Loading branch information
Pupix committed May 19, 2019
1 parent 3d59dbf commit 2dd6395
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 335 deletions.
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ app.on('ready', () => {
return;
}

await restartLCUWithOverride();
await restartLCUWithOverride(LCUData);
LCURestarted = true;
} catch (error) {
console.error(error);
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rift-explorer",
"version": "6.0.0",
"version": "6.0.1",
"description": "Always up to date documentation for the League Client API",
"main": "app.js",
"scripts": {
Expand All @@ -10,8 +10,6 @@
"author": "Robert Manolea <manolea.robert@gmail.com>",
"license": "MIT",
"dependencies": {
"execa": "^1.0.0",
"fkill": "^6.1.0",
"fs-extra": "^7.0.1",
"lcu-connector": "^2.0.0",
"mixin-deep": "^2.0.0",
Expand Down
27 changes: 15 additions & 12 deletions util.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const cp = require('child_process');
const path = require('path');
const fs = require('fs-extra');
const yaml = require('yaml');
const fkill = require('fkill');
const execa = require('execa');
const { execFile } = require('child_process');
const requestPromise = require('request-promise');

const IS_WIN = process.platform === 'win32';
const LEAGUE_PROCESS = IS_WIN ? 'LeagueClient.exe' : 'LeagueClient';
Expand All @@ -26,7 +26,6 @@ function getLCUExecutableFromProcess() {
});
};


async function duplicateSystemYaml() {
const LCUExePath = await getLCUExecutableFromProcess();
const LCUDir = path.dirname(LCUExePath);
Expand All @@ -49,21 +48,25 @@ async function duplicateSystemYaml() {
await fs.outputFile(overrideSystemFile, `---\n${stringifiedFile}`);
}

function restartLCUWithOverride() {
function restartLCUWithOverride(LCUData) {
return new Promise(async (resolve, reject) => {
const LCUExePath = await getLCUExecutableFromProcess();
const LCUDir = path.dirname(LCUExePath);
const overrideSystemFile = path.join(LCUDir, 'Config', 'rift-explorer', 'system.yaml');

// Windows is unable to kill the child processes for some reason so we have to force kill it
await fkill(LEAGUE_PROCESS, { force: true });

// By force killing it the LeagueClient doesn't cleanup the lockfile so we gotta do it manually
await fs.remove(path.join(LCUDir, 'lockfile'));
const { username, password, address, port } = LCUData;

await requestPromise({
strictSSL: false,
method: 'POST',
maxBuffer: 1024 * 1024 * 1024,
uri: `https://${username}:${password}@${address}:${port}/process-control/v1/process/quit`,
});

// Give it some time to do cleanup
execa(LCUExePath, [`--system-yaml-override=${overrideSystemFile}`], { detached: true });
resolve();
setTimeout(() => {
execFile(LCUExePath.trim(), [`--system-yaml-override=${overrideSystemFile}`]);
resolve();
}, 5000);
});
}

Expand Down
Loading

0 comments on commit 2dd6395

Please sign in to comment.