Fixed serverAPI throwing error on proxy server challenge, improved modals (#1820)
This commit is contained in:
@@ -62,7 +62,7 @@ export class AuthManager {
|
|||||||
if (!mainWindow) {
|
if (!mainWindow) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const modalPromise = addModal<LoginModalData, LoginModalResult>(`login-${request.url}`, loginModalHtml, modalPreload, {request, authInfo}, mainWindow);
|
const modalPromise = addModal<LoginModalData, LoginModalResult>(authInfo.isProxy ? `proxy-${authInfo.host}` : `login-${request.url}`, loginModalHtml, modalPreload, {request, authInfo}, mainWindow);
|
||||||
if (modalPromise) {
|
if (modalPromise) {
|
||||||
modalPromise.then((data) => {
|
modalPromise.then((data) => {
|
||||||
const {username, password} = data;
|
const {username, password} = data;
|
||||||
|
@@ -49,6 +49,7 @@ export async function getServerAPI<T>(url: URL, isAuthenticated: boolean, onSucc
|
|||||||
} else {
|
} else {
|
||||||
onError?.(new Error(`Bad status code requesting from ${url.toString()}`));
|
onError?.(new Error(`Bad status code requesting from ${url.toString()}`));
|
||||||
}
|
}
|
||||||
|
response.on('error', onError || (() => {}));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (onAbort) {
|
if (onAbort) {
|
||||||
|
@@ -13,9 +13,9 @@ import * as WindowManager from '../windows/windowManager';
|
|||||||
import {ModalView} from './modalView';
|
import {ModalView} from './modalView';
|
||||||
|
|
||||||
let modalQueue: Array<ModalView<any, any>> = [];
|
let modalQueue: Array<ModalView<any, any>> = [];
|
||||||
|
const modalPromises: Map<string, Promise<any>> = new Map();
|
||||||
|
|
||||||
// TODO: add a queue/add differentiation, in case we need to put a modal first in line
|
// 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<T, T2>(key: string, html: string, preload: string, data: T, win: BrowserWindow) {
|
export function addModal<T, T2>(key: string, html: string, preload: string, data: T, win: BrowserWindow) {
|
||||||
const foundModal = modalQueue.find((modal) => modal.key === key);
|
const foundModal = modalQueue.find((modal) => modal.key === key);
|
||||||
if (!foundModal) {
|
if (!foundModal) {
|
||||||
@@ -28,9 +28,10 @@ export function addModal<T, T2>(key: string, html: string, preload: string, data
|
|||||||
showModal();
|
showModal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
modalPromises.set(key, modalPromise);
|
||||||
return modalPromise;
|
return modalPromise;
|
||||||
}
|
}
|
||||||
return null;
|
return modalPromises.get(key) as Promise<T2>;
|
||||||
}
|
}
|
||||||
|
|
||||||
ipcMain.handle(RETRIEVE_MODAL_INFO, handleInfoRequest);
|
ipcMain.handle(RETRIEVE_MODAL_INFO, handleInfoRequest);
|
||||||
@@ -72,6 +73,7 @@ function handleModalResult(event: IpcMainEvent, data: unknown) {
|
|||||||
const requestModal = findModalByCaller(event);
|
const requestModal = findModalByCaller(event);
|
||||||
if (requestModal) {
|
if (requestModal) {
|
||||||
requestModal.resolve(data);
|
requestModal.resolve(data);
|
||||||
|
modalPromises.delete(requestModal.key);
|
||||||
}
|
}
|
||||||
filterActive();
|
filterActive();
|
||||||
if (modalQueue.length) {
|
if (modalQueue.length) {
|
||||||
@@ -86,6 +88,7 @@ function handleModalCancel(event: IpcMainEvent, data: unknown) {
|
|||||||
const requestModal = findModalByCaller(event);
|
const requestModal = findModalByCaller(event);
|
||||||
if (requestModal) {
|
if (requestModal) {
|
||||||
requestModal.reject(data);
|
requestModal.reject(data);
|
||||||
|
modalPromises.delete(requestModal.key);
|
||||||
}
|
}
|
||||||
filterActive();
|
filterActive();
|
||||||
if (modalQueue.length) {
|
if (modalQueue.length) {
|
||||||
|
Reference in New Issue
Block a user