feature request: Adding new menu item in reader context menu #1773
Replies: 11 comments
-
i don't understand precisely what do you looking for. But if you want to create a new menu in the top bar, our codebase is here : and then you can dispatch a main redux action on click. it should work in prod env. |
Beta Was this translation helpful? Give feedback.
-
Here is the code, The issue is when i right click on the middle of window, Add to bookmark button doesn't appear and it's showing else where. when i right click on setting icon, it's visible in context menu. const wc = readerWindow.webContents;
wc.on("context-menu", (_ev, params) => {
const { x, y } = params;
const openDevToolsAndInspect = () => {
const devToolsOpened = () => {
wc.off("devtools-opened", devToolsOpened);
wc.inspectElement(x, y);
setTimeout(() => {
if (wc.isDevToolsOpened() && wc.devToolsWebContents) {
wc.devToolsWebContents.focus();
}
}, 500);
};
wc.on("devtools-opened", devToolsOpened);
wc.openDevTools({ activate: true, mode: "detach" });
};
Menu.buildFromTemplate([{
label: "Add to Bookmark",
click: () => {
console.log("Add to Bookmark Option Clicked");
// TODO implement the add bookmark function by PRC call
},
}, IS_DEV ? {
click: () => {
const wasOpened = wc.isDevToolsOpened();
if (!wasOpened) {
openDevToolsAndInspect();
} else {
if (!wc.isDevToolsFocused()) {
// wc.toggleDevTools();
wc.closeDevTools();
setImmediate(() => {
openDevToolsAndInspect();
});
} else {
wc.inspectElement(x, y);
}
}
},
label: "Inspect element",
} : undefined]).popup({window: readerWindow});
}); Also, How to pass the RPC call to add to bookmark? Here is what i decided to go with. |
Beta Was this translation helpful? Give feedback.
-
Hello, the "central" part of the reader window is not managed by Thorium's code, it is implemented by the "navigator" component which handles the complex layout and rendering logic of publication resources (in other words, the application user interface is the "chrome" that surrounds this central area). Application developers are not expected to modify / tweak code in the "navigator" component, so ideally / ultimately this component should provide hooks / extension points so that additional context menus / etc. can be plugged in. Right now, this service / API does not exist, I am afraid. Could you please explain what your use case is? What feature do you need the menu items to expose? How much interaction with the rendered DOM of publication HTML documents do you need? (this last question is the main issue, because publication resources are embedded in a strict sandbox, because of security considerations when loading foreign / untrusted content) |
Beta Was this translation helpful? Give feedback.
-
PS: the "add bookmark" feature that already exists in Thorium takes into account the "current reading location" and even the currently-selected text in the webview that hosts publication HTML documents. Users can currently click on the bookmark icon-button (top toolbar), of use the CTRL-B keyboard shortcut (see https://github.com/edrlab/thorium-reader/wiki/Keyboard-shortcuts ). |
Beta Was this translation helpful? Give feedback.
-
@danielweck Yeh your answer makes sense, I also figured that out because the context menu item doesn't appear over the reader view only. My use case is when user selects text and right clicks, I want to provide add to bookmark action in context menu. |
Beta Was this translation helpful? Give feedback.
-
Will the readium.js support that hook in the near future? I'm heavily relying upon that. |
Beta Was this translation helpful? Give feedback.
-
There are no concrete plans, I am afraid. We have several other high development priorities at the moment, and only a small engineering team with finite time. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the hint. It helps a lot. |
Beta Was this translation helpful? Give feedback.
-
thorium-reader/src/renderer/common/redux/api/api.ts Lines 19 to 29 in 321c18b put this on the click function : |
Beta Was this translation helpful? Give feedback.
-
to access to the reader reduxState follow the 'session' key in the main reduxState. |
Beta Was this translation helpful? Give feedback.
-
Moving this to a developer discussion |
Beta Was this translation helpful? Give feedback.
-
I have added the context menu item for the reader window. There already one
Inspect Element
menu entry for dev, I want another entry for a production build. What I'm trying to do is I want context menu itemAdd to Bookmark
and in the click, handler passes the IPC call to renderer process to call the add to bookmark action. But the menu itemAdd to bookmark
won't appear.I' using the latest
develop
branch.Beta Was this translation helpful? Give feedback.
All reactions