mirror of
https://github.com/Grasscutters/GrassClipper.git
synced 2024-11-16 04:45:34 +00:00
eslint changes
This commit is contained in:
parent
f0210cdbfe
commit
eae6cc087b
29
.eslintrc.json
Normal file
29
.eslintrc.json
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"env": {
|
||||
"browser": true,
|
||||
"commonjs": true,
|
||||
"es2021": true
|
||||
},
|
||||
"extends": "eslint:recommended",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 13
|
||||
},
|
||||
"rules": {
|
||||
"indent": [
|
||||
"error",
|
||||
4
|
||||
],
|
||||
"linebreak-style": [
|
||||
"error",
|
||||
"unix"
|
||||
],
|
||||
"quotes": [
|
||||
"error",
|
||||
"single"
|
||||
],
|
||||
"semi": [
|
||||
"error",
|
||||
"never"
|
||||
]
|
||||
}
|
||||
}
|
@ -9,5 +9,8 @@
|
||||
"build-win": ".\\build_win.cmd",
|
||||
"build-linux": "./build.sh",
|
||||
"build": "echo !! Run build-win or build-linux to build for your platform !!\n"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^8.14.0"
|
||||
}
|
||||
}
|
||||
|
@ -9,37 +9,37 @@ async function displayRegisterAlert(message, type, cooldown = null) {
|
||||
}
|
||||
|
||||
function displayAlert(message, type, cooldown, name) {
|
||||
const elm = document.getElementById(`${name}Alert`);
|
||||
const text = document.getElementById(`${name}AlertText`);
|
||||
const elm = document.getElementById(`${name}Alert`)
|
||||
const text = document.getElementById(`${name}AlertText`)
|
||||
|
||||
elm.style.removeProperty('display');
|
||||
elm.style.removeProperty('display')
|
||||
|
||||
// Remove classification classes
|
||||
elm.classList.remove('error');
|
||||
elm.classList.remove('success');
|
||||
elm.classList.remove('warn');
|
||||
elm.classList.remove('error')
|
||||
elm.classList.remove('success')
|
||||
elm.classList.remove('warn')
|
||||
|
||||
switch(type) {
|
||||
case 'error':
|
||||
elm.classList.add('error');
|
||||
break;
|
||||
elm.classList.add('error')
|
||||
break
|
||||
|
||||
case 'success':
|
||||
elm.classList.add('success');
|
||||
break;
|
||||
elm.classList.add('success')
|
||||
break
|
||||
|
||||
case 'warn':
|
||||
default:
|
||||
elm.classList.add('warn');
|
||||
break;
|
||||
elm.classList.add('warn')
|
||||
break
|
||||
}
|
||||
|
||||
text.innerText = message;
|
||||
text.innerText = message
|
||||
|
||||
clearTimeout(alertTimeout)
|
||||
|
||||
// Disappear after cooldown
|
||||
alertTimeout = setTimeout(() => {
|
||||
elm.style.display = 'none';
|
||||
elm.style.display = 'none'
|
||||
}, cooldown || alertCooldown)
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
async function clearGCInstallation() {
|
||||
Neutralino.os.execCommand(`del /s /q "./gc"`)
|
||||
Neutralino.os.execCommand('del /s /q "./gc"')
|
||||
}
|
||||
|
||||
async function setDownloadButtonsToLoading() {
|
||||
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
async function getCfg() {
|
||||
async function getCfg() {
|
||||
const defaultConf = {
|
||||
gameexe: '',
|
||||
serverFolder: '',
|
||||
@ -32,7 +32,7 @@
|
||||
*
|
||||
* @returns {Promise<string[]>}
|
||||
*/
|
||||
async function getFavIps() {
|
||||
async function getFavIps() {
|
||||
const ipStr = await Neutralino.storage.getData('favorites').catch(e => {
|
||||
// The data isn't set, so this is our first time opening
|
||||
Neutralino.storage.setData('favorites', JSON.stringify([]))
|
||||
@ -106,7 +106,7 @@ async function openGrasscutterFolder() {
|
||||
/**
|
||||
* Minimize the window
|
||||
*/
|
||||
function minimizeWin() {
|
||||
function minimizeWin() {
|
||||
console.log('min')
|
||||
Neutralino.window.minimize()
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
Neutralino.init();
|
||||
Neutralino.init()
|
||||
|
||||
let localeObj;
|
||||
let localeObj
|
||||
const filesystem = Neutralino.filesystem
|
||||
const createCmdWindow = async (command) => {
|
||||
Neutralino.os.execCommand(`cmd.exe /c start "" ${command}`, { background: true })
|
||||
@ -31,7 +31,7 @@ async function enableButtons() {
|
||||
/**
|
||||
* Enable server launch button
|
||||
*/
|
||||
async function enableServerButton() {
|
||||
async function enableServerButton() {
|
||||
const serverBtn = document.querySelector('#serverLaunch')
|
||||
|
||||
serverBtn.classList.remove('disabled')
|
||||
@ -46,7 +46,7 @@ async function handleGameNotSet() {
|
||||
document.querySelector('#gamePath').innerHTML = localeObj.folderNotSet
|
||||
|
||||
// Set official server background to default
|
||||
document.querySelector('#firstPanel').style.backgroundImage = `url("../bg/private/default.png")`
|
||||
document.querySelector('#firstPanel').style.backgroundImage = 'url("../bg/private/default.png")'
|
||||
|
||||
const offBtn = document.querySelector('#playOfficial')
|
||||
const privBtn = document.querySelector('#playPrivate')
|
||||
@ -86,7 +86,7 @@ async function displayGameFolder() {
|
||||
/**
|
||||
* Show the server folder under the select button
|
||||
*/
|
||||
async function displayServerFolder() {
|
||||
async function displayServerFolder() {
|
||||
const elm = document.querySelector('#serverPath')
|
||||
const config = await getCfg()
|
||||
|
||||
@ -106,7 +106,7 @@ async function setBackgroundImage() {
|
||||
const servImage = servImages[Math.floor(Math.random() * servImages.length)].entry
|
||||
|
||||
// Set default image, it will change if the bg folder exists
|
||||
document.querySelector('#firstPanel').style.backgroundImage = `url("https://webstatic.hoyoverse.com/upload/event/2020/11/04/7fd661b5184e1734f91f628b6f89a31f_7367318474207189623.png")`
|
||||
document.querySelector('#firstPanel').style.backgroundImage = 'url("https://webstatic.hoyoverse.com/upload/event/2020/11/04/7fd661b5184e1734f91f628b6f89a31f_7367318474207189623.png")'
|
||||
|
||||
// Set the private background image
|
||||
document.querySelector('#secondPanel').style.backgroundImage = `url("../bg/private/${privImage}")`
|
||||
@ -318,7 +318,7 @@ async function openLogin() {
|
||||
|
||||
const config = await getCfg()
|
||||
const useHttps = config.useHttps
|
||||
const url = `${useHttps ? 'https' : 'http'}://${ip}:${port}`;
|
||||
const url = `${useHttps ? 'https' : 'http'}://${ip}:${port}`
|
||||
|
||||
// Check if we even need to authenticate
|
||||
try {
|
||||
@ -380,10 +380,10 @@ async function checkForUpdatesAndShow() {
|
||||
|
||||
// Version mismatch? Update!
|
||||
if (manifest?.version !== NL_APPVERSION) {
|
||||
subtitle.innerHTML = "New update available!"
|
||||
subtitle.innerHTML = 'New update available!'
|
||||
updateBtn.classList.remove('disabled')
|
||||
} else {
|
||||
subtitle.innerHTML = "You are on the latest version! :)"
|
||||
subtitle.innerHTML = 'You are on the latest version! :)'
|
||||
updateBtn.classList.add('disabled')
|
||||
}
|
||||
}
|
||||
@ -411,7 +411,7 @@ async function setGameExe() {
|
||||
]
|
||||
})
|
||||
|
||||
if (!gameExe[0]) return;
|
||||
if (!gameExe[0]) return
|
||||
|
||||
// Set the folder in our configuration
|
||||
const config = await getCfg()
|
||||
@ -434,7 +434,7 @@ async function setGrasscutterFolder() {
|
||||
]
|
||||
})
|
||||
|
||||
if (!folder[0]) return;
|
||||
if (!folder[0]) return
|
||||
|
||||
// Set the folder in our configuration
|
||||
const config = await getCfg()
|
||||
|
@ -2,60 +2,60 @@
|
||||
* Toggle the login section
|
||||
*/
|
||||
async function setLoginSection() {
|
||||
const title = document.getElementById('loginSectionTitle');
|
||||
const altTitle = document.getElementById('registerSectionTitle');
|
||||
const loginSection = document.getElementById('loginPopupContentBody');
|
||||
const registerSection = document.getElementById('registerPopupContentBody');
|
||||
const title = document.getElementById('loginSectionTitle')
|
||||
const altTitle = document.getElementById('registerSectionTitle')
|
||||
const loginSection = document.getElementById('loginPopupContentBody')
|
||||
const registerSection = document.getElementById('registerPopupContentBody')
|
||||
|
||||
title.classList.add('selectedTitle')
|
||||
altTitle.classList.remove('selectedTitle')
|
||||
|
||||
loginSection.style.removeProperty('display');
|
||||
registerSection.style.display = 'none';
|
||||
loginSection.style.removeProperty('display')
|
||||
registerSection.style.display = 'none'
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle the register section
|
||||
*/
|
||||
async function setRegisterSection(fromLogin = false) {
|
||||
const title = document.getElementById('registerSectionTitle');
|
||||
const altTitle = document.getElementById('loginSectionTitle');
|
||||
const loginSection = document.getElementById('loginPopupContentBody');
|
||||
const registerSection = document.getElementById('registerPopupContentBody');
|
||||
const title = document.getElementById('registerSectionTitle')
|
||||
const altTitle = document.getElementById('loginSectionTitle')
|
||||
const loginSection = document.getElementById('loginPopupContentBody')
|
||||
const registerSection = document.getElementById('registerPopupContentBody')
|
||||
|
||||
title.classList.add('selectedTitle')
|
||||
altTitle.classList.remove('selectedTitle')
|
||||
|
||||
loginSection.style.display = 'none';
|
||||
registerSection.style.removeProperty('display');
|
||||
loginSection.style.display = 'none'
|
||||
registerSection.style.removeProperty('display')
|
||||
|
||||
if (fromLogin) {
|
||||
// Take the values from the login section and put them in the register section
|
||||
const loginUsername = document.getElementById('loginUsername').value;
|
||||
const loginPassword = document.getElementById('loginPassword').value;
|
||||
const loginUsername = document.getElementById('loginUsername').value
|
||||
const loginPassword = document.getElementById('loginPassword').value
|
||||
|
||||
document.getElementById('registerUsername').value = loginUsername;
|
||||
document.getElementById('registerPassword').value = loginPassword;
|
||||
document.getElementById('registerUsername').value = loginUsername
|
||||
document.getElementById('registerPassword').value = loginPassword
|
||||
}
|
||||
}
|
||||
|
||||
function parseJwt(token) {
|
||||
const base64Url = token.split('.')[1];
|
||||
const base64 = base64Url.replace('-', '+').replace('_', '/');
|
||||
return JSON.parse(window.atob(base64));
|
||||
const base64Url = token.split('.')[1]
|
||||
const base64 = base64Url.replace('-', '+').replace('_', '/')
|
||||
return JSON.parse(window.atob(base64))
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt login and launch game
|
||||
*/
|
||||
async function login() {
|
||||
const username = document.getElementById('loginUsername').value;
|
||||
const password = document.getElementById('loginPassword').value;
|
||||
const ip = document.getElementById('ip').value;
|
||||
const port = document.getElementById('port').value || '443';
|
||||
const config = await getCfg();
|
||||
const useHttps = config.useHttps;
|
||||
const url = `${useHttps ? 'https' : 'http'}://${ip}:${port}`;
|
||||
const username = document.getElementById('loginUsername').value
|
||||
const password = document.getElementById('loginPassword').value
|
||||
const ip = document.getElementById('ip').value
|
||||
const port = document.getElementById('port').value || '443'
|
||||
const config = await getCfg()
|
||||
const useHttps = config.useHttps
|
||||
const url = `${useHttps ? 'https' : 'http'}://${ip}:${port}`
|
||||
|
||||
const reqBody = {
|
||||
username,
|
||||
@ -66,35 +66,35 @@ async function login() {
|
||||
|
||||
switch(data.message) {
|
||||
case 'INVALID_ACCOUNT':
|
||||
displayLoginAlert(localeObj.alertInvalid || 'Invalid username or password', 'error');
|
||||
break;
|
||||
displayLoginAlert(localeObj.alertInvalid || 'Invalid username or password', 'error')
|
||||
break
|
||||
|
||||
case 'NO_PASSWORD':
|
||||
// No account password, create one with change password
|
||||
displayLoginAlert(localeObj.alertNoPass || 'No password set, please change password', 'warn');
|
||||
break;
|
||||
displayLoginAlert(localeObj.alertNoPass || 'No password set, please change password', 'warn')
|
||||
break
|
||||
|
||||
case 'UNKNOWN':
|
||||
// Unknown error, contact server owner
|
||||
displayLoginAlert(localeObj.alertUnknown || 'Unknown error, contact server owner', 'error');
|
||||
break;
|
||||
displayLoginAlert(localeObj.alertUnknown || 'Unknown error, contact server owner', 'error')
|
||||
break
|
||||
|
||||
case undefined:
|
||||
case null:
|
||||
case 'AUTH_DISABLED':
|
||||
// Authentication is disabled, we can just connect the user
|
||||
displayLoginAlert(localeObj.alertAuthNoLogin || 'Authentication is disabled, no need to log in!', 'warn');
|
||||
launchPrivate();
|
||||
break;
|
||||
displayLoginAlert(localeObj.alertAuthNoLogin || 'Authentication is disabled, no need to log in!', 'warn')
|
||||
launchPrivate()
|
||||
break
|
||||
|
||||
default:
|
||||
// Success! Copy the JWT token to their clipboard
|
||||
const tkData = parseJwt(data.jwt)
|
||||
await Neutralino.clipboard.writeText(tkData.token)
|
||||
|
||||
displayLoginAlert(localeObj.alertLoginSuccess || 'Login successful! Token copied to clipboard. Paste this token into the username field of the game to log in.', 'success', 8000);
|
||||
displayLoginAlert(localeObj.alertLoginSuccess || 'Login successful! Token copied to clipboard. Paste this token into the username field of the game to log in.', 'success', 8000)
|
||||
launchPrivate()
|
||||
break;
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@ -102,14 +102,14 @@ async function login() {
|
||||
* Attempt registration, do not launch game
|
||||
*/
|
||||
async function register() {
|
||||
const username = document.getElementById('registerUsername').value;
|
||||
const password = document.getElementById('registerPassword').value;
|
||||
const password_confirmation = document.getElementById('registerPasswordConfirm').value;
|
||||
const ip = document.getElementById('ip').value;
|
||||
const port = document.getElementById('port').value || '443';
|
||||
const config = await getCfg();
|
||||
const useHttps = config.useHttps;
|
||||
const url = `${useHttps ? 'https' : 'http'}://${ip}:${port}`;
|
||||
const username = document.getElementById('registerUsername').value
|
||||
const password = document.getElementById('registerPassword').value
|
||||
const password_confirmation = document.getElementById('registerPasswordConfirm').value
|
||||
const ip = document.getElementById('ip').value
|
||||
const port = document.getElementById('port').value || '443'
|
||||
const config = await getCfg()
|
||||
const useHttps = config.useHttps
|
||||
const url = `${useHttps ? 'https' : 'http'}://${ip}:${port}`
|
||||
|
||||
const reqBody = {
|
||||
username,
|
||||
@ -122,33 +122,33 @@ async function register() {
|
||||
switch(data.message) {
|
||||
case 'USERNAME_TAKEN':
|
||||
// Username is taken
|
||||
displayRegisterAlert(localeObj.alertUserTaken || 'Username is taken', 'error');
|
||||
break;
|
||||
displayRegisterAlert(localeObj.alertUserTaken || 'Username is taken', 'error')
|
||||
break
|
||||
|
||||
case 'PASSWORD_MISMATCH':
|
||||
// The password and password confirmation do not match
|
||||
displayRegisterAlert(localStorage.alertPassMismatch || 'Password and password confirmation do not match', 'error');
|
||||
break;
|
||||
displayRegisterAlert(localStorage.alertPassMismatch || 'Password and password confirmation do not match', 'error')
|
||||
break
|
||||
|
||||
case 'UNKNOWN':
|
||||
// Unknown error, contact server owner
|
||||
displayRegisterAlert(localeObj.alertUnknown || 'Unknown error, contact server owner', 'error');
|
||||
break;
|
||||
displayRegisterAlert(localeObj.alertUnknown || 'Unknown error, contact server owner', 'error')
|
||||
break
|
||||
|
||||
case undefined:
|
||||
case null:
|
||||
case 'AUTH_DISABLED':
|
||||
// Authentication is disabled, we can just connect the user
|
||||
displayRegisterAlert(localeObj.alertAuthNoRegister || 'Authentication is disabled, no need to register!', 'warn');
|
||||
break;
|
||||
displayRegisterAlert(localeObj.alertAuthNoRegister || 'Authentication is disabled, no need to register!', 'warn')
|
||||
break
|
||||
|
||||
default:
|
||||
// Success!! Bring them to the login screen and auto-input their username
|
||||
const loginUsername = document.getElementById('loginUsername');
|
||||
loginUsername.value = username;
|
||||
const loginUsername = document.getElementById('loginUsername')
|
||||
loginUsername.value = username
|
||||
|
||||
setLoginSection();
|
||||
displayLoginAlert(localeObj.alertRegisterSuccess || 'Registration successful!', 'success', 5000);
|
||||
break;
|
||||
setLoginSection()
|
||||
displayLoginAlert(localeObj.alertRegisterSuccess || 'Registration successful!', 'success', 5000)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@ -3,11 +3,11 @@
|
||||
* Every autofill, such as backgrounds and the game folder,
|
||||
* should be done here to ensure DOM contents are loaded.
|
||||
*/
|
||||
document.addEventListener('DOMContentLoaded', async () => {
|
||||
displayUpdate();
|
||||
setBackgroundImage();
|
||||
displayGameFolder();
|
||||
displayServerFolder();
|
||||
document.addEventListener('DOMContentLoaded', async () => {
|
||||
displayUpdate()
|
||||
setBackgroundImage()
|
||||
displayGameFolder()
|
||||
displayServerFolder()
|
||||
|
||||
// Set title version
|
||||
document.querySelector('#version').innerHTML = NL_APPVERSION
|
||||
@ -35,7 +35,7 @@
|
||||
}
|
||||
|
||||
// Exit favorites list and settings panel when clicking outside of it
|
||||
window.addEventListener("click", function(e) {
|
||||
window.addEventListener('click', function(e) {
|
||||
const favList = document.querySelector('#ipList')
|
||||
const settingsPanel = document.querySelector('#settingsPanel')
|
||||
const downloadPanel = document.querySelector('#downloadPanel')
|
||||
@ -74,7 +74,7 @@
|
||||
downloadPanel.style.display = 'none'
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
// Ensure we do the translation at the very end, after everything else has loaded
|
||||
await doTranslation()
|
||||
|
@ -72,7 +72,7 @@ async function handleLanguageChange(elm) {
|
||||
/**
|
||||
* Toggle the use of HTTPS
|
||||
*/
|
||||
async function toggleHttps() {
|
||||
async function toggleHttps() {
|
||||
const httpsCheckbox = document.querySelector('#httpsOption')
|
||||
const config = await getCfg()
|
||||
|
||||
@ -86,7 +86,7 @@ async function handleLanguageChange(elm) {
|
||||
* OR
|
||||
* Remove the current value of the IP input from the favorites list
|
||||
*/
|
||||
async function setFavorite() {
|
||||
async function setFavorite() {
|
||||
const ip = document.querySelector('#ip').value
|
||||
const port = document.querySelector('#port').value || '443'
|
||||
const ipArr = await getFavIps()
|
||||
|
@ -1,25 +1,25 @@
|
||||
// https://stackoverflow.com/questions/67971689/positioning-the-borderless-window-in-neutralino-js
|
||||
// had to use this since the in-built function breaks the close and minimize buttons
|
||||
let dragging = false, ratio = 1, posX, posY;
|
||||
let draggable;
|
||||
let dragging = false, ratio = 1, posX, posY
|
||||
let draggable
|
||||
|
||||
document.addEventListener('DOMContentLoaded', async () => {
|
||||
draggable = document.getElementById('controlBar');
|
||||
draggable = document.getElementById('controlBar')
|
||||
|
||||
// Listen to hovers
|
||||
draggable.onmousedown = function (e) {
|
||||
ratio = window.devicePixelRatio
|
||||
|
||||
posX = e.pageX * ratio, posY = e.pageY * ratio;
|
||||
dragging = true;
|
||||
posX = e.pageX * ratio, posY = e.pageY * ratio
|
||||
dragging = true
|
||||
}
|
||||
|
||||
// Patch for monitors with scaling enabled, allows them to detach from the titlebar anywhere
|
||||
window.onmouseup = function (e) {
|
||||
dragging = false;
|
||||
dragging = false
|
||||
}
|
||||
|
||||
document.onmousemove = function (e) {
|
||||
if (dragging) Neutralino.window.move(e.screenX * ratio - posX, e.screenY * ratio - posY);
|
||||
if (dragging) Neutralino.window.move(e.screenX * ratio - posX, e.screenY * ratio - posY)
|
||||
}
|
||||
})
|
Loading…
Reference in New Issue
Block a user