Skip to content

Commit

Permalink
Added eslint and @Morilli's fix for the new Riot Client
Browse files Browse the repository at this point in the history
  • Loading branch information
Pupix committed Sep 20, 2019
1 parent a87cb1f commit af3ca54
Show file tree
Hide file tree
Showing 7 changed files with 1,329 additions and 379 deletions.
22 changes: 22 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
root = true

# GENERIC SETTINGS
[*]
indent_style = space
indent_size = 4
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true

# WEB FILES
[*.{css,html,js}]
charset = utf-8

# MARKDOWN
[*.md]
trim_trailing_whitespace = false

# NODE PROJECTS
[{bower.json,package.json,.travis.yml}]
indent_style = space
indent_size = 2
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/node_modules/**
**/bower_components/**
__tests__
86 changes: 86 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"extends": [
"airbnb-base",
"eslint:recommended",
"plugin:node/recommended"
],

"env": {
"browser": true,
"node": true,
},

"plugins": [
// Node specific ESLint rules (requires eslint-plugin-node)
"node",

// Enable es6 imports (requires eslint-plugin-import)
"import",

// Enable linting in html files (requires eslint-plugin-html)
"html"
],

"parserOptions": {
"ecmaVersion": 9,
"sourceType": "module",
},

"settings": {
"import/core-modules": [
"electron"
]
},

"rules": {

"no-console": "off",

"indent": ["error", 4, {
"SwitchCase": 1,
"VariableDeclarator": 1,
"outerIIFEBody": 1,
// MemberExpression: null,
"FunctionDeclaration": {
"parameters": 1,
"body": 1
},
"FunctionExpression": {
"parameters": 1,
"body": 1
},
"CallExpression": {
"arguments": 1
},
"ArrayExpression": 1,
"ObjectExpression": 1,
"ImportDeclaration": 1,
"flatTernaryExpressions": false,
"ignoreComments": false
}],

"no-underscore-dangle": ["error", {
"allowAfterThis": true,
"allowAfterSuper": true
}],

"max-len": ["error", 120, 2, {
"ignoreUrls": true,
"ignoreComments": false,
"ignoreRegExpLiterals": true,
"ignoreStrings": true,
"ignoreTemplateLiterals": true
}],

"node/no-unpublished-require": ["error", {
"allowModules": ["electron"]
}],

"no-async-promise-executor": "off",

"linebreak-style": ["error", "windows"],

"operator-linebreak": ["error", "after"],
}

}
25 changes: 16 additions & 9 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ const DiscordRPC = require('discord-rpc');
const {
duplicateSystemYaml,
restartLCUWithOverride,
} = require('./util');
} = require('./util');

const connector = new LCUConnector();
const { app, dialog } = electron;
const { BrowserWindow } = electron;

const root = __dirname + '/app';
const root = `${__dirname}/app`;

// Checking if the running executable is called electron
// seems to be the most straightforward to do this
// https://stackoverflow.com/a/39395885/4895858
const isDev = process.execPath.search('electron') !== -1;

const clientId = '616399159322214425';
const rpc = new DiscordRPC.Client({ transport: 'ipc' });
Expand All @@ -33,17 +38,17 @@ app.on('ready', () => {
title: 'Rift Explorer',
backgroundColor: '#303030',
webPreferences: {
nodeIntegration: true
}
nodeIntegration: true,
},
});

if (process.env.NODE_ENV === 'development') {
if (isDev) {
mainWindow.openDevTools();
}

// Remove default menu
mainWindow.setMenu(null);
mainWindow.loadURL('file://' + root + '/index.html');
mainWindow.loadURL(`file://${root}/index.html`);

// Avoid white page on load.
mainWindow.webContents.on('did-finish-load', () => {
Expand Down Expand Up @@ -78,11 +83,11 @@ app.on('ready', () => {
await duplicateSystemYaml();
const response = dialog.showMessageBoxSync({
type: 'info',
buttons: [ 'Cancel', 'Ok' ],
buttons: ['Cancel', 'Ok'],
title: 'Rift Explorer',
message: 'Rift Explorer needs to restart your League of Legends client to work properly',
cancelId: 0,
noLink: true
noLink: true,
});

if (!response) {
Expand All @@ -91,6 +96,8 @@ app.on('ready', () => {
}

await restartLCUWithOverride(LCUData);
// https://github.com/eslint/eslint/issues/11899
// eslint-disable-next-line require-atomic-updates
LCURestarted = true;
} catch (error) {
console.error(error);
Expand Down Expand Up @@ -133,7 +140,7 @@ app.on('ready', () => {

connector.start();
rpc.login({ clientId }).catch(console.error);
});
});

app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@
},
"devDependencies": {
"electron": "^6.0.5",
"electron-builder": "^21.2.0"
"electron-builder": "^21.2.0",
"eslint": "^6.4.0",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-plugin-html": "^6.0.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-node": "^10.0.0"
},
"build": {
"productName": "Rift Explorer",
Expand Down
36 changes: 21 additions & 15 deletions util.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const IS_WIN = process.platform === 'win32';
const LEAGUE_PROCESS = IS_WIN ? 'LeagueClient.exe' : 'LeagueClient';

function getLCUExecutableFromProcess() {
return new Promise(resolve => {
return new Promise((resolve, reject) => {
const command = IS_WIN ?
`WMIC PROCESS WHERE name='${LEAGUE_PROCESS}' GET ExecutablePath` :
`ps x -o comm= | grep '${LEAGUE_PROCESS}$'`;
Expand All @@ -20,15 +20,15 @@ function getLCUExecutableFromProcess() {
return;
}

const normalizedPath = path.normalize(stdout);
const normalizedPath = path.normalize(stdout);
resolve(IS_WIN ? normalizedPath.split(/\n|\n\r/)[1] : normalizedPath);
});
});
};
}

async function duplicateSystemYaml() {
const LCUExePath = await getLCUExecutableFromProcess();
const LCUDir = IS_WIN ? path.dirname(LCUExePath) : path.dirname(LCUExePath) + '/../../..';
const LCUDir = IS_WIN ? path.dirname(LCUExePath) : `${path.dirname(LCUExePath)}/../../..`;

const originalSystemFile = path.join(LCUDir, 'system.yaml');
const overrideSystemFile = path.join(LCUDir, 'Config', 'rift-explorer', 'system.yaml');
Expand All @@ -39,35 +39,41 @@ async function duplicateSystemYaml() {
}

const file = await fs.readFile(originalSystemFile, 'utf8');
const fileParsed = yaml.parse(file);

fileParsed.enable_swagger = true;
const fileParsed = yaml.parseDocument(file);

fileParsed.delete('riotclient');
fileParsed.set('enable_swagger', true);

const stringifiedFile = yaml.stringify(fileParsed);
// Rito's file is prefixed with --- newline
await fs.outputFile(overrideSystemFile, `---\n${stringifiedFile}`);
}

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

const { username, password, address, port } = LCUData;


const {
username,
password,
address,
port,
} = LCUData;

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

// Give it some time to do cleanup
setTimeout(() => {
const leagueProcess = spawn(LCUExePath.trim(), [`--system-yaml-override=${overrideSystemFile}`], {
cwd: LCUDir,
detached: true,
stdio: 'ignore'
stdio: 'ignore',
});

leagueProcess.unref();
Expand Down
Loading

8 comments on commit af3ca54

@TLHaruXXX
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey dude, i have problems with rift explorer with league say always rift need to retart, say the same i test 10x :(
maybe problem with new patch?

@Morilli
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TLHaruXXX
Copy link

@TLHaruXXX TLHaruXXX commented on af3ca54 Dec 13, 2019 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Hi-Ray
Copy link
Collaborator

@Hi-Ray Hi-Ray commented on af3ca54 Dec 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a known issue and i'm working on a fix but its not as simple sadly.

@Morilli
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TLHaruXXX did you login in the riot client?

@TLHaruXXX
Copy link

@TLHaruXXX TLHaruXXX commented on af3ca54 Dec 13, 2019 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Hi-Ray
Copy link
Collaborator

@Hi-Ray Hi-Ray commented on af3ca54 Dec 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take in mind Morilli is trying to help please don't be rude when we're trying to help or explain why rift explorer is currently broken

@TLHaruXXX
Copy link

@TLHaruXXX TLHaruXXX commented on af3ca54 Dec 14, 2019 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.