diff --git a/src/main/authManager.ts b/src/main/authManager.ts index 7291a36e..678e9afb 100644 --- a/src/main/authManager.ts +++ b/src/main/authManager.ts @@ -62,7 +62,7 @@ export class AuthManager { if (!mainWindow) { return; } - const modalPromise = addModal(`login-${request.url}`, loginModalHtml, modalPreload, {request, authInfo}, mainWindow); + const modalPromise = addModal(authInfo.isProxy ? `proxy-${authInfo.host}` : `login-${request.url}`, loginModalHtml, modalPreload, {request, authInfo}, mainWindow); if (modalPromise) { modalPromise.then((data) => { const {username, password} = data; diff --git a/src/main/server/serverAPI.ts b/src/main/server/serverAPI.ts index 20f17a53..6a2e86ac 100644 --- a/src/main/server/serverAPI.ts +++ b/src/main/server/serverAPI.ts @@ -49,6 +49,7 @@ export async function getServerAPI(url: URL, isAuthenticated: boolean, onSucc } else { onError?.(new Error(`Bad status code requesting from ${url.toString()}`)); } + response.on('error', onError || (() => {})); }); } if (onAbort) { diff --git a/src/main/views/modalManager.ts b/src/main/views/modalManager.ts index bda8e88e..976cb781 100644 --- a/src/main/views/modalManager.ts +++ b/src/main/views/modalManager.ts @@ -13,9 +13,9 @@ import * as WindowManager from '../windows/windowManager'; import {ModalView} from './modalView'; let modalQueue: Array> = []; +const modalPromises: Map> = new Map(); // TODO: add a queue/add differentiation, in case we need to put a modal first in line -// should we return the original promise if called multiple times with the same key? export function addModal(key: string, html: string, preload: string, data: T, win: BrowserWindow) { const foundModal = modalQueue.find((modal) => modal.key === key); if (!foundModal) { @@ -28,9 +28,10 @@ export function addModal(key: string, html: string, preload: string, data showModal(); } + modalPromises.set(key, modalPromise); return modalPromise; } - return null; + return modalPromises.get(key) as Promise; } ipcMain.handle(RETRIEVE_MODAL_INFO, handleInfoRequest); @@ -72,6 +73,7 @@ function handleModalResult(event: IpcMainEvent, data: unknown) { const requestModal = findModalByCaller(event); if (requestModal) { requestModal.resolve(data); + modalPromises.delete(requestModal.key); } filterActive(); if (modalQueue.length) { @@ -86,6 +88,7 @@ function handleModalCancel(event: IpcMainEvent, data: unknown) { const requestModal = findModalByCaller(event); if (requestModal) { requestModal.reject(data); + modalPromises.delete(requestModal.key); } filterActive(); if (modalQueue.length) {