From 5ea12d469b63b752b02417b02c7dad044382e355 Mon Sep 17 00:00:00 2001 From: Daniel Scalzi Date: Mon, 7 Feb 2022 00:46:23 -0500 Subject: [PATCH] Make logout flow more robust. --- app/assets/js/scripts/landing.js | 8 ++++---- app/assets/js/scripts/login.js | 2 +- app/assets/js/scripts/settings.js | 15 +++++++-------- app/assets/js/scripts/uicore.js | 9 +++++---- index.js | 22 +++++++++++++++------- 5 files changed, 32 insertions(+), 24 deletions(-) diff --git a/app/assets/js/scripts/landing.js b/app/assets/js/scripts/landing.js index 9beabb78..41021f0a 100644 --- a/app/assets/js/scripts/landing.js +++ b/app/assets/js/scripts/landing.js @@ -21,7 +21,7 @@ const launch_details_text = document.getElementById('launch_details_text') const server_selection_button = document.getElementById('server_selection_button') 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 */ @@ -293,7 +293,7 @@ function asyncSystemScan(mcVersion, launchAfter = true){ toggleLaunchArea(true) 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)) forkEnv.CONFIG_DIRECT_PATH = ConfigManager.getLauncherDirectory() @@ -495,8 +495,8 @@ function dlAsync(login = true){ toggleLaunchArea(true) setLaunchPercentage(0, 100) - const loggerAEx = LoggerUtil('%c[AEx]', 'color: #353232; font-weight: bold') - const loggerLaunchSuite = LoggerUtil('%c[LaunchSuite]', 'color: #000668; font-weight: bold') + const loggerAEx = LoggerUtil1('%c[AEx]', 'color: #353232; font-weight: bold') + const loggerLaunchSuite = LoggerUtil1('%c[LaunchSuite]', 'color: #000668; font-weight: bold') const forkEnv = JSON.parse(JSON.stringify(process.env)) forkEnv.CONFIG_DIRECT_PATH = ConfigManager.getLauncherDirectory() diff --git a/app/assets/js/scripts/login.js b/app/assets/js/scripts/login.js index 6c83c17f..4bc79b9d 100644 --- a/app/assets/js/scripts/login.js +++ b/app/assets/js/scripts/login.js @@ -21,7 +21,7 @@ const loginForm = document.getElementById('loginForm') // Control variables. 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') /** diff --git a/app/assets/js/scripts/settings.js b/app/assets/js/scripts/settings.js index 8b8698d6..73d6b6c2 100644 --- a/app/assets/js/scripts/settings.js +++ b/app/assets/js/scripts/settings.js @@ -315,6 +315,9 @@ settingsNavDone.onclick = () => { * Account Management Tab */ +const msftLoginLogger = LoggerUtil.getLogger('Microsoft Login') +const msftLogoutLogger = LoggerUtil.getLogger('Microsoft Logout') + // Bind the add mojang account button. document.getElementById('settingsAddMojangAccount').onclick = (e) => { 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) { // User cancelled. - // TODO Get logger from LoggerUtil - console.log('Login Cancelled') + msftLoginLogger.info('Login cancelled by user.') return } @@ -379,8 +381,7 @@ ipcRenderer.on(MSFT_OPCODE.REPLY_LOGIN, (_, ...arguments_) => { toggleOverlay(true) } else { - // TODO Update logging message - console.log('Acquired authCode') + msftLoginLogger.info('Acquired authCode, proceeding with authentication.') const authCode = queryMap.code AuthManager.addMicrosoftAccount(authCode).then(value => { @@ -483,14 +484,12 @@ function processLogOut(val, isLastAccount){ // Bind reply for Microsoft Logout. ipcRenderer.on(MSFT_OPCODE.REPLY_LOGOUT, (_, ...arguments_) => { - console.log('on logout, ', arguments_) if (arguments_[0] === MSFT_REPLY_TYPE.ERROR) { switchView(getCurrentView(), VIEWS.settings, 500, 500, () => { if(arguments_.length > 1 && arguments_[1] === MSFT_ERROR.NOT_FINISHED) { // User cancelled. - // TODO Get logger from LoggerUtil - console.log('Logout Cancelled') + msftLogoutLogger.info('Logout cancelled by user.') return } @@ -511,7 +510,7 @@ ipcRenderer.on(MSFT_OPCODE.REPLY_LOGOUT, (_, ...arguments_) => { const isLastAccount = arguments_[2] const prevSelAcc = ConfigManager.getSelectedAccount() - console.log('Logout Successful. uuid:', uuid) + msftLogoutLogger.info('Logout Successful. uuid:', uuid) AuthManager.removeMicrosoftAccount(uuid) .then(() => { diff --git a/app/assets/js/scripts/uicore.js b/app/assets/js/scripts/uicore.js index 7d3cddbd..cb36c9d5 100644 --- a/app/assets/js/scripts/uicore.js +++ b/app/assets/js/scripts/uicore.js @@ -9,11 +9,12 @@ const $ = require('jquery') const {ipcRenderer, shell, webFrame} = require('electron') const remote = require('@electron/remote') 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 loggerAutoUpdater = LoggerUtil('%c[AutoUpdater]', 'color: #000668; font-weight: bold') -const loggerAutoUpdaterSuccess = LoggerUtil('%c[AutoUpdater]', 'color: #209b07; font-weight: bold') +const loggerUICore = LoggerUtil1('%c[UICore]', 'color: #000668; font-weight: bold') +const loggerAutoUpdater = LoggerUtil1('%c[AutoUpdater]', 'color: #000668; font-weight: bold') +const loggerAutoUpdaterSuccess = LoggerUtil1('%c[AutoUpdater]', 'color: #209b07; font-weight: bold') // Log deprecation and process warnings. process.traceProcessWarnings = true diff --git a/index.js b/index.js index 4a8e48a4..a2c43226 100644 --- a/index.js +++ b/index.js @@ -145,6 +145,7 @@ ipcMain.on(MSFT_OPCODE.OPEN_LOGIN, (ipcEvent) => { // Microsoft Auth Logout let msftLogoutWindow let msftLogoutSuccess +let msftLogoutSuccessSent ipcMain.on(MSFT_OPCODE.OPEN_LOGOUT, (ipcEvent, uuid, isLastAccount) => { if (msftLogoutWindow) { 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 + msftLogoutSuccessSent = false msftLogoutWindow = new BrowserWindow({ title: 'Microsoft Logout', backgroundColor: '#222222', @@ -168,21 +170,27 @@ ipcMain.on(MSFT_OPCODE.OPEN_LOGOUT, (ipcEvent, uuid, isLastAccount) => { msftLogoutWindow.on('close', () => { if(!msftLogoutSuccess) { 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', () => { - setTimeout(() => { - if(msftLogoutWindow) { - ipcEvent.reply(MSFT_OPCODE.REPLY_LOGOUT, MSFT_REPLY_TYPE.SUCCESS, uuid, isLastAccount) - msftLogoutSuccess = true + msftLogoutWindow.webContents.on('did-navigate', (_, uri) => { + if(uri.startsWith('https://login.microsoftonline.com/common/oauth2/v2.0/logoutsession')) { + msftLogoutSuccess = true + setTimeout(() => { + if(!msftLogoutSuccessSent) { + msftLogoutSuccessSent = true + ipcEvent.reply(MSFT_OPCODE.REPLY_LOGOUT, MSFT_REPLY_TYPE.SUCCESS, uuid, isLastAccount) + } if(msftLogoutWindow) { msftLogoutWindow.close() msftLogoutWindow = null } - } - }, 5000) + }, 5000) + } }) msftLogoutWindow.removeMenu()