Make logout flow more robust.

This commit is contained in:
Daniel Scalzi 2022-02-07 00:46:23 -05:00
parent eae490b0a7
commit 5ea12d469b
No known key found for this signature in database
GPG Key ID: 9E3E2AFE45328AA5
5 changed files with 32 additions and 24 deletions

View File

@ -21,7 +21,7 @@ const launch_details_text = document.getElementById('launch_details_text')
const server_selection_button = document.getElementById('server_selection_button') const server_selection_button = document.getElementById('server_selection_button')
const user_text = document.getElementById('user_text') const user_text = document.getElementById('user_text')
const loggerLanding = LoggerUtil('%c[Landing]', 'color: #000668; font-weight: bold') const loggerLanding = LoggerUtil1('%c[Landing]', 'color: #000668; font-weight: bold')
/* Launch Progress Wrapper Functions */ /* Launch Progress Wrapper Functions */
@ -293,7 +293,7 @@ function asyncSystemScan(mcVersion, launchAfter = true){
toggleLaunchArea(true) toggleLaunchArea(true)
setLaunchPercentage(0, 100) setLaunchPercentage(0, 100)
const loggerSysAEx = LoggerUtil('%c[SysAEx]', 'color: #353232; font-weight: bold') const loggerSysAEx = LoggerUtil1('%c[SysAEx]', 'color: #353232; font-weight: bold')
const forkEnv = JSON.parse(JSON.stringify(process.env)) const forkEnv = JSON.parse(JSON.stringify(process.env))
forkEnv.CONFIG_DIRECT_PATH = ConfigManager.getLauncherDirectory() forkEnv.CONFIG_DIRECT_PATH = ConfigManager.getLauncherDirectory()
@ -495,8 +495,8 @@ function dlAsync(login = true){
toggleLaunchArea(true) toggleLaunchArea(true)
setLaunchPercentage(0, 100) setLaunchPercentage(0, 100)
const loggerAEx = LoggerUtil('%c[AEx]', 'color: #353232; font-weight: bold') const loggerAEx = LoggerUtil1('%c[AEx]', 'color: #353232; font-weight: bold')
const loggerLaunchSuite = LoggerUtil('%c[LaunchSuite]', 'color: #000668; font-weight: bold') const loggerLaunchSuite = LoggerUtil1('%c[LaunchSuite]', 'color: #000668; font-weight: bold')
const forkEnv = JSON.parse(JSON.stringify(process.env)) const forkEnv = JSON.parse(JSON.stringify(process.env))
forkEnv.CONFIG_DIRECT_PATH = ConfigManager.getLauncherDirectory() forkEnv.CONFIG_DIRECT_PATH = ConfigManager.getLauncherDirectory()

View File

@ -21,7 +21,7 @@ const loginForm = document.getElementById('loginForm')
// Control variables. // Control variables.
let lu = false, lp = false let lu = false, lp = false
const loggerLogin = LoggerUtil('%c[Login]', 'color: #000668; font-weight: bold') const loggerLogin = LoggerUtil1('%c[Login]', 'color: #000668; font-weight: bold')
/** /**

View File

@ -315,6 +315,9 @@ settingsNavDone.onclick = () => {
* Account Management Tab * Account Management Tab
*/ */
const msftLoginLogger = LoggerUtil.getLogger('Microsoft Login')
const msftLogoutLogger = LoggerUtil.getLogger('Microsoft Logout')
// Bind the add mojang account button. // Bind the add mojang account button.
document.getElementById('settingsAddMojangAccount').onclick = (e) => { document.getElementById('settingsAddMojangAccount').onclick = (e) => {
switchView(getCurrentView(), VIEWS.login, 500, 500, () => { switchView(getCurrentView(), VIEWS.login, 500, 500, () => {
@ -338,8 +341,7 @@ ipcRenderer.on(MSFT_OPCODE.REPLY_LOGIN, (_, ...arguments_) => {
if(arguments_.length > 1 && arguments_[1] === MSFT_ERROR.NOT_FINISHED) { if(arguments_.length > 1 && arguments_[1] === MSFT_ERROR.NOT_FINISHED) {
// User cancelled. // User cancelled.
// TODO Get logger from LoggerUtil msftLoginLogger.info('Login cancelled by user.')
console.log('Login Cancelled')
return return
} }
@ -379,8 +381,7 @@ ipcRenderer.on(MSFT_OPCODE.REPLY_LOGIN, (_, ...arguments_) => {
toggleOverlay(true) toggleOverlay(true)
} else { } else {
// TODO Update logging message msftLoginLogger.info('Acquired authCode, proceeding with authentication.')
console.log('Acquired authCode')
const authCode = queryMap.code const authCode = queryMap.code
AuthManager.addMicrosoftAccount(authCode).then(value => { AuthManager.addMicrosoftAccount(authCode).then(value => {
@ -483,14 +484,12 @@ function processLogOut(val, isLastAccount){
// Bind reply for Microsoft Logout. // Bind reply for Microsoft Logout.
ipcRenderer.on(MSFT_OPCODE.REPLY_LOGOUT, (_, ...arguments_) => { ipcRenderer.on(MSFT_OPCODE.REPLY_LOGOUT, (_, ...arguments_) => {
console.log('on logout, ', arguments_)
if (arguments_[0] === MSFT_REPLY_TYPE.ERROR) { if (arguments_[0] === MSFT_REPLY_TYPE.ERROR) {
switchView(getCurrentView(), VIEWS.settings, 500, 500, () => { switchView(getCurrentView(), VIEWS.settings, 500, 500, () => {
if(arguments_.length > 1 && arguments_[1] === MSFT_ERROR.NOT_FINISHED) { if(arguments_.length > 1 && arguments_[1] === MSFT_ERROR.NOT_FINISHED) {
// User cancelled. // User cancelled.
// TODO Get logger from LoggerUtil msftLogoutLogger.info('Logout cancelled by user.')
console.log('Logout Cancelled')
return return
} }
@ -511,7 +510,7 @@ ipcRenderer.on(MSFT_OPCODE.REPLY_LOGOUT, (_, ...arguments_) => {
const isLastAccount = arguments_[2] const isLastAccount = arguments_[2]
const prevSelAcc = ConfigManager.getSelectedAccount() const prevSelAcc = ConfigManager.getSelectedAccount()
console.log('Logout Successful. uuid:', uuid) msftLogoutLogger.info('Logout Successful. uuid:', uuid)
AuthManager.removeMicrosoftAccount(uuid) AuthManager.removeMicrosoftAccount(uuid)
.then(() => { .then(() => {

View File

@ -9,11 +9,12 @@ const $ = require('jquery')
const {ipcRenderer, shell, webFrame} = require('electron') const {ipcRenderer, shell, webFrame} = require('electron')
const remote = require('@electron/remote') const remote = require('@electron/remote')
const isDev = require('./assets/js/isdev') const isDev = require('./assets/js/isdev')
const LoggerUtil = require('./assets/js/loggerutil') const { LoggerUtil } = require('helios-core')
const LoggerUtil1 = require('./assets/js/loggerutil')
const loggerUICore = LoggerUtil('%c[UICore]', 'color: #000668; font-weight: bold') const loggerUICore = LoggerUtil1('%c[UICore]', 'color: #000668; font-weight: bold')
const loggerAutoUpdater = LoggerUtil('%c[AutoUpdater]', 'color: #000668; font-weight: bold') const loggerAutoUpdater = LoggerUtil1('%c[AutoUpdater]', 'color: #000668; font-weight: bold')
const loggerAutoUpdaterSuccess = LoggerUtil('%c[AutoUpdater]', 'color: #209b07; font-weight: bold') const loggerAutoUpdaterSuccess = LoggerUtil1('%c[AutoUpdater]', 'color: #209b07; font-weight: bold')
// Log deprecation and process warnings. // Log deprecation and process warnings.
process.traceProcessWarnings = true process.traceProcessWarnings = true

View File

@ -145,6 +145,7 @@ ipcMain.on(MSFT_OPCODE.OPEN_LOGIN, (ipcEvent) => {
// Microsoft Auth Logout // Microsoft Auth Logout
let msftLogoutWindow let msftLogoutWindow
let msftLogoutSuccess let msftLogoutSuccess
let msftLogoutSuccessSent
ipcMain.on(MSFT_OPCODE.OPEN_LOGOUT, (ipcEvent, uuid, isLastAccount) => { ipcMain.on(MSFT_OPCODE.OPEN_LOGOUT, (ipcEvent, uuid, isLastAccount) => {
if (msftLogoutWindow) { if (msftLogoutWindow) {
ipcEvent.reply(MSFT_OPCODE.REPLY_LOGOUT, MSFT_REPLY_TYPE.ERROR, MSFT_ERROR.ALREADY_OPEN) ipcEvent.reply(MSFT_OPCODE.REPLY_LOGOUT, MSFT_REPLY_TYPE.ERROR, MSFT_ERROR.ALREADY_OPEN)
@ -152,6 +153,7 @@ ipcMain.on(MSFT_OPCODE.OPEN_LOGOUT, (ipcEvent, uuid, isLastAccount) => {
} }
msftLogoutSuccess = false msftLogoutSuccess = false
msftLogoutSuccessSent = false
msftLogoutWindow = new BrowserWindow({ msftLogoutWindow = new BrowserWindow({
title: 'Microsoft Logout', title: 'Microsoft Logout',
backgroundColor: '#222222', backgroundColor: '#222222',
@ -168,21 +170,27 @@ ipcMain.on(MSFT_OPCODE.OPEN_LOGOUT, (ipcEvent, uuid, isLastAccount) => {
msftLogoutWindow.on('close', () => { msftLogoutWindow.on('close', () => {
if(!msftLogoutSuccess) { if(!msftLogoutSuccess) {
ipcEvent.reply(MSFT_OPCODE.REPLY_LOGOUT, MSFT_REPLY_TYPE.ERROR, MSFT_ERROR.NOT_FINISHED) ipcEvent.reply(MSFT_OPCODE.REPLY_LOGOUT, MSFT_REPLY_TYPE.ERROR, MSFT_ERROR.NOT_FINISHED)
} else if(!msftLogoutSuccessSent) {
msftLogoutSuccessSent = true
ipcEvent.reply(MSFT_OPCODE.REPLY_LOGOUT, MSFT_REPLY_TYPE.SUCCESS, uuid, isLastAccount)
} }
}) })
msftLogoutWindow.webContents.on('did-navigate', () => { msftLogoutWindow.webContents.on('did-navigate', (_, uri) => {
setTimeout(() => { if(uri.startsWith('https://login.microsoftonline.com/common/oauth2/v2.0/logoutsession')) {
if(msftLogoutWindow) {
ipcEvent.reply(MSFT_OPCODE.REPLY_LOGOUT, MSFT_REPLY_TYPE.SUCCESS, uuid, isLastAccount)
msftLogoutSuccess = true msftLogoutSuccess = true
setTimeout(() => {
if(!msftLogoutSuccessSent) {
msftLogoutSuccessSent = true
ipcEvent.reply(MSFT_OPCODE.REPLY_LOGOUT, MSFT_REPLY_TYPE.SUCCESS, uuid, isLastAccount)
}
if(msftLogoutWindow) { if(msftLogoutWindow) {
msftLogoutWindow.close() msftLogoutWindow.close()
msftLogoutWindow = null msftLogoutWindow = null
} }
}
}, 5000) }, 5000)
}
}) })
msftLogoutWindow.removeMenu() msftLogoutWindow.removeMenu()