Skip to content

Commit

Permalink
Merge pull request #38 from baseballlover723/master
Browse files Browse the repository at this point in the history
Feature: Added WSL 1 support
  • Loading branch information
Pupix authored Nov 23, 2023
2 parents 7764b53 + 30586a4 commit 68b14f0
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@ const path = require('path');
const chokidar = require('chokidar');
const cp = require('child_process');
const LockfileParser = require('lol-lockfile-parser');
const os = require('os');

const lockfile = new LockfileParser();
const IS_WIN = process.platform === 'win32';
const IS_MAC = process.platform === 'darwin';
const IS_WSL = process.platform === 'linux' && os.release().toLowerCase().includes('microsoft');

class LCUConnector extends EventEmitter {

static getLCUPathFromProcess() {
return new Promise(resolve => {
const INSTALL_REGEX_WIN = /"--install-directory=(.*?)"/;
const INSTALL_REGEX_MAC = /--install-directory=(.*?)( --|\n|$)/;
const INSTALL_REGEX = IS_WIN ? INSTALL_REGEX_WIN : INSTALL_REGEX_MAC;
const INSTALL_REGEX = IS_WIN || IS_WSL ? INSTALL_REGEX_WIN : INSTALL_REGEX_MAC;
const command = IS_WIN ?
`WMIC PROCESS WHERE name='LeagueClientUx.exe' GET commandline` :
`ps x -o args | grep 'LeagueClientUx'`;
IS_WSL ?
`WMIC.exe PROCESS WHERE "name='LeagueClientUx.exe'" GET commandline` :
`ps x -o args | grep 'LeagueClientUx'`;

cp.exec(command, (err, stdout, stderr) => {
if (err || !stdout || stderr) {
Expand All @@ -27,7 +31,8 @@ class LCUConnector extends EventEmitter {
}

const parts = stdout.match(INSTALL_REGEX) || [];
resolve(parts[1]);
const dirPath = !IS_WSL ? parts[1] : parts[1].split(path.win32.sep).join(path.sep).replace(/^([a-zA-Z]):/, match => '/mnt/' + match[0].toLowerCase());
resolve(dirPath);
});
});
}
Expand Down

0 comments on commit 68b14f0

Please sign in to comment.