Skip to content

Commit

Permalink
implement a contextmenu for saving images in webview
Browse files Browse the repository at this point in the history
  • Loading branch information
sawka committed Oct 4, 2024
1 parent a513072 commit 7c820de
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions emain/preload-webview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,18 @@ document.addEventListener("contextmenu", (event) => {
const targetElement = event.target as HTMLElement;
// Check if the right-click is on an image
if (targetElement.tagName === "IMG") {
const imgElem = targetElement as HTMLImageElement;
const imageUrl = imgElem.src;
ipcRenderer.send("save-image", { src: imageUrl });
setTimeout(() => {
if (event.defaultPrevented) {
return;
}
event.preventDefault();
const imgElem = targetElement as HTMLImageElement;
const imageUrl = imgElem.src;
ipcRenderer.send("webview-image-contextmenu", { src: imageUrl });
}, 50);
return;
}
// do nothing
});

console.log("loaded wave preload-webview.ts");

0 comments on commit 7c820de

Please sign in to comment.