-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enable context menu for the browser window #11
- Loading branch information
Showing
5 changed files
with
104 additions
and
94 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "protonmail-desktop-app", | ||
"description": "Unofficial ProtonMail Desktop App", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"author": "Vladimir Yakovlev <[email protected]>", | ||
"license": "MIT", | ||
"homepage": "https://github.com/vladimiry/protonmail-desktop-app", | ||
|
@@ -80,7 +80,6 @@ | |
"jimp": "0.2.28", | ||
"keepasshttp-client": "2.2.5", | ||
"keytar": "4.1.0", | ||
"otpauth": "3.1.3", | ||
"rxjs": "5.5.6", | ||
"stacktrace-js": "2.0.0", | ||
"valid-url": "1.0.9" | ||
|
@@ -105,7 +104,7 @@ | |
"@ngtools/webpack": "1.9.7", | ||
"@types/keytar": "4.0.1", | ||
"@types/mkdirp": "0.5.2", | ||
"@types/node": "9.4.0", | ||
"@types/node": "9.4.1", | ||
"@types/randomstring": "1.1.6", | ||
"@types/sinon": "4.1.3", | ||
"@types/stacktrace-js": "0.0.32", | ||
|
@@ -127,7 +126,7 @@ | |
"css-loader": "0.28.9", | ||
"cssnano": "3.10.0", | ||
"devtron": "1.4.0", | ||
"electron": "1.8.2-beta.5", | ||
"electron": "1.8.2", | ||
"electron-builder": "19.56.0", | ||
"electron-builder-squirrel-windows": "20.0.1", | ||
"electron-rebuild": "1.7.3", | ||
|
@@ -145,6 +144,7 @@ | |
"ngx-bootstrap": "2.0.2", | ||
"node-sass": "4.7.2", | ||
"npm-run-all": "4.1.2", | ||
"otpauth": "3.1.3", | ||
"postcss-custom-properties": "6.2.0", | ||
"postcss-loader": "2.1.0", | ||
"postcss-url": "7.3.0", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,58 @@ | ||
import {app, clipboard, Menu} from "electron"; | ||
|
||
import {UIContext} from "./model"; | ||
|
||
export function initWebContentContextMenu(uiContext: UIContext) { | ||
app.on("web-contents-created", (webContentsCreatedEvent, contents) => { | ||
const selectionMenu = Menu.buildFromTemplate([ | ||
{role: "copy"}, | ||
{type: "separator"}, | ||
{role: "selectall"}, | ||
]); | ||
const inputMenu = Menu.buildFromTemplate([ | ||
{role: "undo"}, | ||
{role: "redo"}, | ||
{type: "separator"}, | ||
{role: "cut"}, | ||
{role: "copy"}, | ||
{role: "paste"}, | ||
{type: "separator"}, | ||
{role: "selectall"}, | ||
]); | ||
|
||
contents.on("context-menu", (e, props) => { | ||
const {selectionText, isEditable, linkURL} = props; | ||
|
||
if (isEditable) { | ||
inputMenu.popup(uiContext.browserWindow); | ||
return; | ||
} | ||
|
||
if (linkURL) { | ||
Menu | ||
.buildFromTemplate([{ | ||
label: "Copy Link Address", | ||
click() { | ||
clipboard.writeText(linkURL); | ||
}, | ||
}]) | ||
.popup(uiContext.browserWindow); | ||
return; | ||
} | ||
|
||
if (selectionText && selectionText.trim()) { | ||
selectionMenu.popup(uiContext.browserWindow); | ||
} | ||
}); | ||
import {app, clipboard, ContextMenuParams, Event, Menu} from "electron"; | ||
|
||
import {Context} from "./model"; | ||
|
||
const selectionMenu = Menu.buildFromTemplate([ | ||
{role: "copy"}, | ||
{type: "separator"}, | ||
{role: "selectall"}, | ||
]); | ||
const inputMenu = Menu.buildFromTemplate([ | ||
{role: "undo"}, | ||
{role: "redo"}, | ||
{type: "separator"}, | ||
{role: "cut"}, | ||
{role: "copy"}, | ||
{role: "paste"}, | ||
{type: "separator"}, | ||
{role: "selectall"}, | ||
]); | ||
|
||
export function initWebContentContextMenu(ctx: Context) { | ||
const contextMenuEvenHandler = (e: Event, props: ContextMenuParams) => { | ||
const {selectionText, isEditable, linkURL} = props; | ||
const browserWindow = ctx.uiContext && ctx.uiContext.browserWindow; | ||
|
||
if (!browserWindow) { | ||
return; | ||
} | ||
|
||
if (isEditable) { | ||
inputMenu.popup(browserWindow); | ||
return; | ||
} | ||
|
||
if (linkURL) { | ||
Menu | ||
.buildFromTemplate([{ | ||
label: "Copy Link Address", | ||
click() { | ||
clipboard.writeText(linkURL); | ||
}, | ||
}]) | ||
.popup(browserWindow); | ||
return; | ||
} | ||
|
||
if (selectionText && selectionText.trim()) { | ||
selectionMenu.popup(browserWindow); | ||
} | ||
}; | ||
|
||
app.on("browser-window-created", (event, {webContents}) => { | ||
webContents.on("context-menu", contextMenuEvenHandler); | ||
}); | ||
app.on("web-contents-created", (webContentsCreatedEvent, webContents) => { | ||
webContents.on("context-menu", contextMenuEvenHandler); | ||
}); | ||
} |