Fixed the popout modal for the native client

master
WolverinDEV 2021-03-22 20:24:34 +01:00
parent f7c1f828c5
commit dd7fa648c4
1 changed files with 23 additions and 7 deletions

View File

@ -1,9 +1,13 @@
import {LogCategory, logError, logInfo, logWarn} from "tc-shared/log"; import {LogCategory, logError, logInfo, logTrace, logWarn} from "tc-shared/log";
import {getIpcInstance, IPCChannel} from "tc-shared/ipc/BrowserIPC"; import {getIpcInstance, IPCChannel} from "tc-shared/ipc/BrowserIPC";
import {Registry} from "tc-events"; import {Registry} from "tc-events";
import {ModalOptions} from "tc-shared/ui/react-elements/modal/Definitions"; import {
ModalInstanceController,
ModalInstanceEvents,
ModalOptions,
ModalState
} from "tc-shared/ui/react-elements/modal/Definitions";
import {guid} from "tc-shared/crypto/uid"; import {guid} from "tc-shared/crypto/uid";
import {ModalInstanceController, ModalInstanceEvents, ModalState} from "tc-shared/ui/react-elements/modal/Definitions";
import {getWindowManager} from "tc-shared/ui/windows/WindowManager"; import {getWindowManager} from "tc-shared/ui/windows/WindowManager";
import {assertMainApplication} from "tc-shared/ui/utils"; import {assertMainApplication} from "tc-shared/ui/utils";
import { import {
@ -23,6 +27,7 @@ export class ExternalModalController implements ModalInstanceController {
private ipcChannel: IPCChannel; private ipcChannel: IPCChannel;
private readonly modalEvents: Registry<ModalInstanceEvents>; private readonly modalEvents: Registry<ModalInstanceEvents>;
private modalInitialized: boolean;
private modalInitializeCallback: () => void; private modalInitializeCallback: () => void;
private windowId: string | undefined; private windowId: string | undefined;
@ -69,6 +74,7 @@ export class ExternalModalController implements ModalInstanceController {
if(this.modalInitializeCallback) { if(this.modalInitializeCallback) {
this.modalInitializeCallback(); this.modalInitializeCallback();
} }
this.modalInitialized = true;
this.sendIpcMessage("hello-controller", { this.sendIpcMessage("hello-controller", {
accepted: true, accepted: true,
@ -120,6 +126,8 @@ export class ExternalModalController implements ModalInstanceController {
return; return;
} }
this.modalInitialized = false;
this.modalInitializeCallback = undefined;
const result = await windowManager.createWindow({ const result = await windowManager.createWindow({
uniqueId: this.modalOptions.uniqueId || this.modalType, uniqueId: this.modalOptions.uniqueId || this.modalType,
loaderTarget: "modal-external", loaderTarget: "modal-external",
@ -149,16 +157,24 @@ export class ExternalModalController implements ModalInstanceController {
this.windowId = result.windowId; this.windowId = result.windowId;
try { try {
await new Promise((resolve, reject) => { if(!this.modalInitialized) {
this.modalInitializeCallback = resolve; await new Promise((resolve, reject) => {
setTimeout(reject, 15000); const timeoutId = setTimeout(reject, 15000);
}); this.modalInitializeCallback = () => {
clearTimeout(timeoutId);
resolve();
};
});
}
} catch (_) { } catch (_) {
logError(LogCategory.IPC, tr("Opened modal failed to call back within 15 seconds.")); logError(LogCategory.IPC, tr("Opened modal failed to call back within 15 seconds."));
getWindowManager().destroyWindow(this.windowId); getWindowManager().destroyWindow(this.windowId);
} finally { } finally {
this.modalInitialized = false;
this.modalInitializeCallback = undefined; this.modalInitializeCallback = undefined;
} }
logTrace(LogCategory.GENERAL, tr("Successfully showed external modal"));
}); });
} }