mirror of
https://github.com/dscalzi/HeliosLauncher.git
synced 2024-12-22 11:42:14 -08:00
Added eslint. To lint, npm run lint.
Linted the entire project. Using different rules for the script files as there are a lot of undefined variables just because of the way the DOM's global scope works. Mostly just code cleanup, however the linter did catch a minor bug with a settings regex. That has been corrected.
This commit is contained in:
parent
ededf85892
commit
810e81521c
50
.eslintrc.json
Normal file
50
.eslintrc.json
Normal file
@ -0,0 +1,50 @@
|
||||
{
|
||||
"env": {
|
||||
"es6": true,
|
||||
"node": true
|
||||
},
|
||||
"extends": "eslint:recommended",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2017,
|
||||
"sourceType": "module"
|
||||
},
|
||||
"rules": {
|
||||
"indent": [
|
||||
"error",
|
||||
4,
|
||||
{
|
||||
"SwitchCase": 1
|
||||
}
|
||||
],
|
||||
"linebreak-style": [
|
||||
"error",
|
||||
"windows"
|
||||
],
|
||||
"quotes": [
|
||||
"error",
|
||||
"single"
|
||||
],
|
||||
"semi": [
|
||||
"error",
|
||||
"never"
|
||||
],
|
||||
"no-var": [
|
||||
"error"
|
||||
],
|
||||
"no-console": [
|
||||
0
|
||||
],
|
||||
"no-control-regex": [
|
||||
0
|
||||
],
|
||||
"no-unused-vars": [
|
||||
"error",
|
||||
{
|
||||
"vars": "all",
|
||||
"args": "none",
|
||||
"ignoreRestSiblings": false,
|
||||
"argsIgnorePattern": "reject"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
47
.eslintrc.scripts.json
Normal file
47
.eslintrc.scripts.json
Normal file
@ -0,0 +1,47 @@
|
||||
{
|
||||
"env": {
|
||||
"es6": true,
|
||||
"node": true
|
||||
},
|
||||
"extends": "eslint:recommended",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2017,
|
||||
"sourceType": "module"
|
||||
},
|
||||
"rules": {
|
||||
"indent": [
|
||||
"error",
|
||||
4,
|
||||
{
|
||||
"SwitchCase": 1
|
||||
}
|
||||
],
|
||||
"linebreak-style": [
|
||||
"error",
|
||||
"windows"
|
||||
],
|
||||
"quotes": [
|
||||
"error",
|
||||
"single"
|
||||
],
|
||||
"semi": [
|
||||
"error",
|
||||
"never"
|
||||
],
|
||||
"no-var": [
|
||||
"error"
|
||||
],
|
||||
"no-console": [
|
||||
0
|
||||
],
|
||||
"no-control-regex": [
|
||||
0
|
||||
],
|
||||
"no-unused-vars": [
|
||||
0
|
||||
],
|
||||
"no-undef": [
|
||||
0
|
||||
]
|
||||
}
|
||||
}
|
@ -22,7 +22,7 @@ const crypto = require('crypto')
|
||||
const EventEmitter = require('events')
|
||||
const fs = require('fs')
|
||||
const isDev = require('electron-is-dev')
|
||||
const mkpath = require('mkdirp');
|
||||
const mkpath = require('mkdirp')
|
||||
const path = require('path')
|
||||
const Registry = require('winreg')
|
||||
const request = require('request')
|
||||
@ -70,13 +70,13 @@ class Library extends Asset {
|
||||
static mojangFriendlyOS(){
|
||||
const opSys = process.platform
|
||||
if (opSys === 'darwin') {
|
||||
return 'osx';
|
||||
return 'osx'
|
||||
} else if (opSys === 'win32'){
|
||||
return 'windows';
|
||||
return 'windows'
|
||||
} else if (opSys === 'linux'){
|
||||
return 'linux';
|
||||
return 'linux'
|
||||
} else {
|
||||
return 'unknown_os';
|
||||
return 'unknown_os'
|
||||
}
|
||||
}
|
||||
|
||||
@ -241,12 +241,11 @@ class AssetGuard extends EventEmitter {
|
||||
if(hash == null){
|
||||
return true
|
||||
}
|
||||
let fileName = path.basename(filePath)
|
||||
let buf = fs.readFileSync(filePath)
|
||||
let calcdhash = AssetGuard._calculateHash(buf, algo)
|
||||
return calcdhash === hash
|
||||
}
|
||||
return false;
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
@ -926,7 +925,7 @@ class AssetGuard extends EventEmitter {
|
||||
}
|
||||
|
||||
// Check the JAVA_HOME environment variable.
|
||||
const jHome = AssetGuard._scanJavaHome()
|
||||
let jHome = AssetGuard._scanJavaHome()
|
||||
if(jHome != null){
|
||||
// Ensure we are at the absolute root.
|
||||
if(jHome.contains('/Contents/Home')){
|
||||
@ -1099,7 +1098,6 @@ class AssetGuard extends EventEmitter {
|
||||
//Asset constants
|
||||
const resourceURL = 'http://resources.download.minecraft.net/'
|
||||
const localPath = path.join(self.commonPath, 'assets')
|
||||
const indexPath = path.join(localPath, 'indexes')
|
||||
const objectPath = path.join(localPath, 'objects')
|
||||
|
||||
const assetDlQueue = []
|
||||
@ -1112,7 +1110,7 @@ class AssetGuard extends EventEmitter {
|
||||
self.emit('progress', 'assets', acc, total)
|
||||
const hash = value.hash
|
||||
const assetName = path.join(hash.substring(0, 2), hash)
|
||||
const urlName = hash.substring(0, 2) + "/" + hash
|
||||
const urlName = hash.substring(0, 2) + '/' + hash
|
||||
const ast = new Asset(key, hash, value.size, resourceURL + urlName, path.join(objectPath, assetName))
|
||||
if(!AssetGuard._validateLocal(ast.to, 'sha1', ast.hash)){
|
||||
dlSize += (ast.size*1)
|
||||
@ -1271,7 +1269,7 @@ class AssetGuard extends EventEmitter {
|
||||
|
||||
_parseDistroModules(modules, version, servid){
|
||||
let alist = []
|
||||
let asize = 0;
|
||||
let asize = 0
|
||||
let decompressqueue = []
|
||||
for(let ob of modules){
|
||||
let obType = ob.getType
|
||||
@ -1525,7 +1523,7 @@ class AssetGuard extends EventEmitter {
|
||||
}, (err) => {
|
||||
|
||||
if(err){
|
||||
console.log('An item in ' + identifier + ' failed to process');
|
||||
console.log('An item in ' + identifier + ' failed to process')
|
||||
} else {
|
||||
console.log('All ' + identifier + ' have been processed successfully')
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ const DEFAULT_CONFIG = {
|
||||
modConfigurations: []
|
||||
}
|
||||
|
||||
let config = null;
|
||||
let config = null
|
||||
|
||||
// Persistance Utility Functions
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
// Work in progress
|
||||
const {Client} = require('discord-rpc')
|
||||
const ConfigManager = require('./configmanager')
|
||||
|
||||
let client
|
||||
let activity
|
||||
|
@ -483,7 +483,7 @@ class DistroIndex {
|
||||
* @returns {Server} The main server.
|
||||
*/
|
||||
getMainServer(){
|
||||
return getServer(this.mainServer)
|
||||
return this.mainServer != null ? this.getServer(this.mainServer) : null
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -241,7 +241,7 @@ class ProcessBuilder {
|
||||
for(let i=0; i<mcArgs.length; ++i){
|
||||
if(argDiscovery.test(mcArgs[i])){
|
||||
const identifier = mcArgs[i].match(argDiscovery)[1]
|
||||
let val = null;
|
||||
let val = null
|
||||
switch(identifier){
|
||||
case 'auth_player_name':
|
||||
val = this.authUser.displayName
|
||||
@ -273,7 +273,7 @@ class ProcessBuilder {
|
||||
break
|
||||
}
|
||||
if(val != null){
|
||||
mcArgs[i] = val;
|
||||
mcArgs[i] = val
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -152,8 +152,8 @@ const refreshMojangStatuses = async function(){
|
||||
console.log('Refreshing Mojang Statuses..')
|
||||
|
||||
let status = 'grey'
|
||||
let tooltipEssentialHTML = ``
|
||||
let tooltipNonEssentialHTML = ``
|
||||
let tooltipEssentialHTML = ''
|
||||
let tooltipNonEssentialHTML = ''
|
||||
|
||||
try {
|
||||
const statuses = await Mojang.status()
|
||||
@ -366,7 +366,7 @@ function asyncSystemScan(launchAfter = true){
|
||||
} else if(m.context === 'complete'){
|
||||
|
||||
switch(m.data){
|
||||
case 'download':
|
||||
case 'download': {
|
||||
// Show installing progress bar.
|
||||
remote.getCurrentWindow().setProgressBar(2)
|
||||
|
||||
@ -383,6 +383,7 @@ function asyncSystemScan(launchAfter = true){
|
||||
setLaunchDetails(eLStr + dotStr)
|
||||
}, 750)
|
||||
break
|
||||
}
|
||||
case 'java':
|
||||
// Download & extraction complete, remove the loading from the OS progress bar.
|
||||
remote.getCurrentWindow().setProgressBar(-1)
|
||||
@ -497,14 +498,15 @@ function dlAsync(login = true){
|
||||
}
|
||||
} else if(m.context === 'progress'){
|
||||
switch(m.data){
|
||||
case 'assets':
|
||||
case 'assets': {
|
||||
const perc = (m.value/m.total)*20
|
||||
setLaunchPercentage(40+perc, 100, parseInt(40+perc))
|
||||
break
|
||||
}
|
||||
case 'download':
|
||||
setDownloadPercentage(m.value, m.total, m.percent)
|
||||
break
|
||||
case 'extract':
|
||||
case 'extract': {
|
||||
// Show installing progress bar.
|
||||
remote.getCurrentWindow().setProgressBar(2)
|
||||
|
||||
@ -522,6 +524,7 @@ function dlAsync(login = true){
|
||||
}, 750)
|
||||
break
|
||||
}
|
||||
}
|
||||
} else if(m.context === 'complete'){
|
||||
switch(m.data){
|
||||
case 'download':
|
||||
@ -1022,7 +1025,7 @@ function loadNews(){
|
||||
let content = el.find('content\\:encoded').text()
|
||||
let regex = /src="(?!http:\/\/|https:\/\/)(.+)"/g
|
||||
let matches
|
||||
while(matches = regex.exec(content)){
|
||||
while((matches = regex.exec(content))){
|
||||
content = content.replace(matches[1], newsHost + matches[1])
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ function toggleOverlay(toggleState, dismissable = false, content = 'overlayConte
|
||||
if(toggleState){
|
||||
document.getElementById('main').setAttribute('overlay', true)
|
||||
// Make things untabbable.
|
||||
$("#main *").attr('tabindex', '-1')
|
||||
$('#main *').attr('tabindex', '-1')
|
||||
$('#' + content).parent().children().hide()
|
||||
$('#' + content).show()
|
||||
if(dismissable){
|
||||
@ -41,7 +41,7 @@ function toggleOverlay(toggleState, dismissable = false, content = 'overlayConte
|
||||
} else {
|
||||
document.getElementById('main').removeAttribute('overlay')
|
||||
// Make things tabbable.
|
||||
$("#main *").removeAttr('tabindex')
|
||||
$('#main *').removeAttr('tabindex')
|
||||
$('#overlayContainer').fadeOut({
|
||||
duration: 250,
|
||||
start: () => {
|
||||
@ -232,9 +232,9 @@ function populateServerListings(){
|
||||
const distro = DistroManager.getDistribution()
|
||||
const giaSel = ConfigManager.getSelectedServer()
|
||||
const servers = distro.getServers()
|
||||
let htmlString = ``
|
||||
let htmlString = ''
|
||||
for(const serv of servers){
|
||||
htmlString += `<button class="serverListing" servid="${serv.getID()}" ${serv.getID() === giaSel ? `selected` : ``}>
|
||||
htmlString += `<button class="serverListing" servid="${serv.getID()}" ${serv.getID() === giaSel ? 'selected' : ''}>
|
||||
<img class="serverListingImg" src="${serv.getIcon()}"/>
|
||||
<div class="serverListingDetails">
|
||||
<span class="serverListingName">${serv.getName()}</span>
|
||||
@ -251,7 +251,7 @@ function populateServerListings(){
|
||||
<circle class="cls-2" cx="53.73" cy="53.9" r="38"/>
|
||||
</svg>
|
||||
<span class="serverListingStarTooltip">Main Server</span>
|
||||
</div>` : ``}
|
||||
</div>` : ''}
|
||||
</div>
|
||||
</div>
|
||||
</button>`
|
||||
@ -262,8 +262,8 @@ function populateServerListings(){
|
||||
|
||||
function populateAccountListings(){
|
||||
const accountsObj = ConfigManager.getAuthAccounts()
|
||||
const accounts = Array.from(Object.keys(accountsObj), v=>accountsObj[v]);
|
||||
let htmlString = ``
|
||||
const accounts = Array.from(Object.keys(accountsObj), v=>accountsObj[v])
|
||||
let htmlString = ''
|
||||
for(let i=0; i<accounts.length; i++){
|
||||
htmlString += `<button class="accountListing" uuid="${accounts[i].uuid}" ${i===0 ? 'selected' : ''}>
|
||||
<img src="https://crafatar.com/renders/head/${accounts[i].uuid}?scale=2&default=MHF_Steve&overlay">
|
||||
|
@ -12,7 +12,7 @@ const settingsState = {
|
||||
* General Settings Functions
|
||||
*/
|
||||
|
||||
/**
|
||||
/**
|
||||
* Bind value validators to the settings UI elements. These will
|
||||
* validate against the criteria defined in the ConfigManager (if
|
||||
* and). If the value is invalid, the UI will reflect this and saving
|
||||
@ -363,7 +363,7 @@ function populateAuthAccounts(){
|
||||
const authKeys = Object.keys(authAccounts)
|
||||
const selectedUUID = ConfigManager.getSelectedAccount().uuid
|
||||
|
||||
let authAccountStr = ``
|
||||
let authAccountStr = ''
|
||||
|
||||
authKeys.map((val) => {
|
||||
const acc = authAccounts[val]
|
||||
@ -408,16 +408,16 @@ function prepareAccountsTab() {
|
||||
* Minecraft Tab
|
||||
*/
|
||||
|
||||
/**
|
||||
/**
|
||||
* Disable decimals, negative signs, and scientific notation.
|
||||
*/
|
||||
document.getElementById('settingsGameWidth').addEventListener('keydown', (e) => {
|
||||
if(/[-\.eE]/.test(e.key)){
|
||||
document.getElementById('settingsGameWidth').addEventListener('keydown', (e) => {
|
||||
if(/^[-.eE]$/.test(e.key)){
|
||||
e.preventDefault()
|
||||
}
|
||||
})
|
||||
document.getElementById('settingsGameHeight').addEventListener('keydown', (e) => {
|
||||
if(/[-\.eE]/.test(e.key)){
|
||||
if(/^[-.eE]$/.test(e.key)){
|
||||
e.preventDefault()
|
||||
}
|
||||
})
|
||||
@ -730,7 +730,7 @@ function prepareAboutTab(){
|
||||
* Settings preparation functions.
|
||||
*/
|
||||
|
||||
/**
|
||||
/**
|
||||
* Prepare the entire settings UI.
|
||||
*
|
||||
* @param {boolean} first Whether or not it is the first load.
|
||||
|
@ -104,7 +104,7 @@ function showMainUI(data){
|
||||
}, 750)
|
||||
// Disable tabbing to the news container.
|
||||
initNews().then(() => {
|
||||
$("#newsContainer *").attr('tabindex', '-1')
|
||||
$('#newsContainer *').attr('tabindex', '-1')
|
||||
})
|
||||
}
|
||||
|
||||
@ -313,7 +313,7 @@ async function validateSelectedAccount(){
|
||||
})
|
||||
} else {
|
||||
const accountsObj = ConfigManager.getAuthAccounts()
|
||||
const accounts = Array.from(Object.keys(accountsObj), v => accountsObj[v]);
|
||||
const accounts = Array.from(Object.keys(accountsObj), v => accountsObj[v])
|
||||
// This function validates the account switch.
|
||||
setSelectedAccount(accounts[0].uuid)
|
||||
toggleOverlay(false)
|
||||
|
@ -5,7 +5,7 @@
|
||||
* modules, excluding dependencies.
|
||||
*/
|
||||
// Requirements
|
||||
const $ = require('jquery');
|
||||
const $ = require('jquery')
|
||||
const {ipcRenderer, remote, shell, webFrame} = require('electron')
|
||||
const isDev = require('electron-is-dev')
|
||||
|
||||
@ -50,6 +50,7 @@ if(!isDev){
|
||||
ipcRenderer.send('autoUpdateAction', 'checkForUpdate')
|
||||
}, 1800000)
|
||||
ipcRenderer.send('autoUpdateAction', 'checkForUpdate')
|
||||
break
|
||||
case 'realerror':
|
||||
if(info != null && info.code != null){
|
||||
if(info.code === 'ERR_UPDATER_INVALID_RELEASE_FEED'){
|
||||
@ -108,7 +109,7 @@ $(function(){
|
||||
|
||||
document.addEventListener('readystatechange', function () {
|
||||
if (document.readyState === 'interactive'){
|
||||
console.log('UICore Initializing..');
|
||||
console.log('UICore Initializing..')
|
||||
|
||||
// Bind close button.
|
||||
Array.from(document.getElementsByClassName('fCb')).map((val) => {
|
||||
@ -157,10 +158,10 @@ document.addEventListener('readystatechange', function () {
|
||||
//const targetWidth2 = document.getElementById("server_selection").getBoundingClientRect().width
|
||||
//const targetWidth3 = document.getElementById("launch_button").getBoundingClientRect().width
|
||||
|
||||
document.getElementById("launch_details").style.maxWidth = 266.01
|
||||
document.getElementById("launch_progress").style.width = 170.8
|
||||
document.getElementById("launch_details_right").style.maxWidth = 170.8
|
||||
document.getElementById("launch_progress_label").style.width = 53.21
|
||||
document.getElementById('launch_details').style.maxWidth = 266.01
|
||||
document.getElementById('launch_progress').style.width = 170.8
|
||||
document.getElementById('launch_details_right').style.maxWidth = 170.8
|
||||
document.getElementById('launch_progress_label').style.width = 53.21
|
||||
|
||||
}
|
||||
|
||||
@ -170,7 +171,7 @@ document.addEventListener('readystatechange', function () {
|
||||
* Open web links in the user's default browser.
|
||||
*/
|
||||
$(document).on('click', 'a[href^="http"]', function(event) {
|
||||
event.preventDefault();
|
||||
event.preventDefault()
|
||||
//console.log(os.homedir())
|
||||
shell.openExternal(this.href)
|
||||
})
|
||||
|
@ -1,44 +0,0 @@
|
||||
const app = require('electron')
|
||||
const remote = require('electron').BrowserWindow
|
||||
|
||||
/**
|
||||
* Doesn't work yet.
|
||||
*/
|
||||
exports.setIconBadge = function(text){
|
||||
if(process.platform === 'darwin'){
|
||||
app.dock.setBadge('' + text)
|
||||
} else if (process.platform === 'win32'){
|
||||
const win = remote.getFocusedWindow()
|
||||
if(text === ''){
|
||||
win.setOverlayIcon(null, '')
|
||||
return;
|
||||
}
|
||||
|
||||
//Create badge
|
||||
const canvas = document.createElement('canvas')
|
||||
canvas.height = 140;
|
||||
canvas.width = 140;
|
||||
const ctx = canvas.getContext('2d')
|
||||
ctx.fillStyle = '#a02d2a'
|
||||
ctx.beginPath()
|
||||
ctx.ellipse(70, 70, 70, 70, 0, 0, 2 * Math.PI)
|
||||
ctx.fill()
|
||||
ctx.textAlign = 'center'
|
||||
ctx.fillStyle = 'white'
|
||||
|
||||
if(text.length > 2 ){
|
||||
ctx.font = '75px sans-serif'
|
||||
ctx.fillText('' + text, 70, 98)
|
||||
} else if (text.length > 1){
|
||||
ctx.font = '100px sans-serif'
|
||||
ctx.fillText('' + text, 70, 105)
|
||||
} else {
|
||||
ctx.font = '125px sans-serif'
|
||||
ctx.fillText('' + text, 70, 112)
|
||||
}
|
||||
|
||||
const badgeDataURL = canvas.toDataURL()
|
||||
const img = NativeImage.createFromDataURL(badgeDataURL)
|
||||
win.setOverlayIcon(img, '' + text)
|
||||
}
|
||||
}
|
2
index.js
2
index.js
@ -130,7 +130,7 @@ function getPlatformIcon(filename){
|
||||
return path.join(__dirname, 'app', 'assets', 'images', filename)
|
||||
}
|
||||
|
||||
app.on('ready', createWindow);
|
||||
app.on('ready', createWindow)
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
// On macOS it is common for applications and their menu bar
|
||||
|
888
package-lock.json
generated
888
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -12,7 +12,8 @@
|
||||
"dist:win": "npm run dist -- --win --x64",
|
||||
"dist:mac": "npm run dist -- --mac",
|
||||
"dist:linux": "npm run dist -- --linux --x64",
|
||||
"dist:all": "npm run dist -- -wl --x64"
|
||||
"dist:all": "npm run dist -- -wl --x64",
|
||||
"lint": "eslint --config .eslintrc.json --ignore-pattern app/assets/js/scripts/*.js . && eslint --config .eslintrc.scripts.json app/assets/js/scripts"
|
||||
},
|
||||
"engines": {
|
||||
"node": "10.5.x"
|
||||
@ -47,7 +48,8 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"electron": "^2.0.5",
|
||||
"electron-builder": "^20.24.4"
|
||||
"electron-builder": "^20.24.4",
|
||||
"eslint": "^5.2.0"
|
||||
},
|
||||
"build": {
|
||||
"appId": "westeroscraftlauncher",
|
||||
|
Loading…
Reference in New Issue
Block a user