Fixed some remote context menu bugs
This commit is contained in:
parent
7a6f1691d3
commit
ee4da7fbcc
3 changed files with 24 additions and 22 deletions
|
@ -27,7 +27,7 @@ class IPCContextMenu implements ContextMenuFactory {
|
||||||
private closeCallback: () => void;
|
private closeCallback: () => void;
|
||||||
|
|
||||||
constructor() {
|
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);
|
this.ipcChannel.messageHandler = this.handleIpcMessage.bind(this);
|
||||||
|
|
||||||
/* if we're just created we're the focused window ;) */
|
/* if we're just created we're the focused window ;) */
|
||||||
|
@ -64,9 +64,7 @@ class IPCContextMenu implements ContextMenuFactory {
|
||||||
|
|
||||||
/* fall through wanted! */
|
/* fall through wanted! */
|
||||||
case "checkbox":
|
case "checkbox":
|
||||||
if(!entry.click) {
|
if(!entry.click) { break; }
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!entry.uniqueId) {
|
if(!entry.uniqueId) {
|
||||||
entry.uniqueId = "r_" + (++this.uniqueEntryId);
|
entry.uniqueId = "r_" + (++this.uniqueEntryId);
|
||||||
|
@ -74,11 +72,9 @@ class IPCContextMenu implements ContextMenuFactory {
|
||||||
|
|
||||||
this.menuCallbacks[entry.uniqueId] = entry.click;
|
this.menuCallbacks[entry.uniqueId] = entry.click;
|
||||||
entry.click = undefined;
|
entry.click = undefined;
|
||||||
return entry;
|
break;
|
||||||
|
|
||||||
default:
|
|
||||||
return entry;
|
|
||||||
}
|
}
|
||||||
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
private wrapMenuEntryFromRemote(entry: ContextMenuEntry) : ContextMenuEntry {
|
private wrapMenuEntryFromRemote(entry: ContextMenuEntry) : ContextMenuEntry {
|
||||||
|
@ -87,23 +83,23 @@ class IPCContextMenu implements ContextMenuFactory {
|
||||||
if(entry.subMenu) {
|
if(entry.subMenu) {
|
||||||
entry.subMenu = entry.subMenu.map(entry => this.wrapMenuEntryFromRemote(entry));
|
entry.subMenu = entry.subMenu.map(entry => this.wrapMenuEntryFromRemote(entry));
|
||||||
}
|
}
|
||||||
if(entry.icon) {
|
|
||||||
|
if(typeof entry.icon === "object") {
|
||||||
const icon = entry.icon as any;
|
const icon = entry.icon as any;
|
||||||
entry.icon = getIconManager().resolveIcon(icon.iconId, icon.serverUniqueId);
|
entry.icon = getIconManager().resolveIcon(icon.iconId, icon.serverUniqueId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* fall through wanted! */
|
/* fall through wanted! */
|
||||||
case "checkbox":
|
case "checkbox":
|
||||||
if(!entry.uniqueId) {
|
if(!entry.uniqueId) { break; }
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
|
|
||||||
entry.click = () => this.remoteContextMenuSupplierId && this.ipcChannel.sendMessage("notify-entry-click", { id: entry.uniqueId }, this.remoteContextMenuSupplierId);
|
entry.click = () => {
|
||||||
return entry;
|
console.error("Click: %O", this.remoteContextMenuSupplierId);
|
||||||
|
this.remoteContextMenuSupplierId && this.ipcChannel.sendMessage("notify-entry-click", { id: entry.uniqueId }, this.remoteContextMenuSupplierId);
|
||||||
default:
|
};
|
||||||
return entry;
|
break;
|
||||||
}
|
}
|
||||||
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
closeContextMenu() {
|
closeContextMenu() {
|
||||||
|
@ -142,6 +138,7 @@ class IPCContextMenu implements ContextMenuFactory {
|
||||||
/* close out context menu if we've any */
|
/* close out context menu if we've any */
|
||||||
reactContextMenuInstance.closeContextMenu();
|
reactContextMenuInstance.closeContextMenu();
|
||||||
} else if(message.type === "notify-entry-click") {
|
} else if(message.type === "notify-entry-click") {
|
||||||
|
console.error("Entry click: %o", message.data.id);
|
||||||
const callback = this.menuCallbacks[message.data.id];
|
const callback = this.menuCallbacks[message.data.id];
|
||||||
if(!callback) { return; }
|
if(!callback) { return; }
|
||||||
callback();
|
callback();
|
||||||
|
|
|
@ -4,7 +4,10 @@
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|
||||||
position: static;
|
position: absolute;
|
||||||
|
|
||||||
|
overflow: hidden;
|
||||||
|
pointer-events: none;
|
||||||
|
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
|
|
|
@ -45,10 +45,12 @@ const MenuLabelRenderer = (props: { label: MenuEntryLabel }) => {
|
||||||
const MenuEntryRenderer = (props: { entry: ContextMenuEntry }) => {
|
const MenuEntryRenderer = (props: { entry: ContextMenuEntry }) => {
|
||||||
const closeCallback = useContext(CloseCallback);
|
const closeCallback = useContext(CloseCallback);
|
||||||
const clickListener = () => {
|
const clickListener = () => {
|
||||||
closeCallback();
|
try {
|
||||||
|
if("click" in props.entry && typeof props.entry.click === "function") {
|
||||||
if("click" in props.entry && typeof props.entry.click === "function") {
|
props.entry.click();
|
||||||
props.entry.click();
|
}
|
||||||
|
} finally {
|
||||||
|
closeCallback();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue