Repository navigation
feature request: Adding new menu item in reader context menu #1773
Replies: 13 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. |
|
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. |
|
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) |
|
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 ). |
|
@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. |
|
Will the readium.js support that hook in the near future? I'm heavily relying upon that. |
|
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. |
|
Thanks for the hint. It helps a lot. |
|
thorium-reader/src/renderer/common/redux/api/api.ts Lines 19 to 29 in 321c18b put this on the click function : |
|
to access to the reader reduxState follow the 'session' key in the main reduxState. |
|
Moving this to a developer discussion |
|
The main "blocker" for this functional evolution of Thorium's Graphical User Interface is not technical, it is more about the fact that the right-click context menu was originally introduced only in debug mode (only activated in test builds) in order to inspect the current DOM element. There is a similar UX evolution problem with the system-level menubar (i.e. depending on the operating system, either displayed at the top of the application window(s) or at the top of the screen): this is technically feasible but the user experience (UX) wasn't originally designed with a menubar in mind. |
Uh oh!
There was an error while loading. Please reload this page.
I have added the context menu item for the reader window. There already one
Inspect Elementmenu entry for dev, I want another entry for a production build. What I'm trying to do is I want context menu itemAdd to Bookmarkand in the click, handler passes the IPC call to renderer process to call the add to bookmark action. But the menu itemAdd to bookmarkwon't appear.I' using the latest
developbranch.All reactions