From ee4da7fbccd0b0500f3b3a7043a2d20a987e7212 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Tue, 29 Sep 2020 15:02:00 +0200 Subject: [PATCH] Fixed some remote context menu bugs --- shared/js/ui/context-menu/Ipc.ts | 31 +++++++++----------- shared/js/ui/context-menu/ReactRenderer.scss | 5 +++- shared/js/ui/context-menu/ReactRenderer.tsx | 10 ++++--- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/shared/js/ui/context-menu/Ipc.ts b/shared/js/ui/context-menu/Ipc.ts index 97031af0..96eb3339 100644 --- a/shared/js/ui/context-menu/Ipc.ts +++ b/shared/js/ui/context-menu/Ipc.ts @@ -27,7 +27,7 @@ class IPCContextMenu implements ContextMenuFactory { private closeCallback: () => void; constructor() { - this.ipcChannel = ipc.getInstance().createChannel(Settings.instance.static(Settings.KEY_IPC_REMOTE_ADDRESS, undefined), kIPCContextMenuChannel); + this.ipcChannel = ipc.getInstance().createChannel(undefined, kIPCContextMenuChannel); this.ipcChannel.messageHandler = this.handleIpcMessage.bind(this); /* if we're just created we're the focused window ;) */ @@ -64,9 +64,7 @@ class IPCContextMenu implements ContextMenuFactory { /* fall through wanted! */ case "checkbox": - if(!entry.click) { - return entry; - } + if(!entry.click) { break; } if(!entry.uniqueId) { entry.uniqueId = "r_" + (++this.uniqueEntryId); @@ -74,11 +72,9 @@ class IPCContextMenu implements ContextMenuFactory { this.menuCallbacks[entry.uniqueId] = entry.click; entry.click = undefined; - return entry; - - default: - return entry; + break; } + return entry; } private wrapMenuEntryFromRemote(entry: ContextMenuEntry) : ContextMenuEntry { @@ -87,23 +83,23 @@ class IPCContextMenu implements ContextMenuFactory { if(entry.subMenu) { entry.subMenu = entry.subMenu.map(entry => this.wrapMenuEntryFromRemote(entry)); } - if(entry.icon) { + + if(typeof entry.icon === "object") { const icon = entry.icon as any; entry.icon = getIconManager().resolveIcon(icon.iconId, icon.serverUniqueId); } /* fall through wanted! */ case "checkbox": - if(!entry.uniqueId) { - return entry; - } + if(!entry.uniqueId) { break; } - entry.click = () => this.remoteContextMenuSupplierId && this.ipcChannel.sendMessage("notify-entry-click", { id: entry.uniqueId }, this.remoteContextMenuSupplierId); - return entry; - - default: - return entry; + entry.click = () => { + console.error("Click: %O", this.remoteContextMenuSupplierId); + this.remoteContextMenuSupplierId && this.ipcChannel.sendMessage("notify-entry-click", { id: entry.uniqueId }, this.remoteContextMenuSupplierId); + }; + break; } + return entry; } closeContextMenu() { @@ -142,6 +138,7 @@ class IPCContextMenu implements ContextMenuFactory { /* close out context menu if we've any */ reactContextMenuInstance.closeContextMenu(); } else if(message.type === "notify-entry-click") { + console.error("Entry click: %o", message.data.id); const callback = this.menuCallbacks[message.data.id]; if(!callback) { return; } callback(); diff --git a/shared/js/ui/context-menu/ReactRenderer.scss b/shared/js/ui/context-menu/ReactRenderer.scss index bc0c3467..96c7fae2 100644 --- a/shared/js/ui/context-menu/ReactRenderer.scss +++ b/shared/js/ui/context-menu/ReactRenderer.scss @@ -4,7 +4,10 @@ display: flex; flex-direction: column; - position: static; + position: absolute; + + overflow: hidden; + pointer-events: none; top: 0; left: 0; diff --git a/shared/js/ui/context-menu/ReactRenderer.tsx b/shared/js/ui/context-menu/ReactRenderer.tsx index ea947ee7..e96e9888 100644 --- a/shared/js/ui/context-menu/ReactRenderer.tsx +++ b/shared/js/ui/context-menu/ReactRenderer.tsx @@ -45,10 +45,12 @@ const MenuLabelRenderer = (props: { label: MenuEntryLabel }) => { const MenuEntryRenderer = (props: { entry: ContextMenuEntry }) => { const closeCallback = useContext(CloseCallback); const clickListener = () => { - closeCallback(); - - if("click" in props.entry && typeof props.entry.click === "function") { - props.entry.click(); + try { + if("click" in props.entry && typeof props.entry.click === "function") { + props.entry.click(); + } + } finally { + closeCallback(); } };