diff --git a/app/assets/js/scripts/loginOptions.js b/app/assets/js/scripts/loginOptions.js index 5d4d6fc0..cdb1bc8e 100644 --- a/app/assets/js/scripts/loginOptions.js +++ b/app/assets/js/scripts/loginOptions.js @@ -1,12 +1,14 @@ const loginOptionsCancelContainer = document.getElementById('loginOptionCancelContainer') const loginOptionMicrosoft = document.getElementById('loginOptionMicrosoft') const loginOptionMojang = document.getElementById('loginOptionMojang') +const loginOptionsCancelButton = document.getElementById('loginOptionCancelButton') let loginOptionsCancellable = false let loginOptionsViewOnLoginSuccess let loginOptionsViewOnLoginCancel let loginOptionsViewOnCancel +let loginOptionsViewCancelHandler function loginOptionsCancelEnabled(val){ if(val){ @@ -33,3 +35,16 @@ loginOptionMojang.onclick = (e) => { loginCancelEnabled(true) }) } + +loginOptionsCancelButton.onclick = (e) => { + switchView(getCurrentView(), loginOptionsViewOnCancel, 500, 500, () => { + // Clear login values (Mojang login) + // No cleanup needed for Microsoft. + loginUsername.value = '' + loginPassword.value = '' + if(loginOptionsViewCancelHandler != null){ + loginOptionsViewCancelHandler() + loginOptionsViewCancelHandler = null + } + }) +} \ No newline at end of file diff --git a/app/assets/js/scripts/overlay.js b/app/assets/js/scripts/overlay.js index 22d81d62..cf2c5c98 100644 --- a/app/assets/js/scripts/overlay.js +++ b/app/assets/js/scripts/overlay.js @@ -197,6 +197,9 @@ document.getElementById('accountSelectConfirm').addEventListener('click', () => const authAcc = ConfigManager.setSelectedAccount(listings[i].getAttribute('uuid')) ConfigManager.save() updateSelectedAccount(authAcc) + if(getCurrentView() === VIEWS.settings) { + prepareSettings() + } toggleOverlay(false) validateSelectedAccount() return @@ -207,6 +210,9 @@ document.getElementById('accountSelectConfirm').addEventListener('click', () => const authAcc = ConfigManager.setSelectedAccount(listings[0].getAttribute('uuid')) ConfigManager.save() updateSelectedAccount(authAcc) + if(getCurrentView() === VIEWS.settings) { + prepareSettings() + } toggleOverlay(false) validateSelectedAccount() } diff --git a/app/assets/js/scripts/uibinder.js b/app/assets/js/scripts/uibinder.js index 087646de..d3385140 100644 --- a/app/assets/js/scripts/uibinder.js +++ b/app/assets/js/scripts/uibinder.js @@ -334,20 +334,46 @@ async function validateSelectedAccount(){ 'Select Another Account' ) setOverlayHandler(() => { - document.getElementById('loginUsername').value = selectedAcc.username - validateEmail(selectedAcc.username) - loginViewOnSuccess = getCurrentView() - loginViewOnCancel = getCurrentView() - if(accLen > 0){ - loginViewCancelHandler = () => { - ConfigManager.addMojangAuthAccount(selectedAcc.uuid, selectedAcc.accessToken, selectedAcc.username, selectedAcc.displayName) + + const isMicrosoft = selectedAcc.type === 'microsoft' + + if(isMicrosoft) { + // Empty for now + } else { + // Mojang + // For convenience, pre-populate the username of the account. + document.getElementById('loginUsername').value = selectedAcc.username + validateEmail(selectedAcc.username) + } + + loginOptionsViewOnLoginSuccess = getCurrentView() + loginOptionsViewOnLoginCancel = VIEWS.loginOptions + + if(accLen > 0) { + loginOptionsViewOnCancel = getCurrentView() + loginOptionsViewCancelHandler = () => { + if(isMicrosoft) { + ConfigManager.addMicrosoftAuthAccount( + selectedAcc.uuid, + selectedAcc.accessToken, + selectedAcc.username, + selectedAcc.expiresAt, + selectedAcc.microsoft.access_token, + selectedAcc.microsoft.refresh_token, + selectedAcc.microsoft.expires_at + ) + } else { + ConfigManager.addMojangAuthAccount(selectedAcc.uuid, selectedAcc.accessToken, selectedAcc.username, selectedAcc.displayName) + } ConfigManager.save() validateSelectedAccount() } - loginCancelEnabled(true) + loginOptionsCancelEnabled(true) + } else { + loginOptionsCancelEnabled(false) } toggleOverlay(false) - switchView(getCurrentView(), VIEWS.login) + switchView(getCurrentView(), VIEWS.loginOptions) }) setDismissHandler(() => { if(accLen > 1){