Added mojang account validation UI.
Other minor fixes included. Bumped version from dev to alpha. Testing to begin soon.
This commit is contained in:
@@ -6,7 +6,6 @@ const cp = require('child_process')
|
||||
const {URL} = require('url')
|
||||
|
||||
// Internal Requirements
|
||||
const AuthManager = require('./assets/js/authmanager.js')
|
||||
const DiscordWrapper = require('./assets/js/discordwrapper.js')
|
||||
const Mojang = require('./assets/js/mojang.js')
|
||||
const ProcessBuilder = require('./assets/js/processbuilder.js')
|
||||
|
||||
@@ -233,8 +233,12 @@ loginButton.addEventListener('click', () => {
|
||||
$('.checkmark').toggle()
|
||||
//console.log(value)
|
||||
setTimeout(() => {
|
||||
$('#loginContainer').fadeOut(500, () => {
|
||||
$('#landingContainer').fadeIn(500)
|
||||
switchView(VIEWS.login, VIEWS.landing, 500, 500, () => {
|
||||
loginUsername.value = ''
|
||||
loginPassword.value = ''
|
||||
loginLoading(false)
|
||||
loginButton.innerHTML = loginButton.innerHTML.replace('SUCCESS', 'LOGIN')
|
||||
formDisabled(false)
|
||||
})
|
||||
}, 1000)
|
||||
}).catch((err) => {
|
||||
|
||||
@@ -109,11 +109,16 @@ document.addEventListener('keydown', (e) => {
|
||||
} else if(e.key === 'Enter'){
|
||||
document.getElementById('serverSelectConfirm').click()
|
||||
}
|
||||
} else if(document.getElementById('accountSelectContent').style.display !== 'none'){
|
||||
console.debug('ServSelLi Keydown Called:', document.getElementById('accountSelectContent').style.display)
|
||||
if(e.key === 'Escape'){
|
||||
document.getElementById('accountSelectCancel').click()
|
||||
} else if(e.key === 'Enter'){
|
||||
document.getElementById('accountSelectConfirm').click()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
document.getElementById('serverSelectActions').onsubmit = () => { return false }
|
||||
|
||||
document.getElementById('serverSelectConfirm').addEventListener('click', () => {
|
||||
const listings = document.getElementsByClassName('serverListing')
|
||||
for(let i=0; i<listings.length; i++){
|
||||
@@ -131,16 +136,45 @@ document.getElementById('serverSelectConfirm').addEventListener('click', () => {
|
||||
// None are selected? Not possible right? Meh, handle it.
|
||||
if(listings.length > 0){
|
||||
ConfigManager.setSelectedServer(listings[0].getAttribute('servid'))
|
||||
ConfigManager.save()
|
||||
updateSelectedServer()
|
||||
toggleOverlay(false)
|
||||
}
|
||||
})
|
||||
|
||||
document.getElementById('accountSelectConfirm').addEventListener('click', () => {
|
||||
const listings = document.getElementsByClassName('accountListing')
|
||||
for(let i=0; i<listings.length; i++){
|
||||
if(listings[i].hasAttribute('selected')){
|
||||
const authAcc = ConfigManager.setSelectedAccount(listings[i].getAttribute('uuid'))
|
||||
ConfigManager.save()
|
||||
updateSelectedAccount(authAcc)
|
||||
toggleOverlay(false)
|
||||
validateSelectedAccount()
|
||||
return
|
||||
}
|
||||
}
|
||||
// None are selected? Not possible right? Meh, handle it.
|
||||
if(listings.length > 0){
|
||||
const authAcc = ConfigManager.setSelectedAccount(listings[0].getAttribute('uuid'))
|
||||
ConfigManager.save()
|
||||
updateSelectedAccount(authAcc)
|
||||
toggleOverlay(false)
|
||||
validateSelectedAccount()
|
||||
}
|
||||
})
|
||||
|
||||
// Bind server select cancel button.
|
||||
document.getElementById('serverSelectCancel').addEventListener('click', () => {
|
||||
toggleOverlay(false)
|
||||
})
|
||||
|
||||
document.getElementById('accountSelectCancel').addEventListener('click', () => {
|
||||
$('#accountSelectContent').fadeOut(250, () => {
|
||||
$('#overlayContent').fadeIn(250)
|
||||
})
|
||||
})
|
||||
|
||||
function setServerListingHandlers(){
|
||||
const listings = Array.from(document.getElementsByClassName('serverListing'))
|
||||
listings.map((val) => {
|
||||
@@ -160,6 +194,25 @@ function setServerListingHandlers(){
|
||||
})
|
||||
}
|
||||
|
||||
function setAccountListingHandlers(){
|
||||
const listings = Array.from(document.getElementsByClassName('accountListing'))
|
||||
listings.map((val) => {
|
||||
val.onclick = e => {
|
||||
if(val.hasAttribute('selected')){
|
||||
return
|
||||
}
|
||||
const cListings = document.getElementsByClassName('accountListing')
|
||||
for(let i=0; i<cListings.length; i++){
|
||||
if(cListings[i].hasAttribute('selected')){
|
||||
cListings[i].removeAttribute('selected')
|
||||
}
|
||||
}
|
||||
val.setAttribute('selected', '')
|
||||
document.activeElement.blur()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function populateServerListings(){
|
||||
const distro = AssetGuard.getDistributionData()
|
||||
const giaSel = ConfigManager.getSelectedServer()
|
||||
@@ -192,7 +245,30 @@ function populateServerListings(){
|
||||
|
||||
}
|
||||
|
||||
function populateAccountListings(){
|
||||
const accountsObj = ConfigManager.getAuthAccounts()
|
||||
const accounts = Array.from(Object.keys(accountsObj), v=>accountsObj[v]);
|
||||
const selectedUUID = ConfigManager.getSelectedAccount().uuid
|
||||
let htmlString = ``
|
||||
for(let i=0; i<accounts.length; i++){
|
||||
if(accounts[i].uuid === selectedUUID) {
|
||||
continue
|
||||
}
|
||||
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">
|
||||
<div class="accountListingName">${accounts[i].displayName}</div>
|
||||
</button>`
|
||||
}
|
||||
document.getElementById('accountSelectListScrollable').innerHTML = htmlString
|
||||
|
||||
}
|
||||
|
||||
function prepareServerSelectionList(){
|
||||
populateServerListings()
|
||||
setServerListingHandlers()
|
||||
}
|
||||
|
||||
function prepareAccountSelectionList(){
|
||||
populateAccountListings()
|
||||
setAccountListingHandlers()
|
||||
}
|
||||
@@ -4,12 +4,54 @@
|
||||
*/
|
||||
// Requirements
|
||||
const path = require('path')
|
||||
const AuthManager = require('./assets/js/authmanager.js')
|
||||
const {AssetGuard} = require('./assets/js/assetguard.js')
|
||||
const ConfigManager = require('./assets/js/configmanager.js')
|
||||
|
||||
let rscShouldLoad = false
|
||||
let fatalStartupError = false
|
||||
|
||||
// Mapping of each view to their container IDs.
|
||||
const VIEWS = {
|
||||
landing: 'landingContainer',
|
||||
login: 'loginContainer',
|
||||
welcome: 'welcomeContainer'
|
||||
}
|
||||
|
||||
// The currently shown view container.
|
||||
let currentView = VIEWS.landing
|
||||
|
||||
/**
|
||||
* Switch launcher views.
|
||||
*
|
||||
* @param {string} current The ID of the current view container.
|
||||
* @param {*} next The ID of the next view container.
|
||||
* @param {*} currentFadeTime Optional. The fade out time for the current view.
|
||||
* @param {*} nextFadeTime Optional. The fade in time for the next view.
|
||||
* @param {*} onCurrentFade Optional. Callback function to execute when the current
|
||||
* view fades out.
|
||||
* @param {*} onNextFade Optional. Callback function to execute when the next view
|
||||
* fades in.
|
||||
*/
|
||||
function switchView(current, next, currentFadeTime = 500, nextFadeTime = 500, onCurrentFade = () => {}, onNextFade = () => {}){
|
||||
currentView = current
|
||||
$(`#${current}`).fadeOut(currentFadeTime, () => {
|
||||
onCurrentFade()
|
||||
$(`#${next}`).fadeIn(nextFadeTime, () => {
|
||||
onNextFade()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the currently shown view container.
|
||||
*
|
||||
* @returns {string} The currently shown view container.
|
||||
*/
|
||||
function getCurrentView(){
|
||||
return currentView
|
||||
}
|
||||
|
||||
function showMainUI(){
|
||||
updateSelectedServer(AssetGuard.getServerById(ConfigManager.getSelectedServer()).name)
|
||||
refreshServerStatus()
|
||||
@@ -18,6 +60,8 @@ function showMainUI(){
|
||||
document.body.style.backgroundImage = `url('assets/images/backgrounds/${document.body.getAttribute('bkid')}.jpg')`
|
||||
$('#main').show()
|
||||
|
||||
//validateSelectedAccount()
|
||||
|
||||
if(ConfigManager.isFirstLaunch()){
|
||||
$('#welcomeContainer').fadeIn(1000)
|
||||
} else {
|
||||
@@ -25,7 +69,7 @@ function showMainUI(){
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
$('#loadingContainer').fadeOut(750, () => {
|
||||
$('#loadingContainer').fadeOut(500, () => {
|
||||
$('#loadSpinnerImage').removeClass('rotating')
|
||||
})
|
||||
}, 500)
|
||||
@@ -70,6 +114,59 @@ function refreshDistributionIndex(remote, onSuccess, onError){
|
||||
}
|
||||
}
|
||||
|
||||
async function validateSelectedAccount(){
|
||||
const selectedAcc = ConfigManager.getSelectedAccount()
|
||||
if(selectedAcc != null){
|
||||
const val = await AuthManager.validateSelected()
|
||||
if(!val){
|
||||
const accLen = Object.keys(ConfigManager.getAuthAccounts()).length
|
||||
setOverlayContent(
|
||||
'Failed to Refresh Login',
|
||||
`We were unable to refresh the login for <strong>${selectedAcc.displayName}</strong>. Please ${accLen > 1 ? 'select another account or ' : ''} login again.`,
|
||||
'Login',
|
||||
'Select Another Account'
|
||||
)
|
||||
setOverlayHandler(() => {
|
||||
document.getElementById('loginUsername').value = selectedAcc.username
|
||||
validateEmail(selectedAcc.username)
|
||||
switchView(getCurrentView(), VIEWS.login)
|
||||
toggleOverlay(false)
|
||||
})
|
||||
setDismissHandler(() => {
|
||||
if(accLen > 2){
|
||||
prepareAccountSelectionList()
|
||||
$('#overlayContent').fadeOut(250, () => {
|
||||
$('#accountSelectContent').fadeIn(250)
|
||||
})
|
||||
} else {
|
||||
const accountsObj = ConfigManager.getAuthAccounts()
|
||||
const accounts = Array.from(Object.keys(accountsObj), v=>accountsObj[v]);
|
||||
const selectedUUID = ConfigManager.getSelectedAccount().uuid
|
||||
for(let i=0; i<accounts.length; i++){
|
||||
if(accounts[i].uuid !== selectedUUID){
|
||||
setSelectedAccount(accounts[i].uuid)
|
||||
toggleOverlay(false)
|
||||
validateSelectedAccount()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
toggleOverlay(true, accLen > 1)
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
function setSelectedAccount(uuid){
|
||||
const authAcc = ConfigManager.setSelectedAccount(uuid)
|
||||
ConfigManager.save()
|
||||
updateSelectedAccount(authAcc)
|
||||
//validateSelectedAccount()
|
||||
}
|
||||
|
||||
// Synchronous Listener
|
||||
document.addEventListener('readystatechange', function(){
|
||||
|
||||
|
||||
@@ -2,7 +2,5 @@
|
||||
* Script for welcome.ejs
|
||||
*/
|
||||
document.getElementById('welcomeButton').addEventListener('click', e => {
|
||||
$('#welcomeContainer').fadeOut(500, () => {
|
||||
$('#loginContainer').fadeIn(500)
|
||||
})
|
||||
switchView(VIEWS.welcome, VIEWS.login)
|
||||
})
|
||||
Reference in New Issue
Block a user