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