-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added reconnect and swagger auto-patching
- Loading branch information
Showing
13 changed files
with
267 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,137 @@ | ||
|
||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Rift Explorer</title> | ||
<link rel="icon" type="image/png" href="images/favicon-32x32.png" sizes="32x32" /> | ||
<link rel="icon" type="image/png" href="images/favicon-16x16.png" sizes="16x16" /> | ||
<link href='css/typography.css' media='screen' rel='stylesheet' type='text/css'/> | ||
<link href='css/reset.css' media='screen' rel='stylesheet' type='text/css'/> | ||
<link href='css/screen.css' media='screen' rel='stylesheet' type='text/css'/> | ||
<link href='css/reset.css' media='print' rel='stylesheet' type='text/css'/> | ||
<link href='css/print.css' media='print' rel='stylesheet' type='text/css'/> | ||
<link href='css/style.css' rel='stylesheet' type='text/css'/> | ||
<script src='lib/jquery-1.8.0.min.js' type='text/javascript'></script> | ||
<script src='lib/jquery.slideto.min.js' type='text/javascript'></script> | ||
<script src='lib/jquery.wiggle.min.js' type='text/javascript'></script> | ||
<script src='lib/jquery.ba-bbq.min.js' type='text/javascript'></script> | ||
<script src='lib/handlebars-2.0.0.js' type='text/javascript'></script> | ||
<script src='lib/underscore-min.js' type='text/javascript'></script> | ||
<script src='lib/backbone-min.js' type='text/javascript'></script> | ||
<script src='swagger-ui.js' type='text/javascript'></script> | ||
<script src='lib/highlight.7.3.pack.js' type='text/javascript'></script> | ||
<script src='lib/jsoneditor.min.js' type='text/javascript'></script> | ||
<script src='lib/marked.js' type='text/javascript'></script> | ||
<script src='lib/swagger-oauth.js' type='text/javascript'></script> | ||
|
||
|
||
<script type="text/javascript"> | ||
|
||
const IPC = require('electron').ipcRenderer; | ||
const shell = require('electron').shell; | ||
const REMOTE = require('electron').remote; | ||
|
||
IPC.on('lcu-load', (event, data) => { | ||
|
||
const { username, password, address, port } = data; | ||
const header = `Basic ${btoa(`${username}:${password}`)}`; | ||
const auth = new SwaggerClient.ApiKeyAuthorization("Authorization", header, "header"); | ||
|
||
window.swaggerUi = new SwaggerUi({ | ||
validatorUrl: null, | ||
url: `https://${username}:${password}@${address}:${port}/swagger/v2/swagger.json`, | ||
authorizations: { riot: auth }, | ||
dom_id: "swagger-ui-container", | ||
onComplete(swaggerApi, swaggerUi) { | ||
$('pre code').each(function(i, e) { | ||
hljs.highlightBlock(e) | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Rift Explorer</title> | ||
<link rel="icon" type="image/png" href="images/favicon-32x32.png" sizes="32x32" /> | ||
<link rel="icon" type="image/png" href="images/favicon-16x16.png" sizes="16x16" /> | ||
<link href='css/typography.css' media='screen' rel='stylesheet' type='text/css'/> | ||
<link href='css/reset.css' media='screen' rel='stylesheet' type='text/css'/> | ||
<link href='css/screen.css' media='screen' rel='stylesheet' type='text/css'/> | ||
<link href='css/reset.css' media='print' rel='stylesheet' type='text/css'/> | ||
<link href='css/print.css' media='print' rel='stylesheet' type='text/css'/> | ||
<link href='css/style.css' rel='stylesheet' type='text/css'/> | ||
<script src='lib/jquery-1.8.0.min.js' type='text/javascript'></script> | ||
<script src='lib/jquery.slideto.min.js' type='text/javascript'></script> | ||
<script src='lib/jquery.wiggle.min.js' type='text/javascript'></script> | ||
<script src='lib/jquery.ba-bbq.min.js' type='text/javascript'></script> | ||
<script src='lib/handlebars-2.0.0.js' type='text/javascript'></script> | ||
<script src='lib/underscore-min.js' type='text/javascript'></script> | ||
<script src='lib/backbone-min.js' type='text/javascript'></script> | ||
<script src='swagger-ui.js' type='text/javascript'></script> | ||
<script src='lib/highlight.7.3.pack.js' type='text/javascript'></script> | ||
<script src='lib/jsoneditor.min.js' type='text/javascript'></script> | ||
<script src='lib/marked.js' type='text/javascript'></script> | ||
<script src='lib/swagger-oauth.js' type='text/javascript'></script> | ||
|
||
</head> | ||
|
||
<body class="swagger-section"> | ||
<div id="message-bar" class="swagger-ui-wrap" data-sw-translate>Waiting for League to start...</div> | ||
<div id="swagger-ui-container" class="swagger-ui-wrap"></div> | ||
|
||
<script type="text/javascript"> | ||
const IPC = require('electron').ipcRenderer; | ||
const shell = require('electron').shell; | ||
const pkg = require('../package'); | ||
|
||
const swaggerContainer = document.querySelector('#swagger-ui-container'); | ||
const messageBar = document.querySelector('#message-bar'); | ||
|
||
let LCUData = null; | ||
let swaggerDisabled = true; | ||
let loadingSwagger = false; | ||
|
||
// We all love global variables | ||
window.RE = { | ||
info: { | ||
title: 'Rift Explorer', | ||
description: pkg.description, | ||
version: pkg.version, | ||
} | ||
}; | ||
|
||
const loadSwagger = () => { | ||
const { username, password, address, port } = LCUData; | ||
const header = `Basic ${btoa(`${username}:${password}`)}`; | ||
const auth = new SwaggerClient.ApiKeyAuthorization("Authorization", header, "header"); | ||
|
||
loadingSwagger = true; | ||
|
||
window.swaggerUi = new SwaggerUi({ | ||
validatorUrl: null, | ||
url: `https://${username}:${password}@${address}:${port}/swagger/v2/swagger.json`, | ||
authorizations: { riot: auth }, | ||
dom_id: "swagger-ui-container", | ||
onComplete() { | ||
loadingSwagger = false; | ||
|
||
$('pre code').each((i, e) => { | ||
hljs.highlightBlock(e); | ||
}); | ||
|
||
window.swaggerUi.api.clientAuthorizations.add("riot", auth); | ||
}, | ||
// Failure has been taken care of in the swagger-ui file | ||
docExpansion: "none", | ||
jsonEditor: false, | ||
apisSorter: "alpha", | ||
defaultModelRendering: 'schema', | ||
showRequestHeaders: true | ||
}); | ||
|
||
window.swaggerUi.api.clientAuthorizations.add("riot", auth); | ||
}, | ||
onFailure(error) { | ||
// alert('Couldn\'t load the swagger file. Make sure swagger is enabled. More info at https://github.com/Pupix/rift-explorer'); | ||
}, | ||
docExpansion: "none", | ||
jsonEditor: false, | ||
apisSorter: "alpha", | ||
defaultModelRendering: 'schema', | ||
showRequestHeaders: true | ||
window.swaggerUi.load(); | ||
}; | ||
|
||
IPC.on('lcu-load', (event, data) => { | ||
LCUData = data; | ||
|
||
if (!swaggerDisabled && !loadingSwagger) { | ||
loadSwagger(); | ||
} | ||
}); | ||
|
||
IPC.on('lcu-unload', () => { | ||
LCUData = null; | ||
swaggerContainer.innerHTML = ''; | ||
messageBar.innerHTML = 'Waiting for League to start...'; | ||
}); | ||
|
||
window.swaggerUi.load(); | ||
}); | ||
IPC.on('swagger-disabled', () => { | ||
swaggerDisabled = true; | ||
messageBar.innerHTML = 'API has been auto-enabled. Please restart the League Client'; | ||
|
||
function _handleGithubLink(event) { | ||
shell.openExternal('https://github.com/pupix/rift-explorer'); | ||
} | ||
// Allow the DOM to render the new HTML | ||
setTimeout(() => { | ||
const allowedRestart = confirm('Rift Explorer needs to restart the League Client to enable the API documentation'); | ||
|
||
function _handleDiscordLink(event) { | ||
shell.openExternal('https://discord.gg/hPtrMcx'); | ||
} | ||
if (allowedRestart) { | ||
const { username, password, address, port } = LCUData; | ||
|
||
fetch(`https://${address}:${port}/process-control/v1/process/restart?delaySeconds=0`, { | ||
method: 'POST', | ||
headers: new Headers({ Authorization: `Basic ${btoa(`${username}:${password}`)}` }) | ||
}); | ||
} | ||
}, 100); | ||
}); | ||
|
||
IPC.on('swagger-enabled', () => { | ||
swaggerDisabled = false; | ||
messageBar.innerHTML = 'Waiting for League to start...'; | ||
|
||
if (LCUData && !loadingSwagger) { | ||
loadSwagger(); | ||
} | ||
}); | ||
|
||
</script> | ||
</head> | ||
function _handleGithubLink(event) { | ||
shell.openExternal('https://github.com/pupix/rift-explorer'); | ||
} | ||
|
||
<body class="swagger-section"> | ||
<div id="message-bar" class="swagger-ui-wrap" data-sw-translate>Waiting for League to start...</div> | ||
<div id="swagger-ui-container" class="swagger-ui-wrap"></div> | ||
</body> | ||
function _handleDiscordLink(event) { | ||
shell.openExternal('https://discord.gg/hPtrMcx'); | ||
} | ||
</script> | ||
</body> | ||
</html> |
Oops, something went wrong.