2020-08-07 19:03:54 -04:00
|
|
|
import {AbstractExternalModalController} from "tc-shared/ui/react-elements/external-modal/Controller";
|
2020-08-21 07:37:10 -04:00
|
|
|
import {Popout2ControllerMessages, PopoutIPCMessage} from "tc-shared/ui/react-elements/external-modal/IPCMessage";
|
2020-08-23 15:26:27 -04:00
|
|
|
import {ExternalModal, kIPCChannelExternalModal} from "../shared/ipc/ExternalModal";
|
|
|
|
import {ObjectProxyClient} from "../shared/proxy/Client";
|
|
|
|
import {ProxiedClass} from "../shared/proxy/Definitions";
|
2020-12-13 08:51:10 -05:00
|
|
|
import {getIpcInstance} from "tc-shared/ipc/BrowserIPC";
|
2020-08-23 15:26:27 -04:00
|
|
|
|
|
|
|
const modalClient = new ObjectProxyClient<ExternalModal>(kIPCChannelExternalModal);
|
|
|
|
modalClient.initialize();
|
2020-08-07 19:03:54 -04:00
|
|
|
|
2020-08-21 07:37:10 -04:00
|
|
|
export class ExternalModalController extends AbstractExternalModalController {
|
2020-08-23 15:26:27 -04:00
|
|
|
private handle: ProxiedClass<ExternalModal> & ExternalModal;
|
2020-08-07 19:03:54 -04:00
|
|
|
|
|
|
|
constructor(a, b, c) {
|
|
|
|
super(a, b, c);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected async spawnWindow(): Promise<boolean> {
|
2020-08-23 15:26:27 -04:00
|
|
|
if(!this.handle) {
|
|
|
|
this.handle = await modalClient.createNewInstance();
|
2020-08-07 19:03:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
const parameters = {
|
|
|
|
"loader-target": "manifest",
|
|
|
|
"chunk": "modal-external",
|
|
|
|
"modal-target": this.modalType,
|
|
|
|
"ipc-channel": this.ipcChannel.channelId,
|
2020-12-13 08:51:10 -05:00
|
|
|
"ipc-address": getIpcInstance().getLocalAddress(),
|
2020-08-21 07:37:10 -04:00
|
|
|
"loader-abort": 0,
|
|
|
|
"animation-short": 1
|
2020-08-07 19:03:54 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
const baseUrl = location.origin + location.pathname + "?";
|
|
|
|
const url = baseUrl + Object.keys(parameters).map(e => e + "=" + encodeURIComponent(parameters[e])).join("&");
|
|
|
|
|
2020-08-23 15:26:27 -04:00
|
|
|
return await this.handle.spawnWindow(this.modalType, url);
|
2020-08-07 19:03:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
protected destroyWindow(): void {
|
2020-08-23 15:26:27 -04:00
|
|
|
this.handle?.destroy();
|
|
|
|
this.handle = undefined;
|
2020-08-07 19:03:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
protected focusWindow(): void {
|
2020-08-23 15:26:27 -04:00
|
|
|
this.handle?.focus().then(() => {});
|
2020-08-07 19:03:54 -04:00
|
|
|
}
|
|
|
|
|
2020-08-21 07:37:10 -04:00
|
|
|
protected handleTypedIPCMessage<T extends Popout2ControllerMessages>(type: T, payload: PopoutIPCMessage[T]) {
|
|
|
|
super.handleTypedIPCMessage(type, payload);
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case "invoke-modal-action":
|
|
|
|
const data = payload as PopoutIPCMessage["invoke-modal-action"];
|
|
|
|
switch (data.action) {
|
|
|
|
case "close":
|
|
|
|
this.destroy();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "minimize":
|
2020-08-23 15:26:27 -04:00
|
|
|
this.handle?.minimize().then(() => {});
|
2020-08-21 07:37:10 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "hello-popout":
|
|
|
|
break;
|
|
|
|
}
|
2020-08-07 19:03:54 -04:00
|
|
|
}
|
2020-08-21 07:37:10 -04:00
|
|
|
}
|