Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webview: Context Menu: Copy link and *URLs (#110) #372

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions app/frontend/Shared/ContextMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ export function saveVideoAs(context: ContextInfo, win: any) {
download(context.srcURL, win, true);
}

export function copyLink(context: ContextInfo, win: any) {
copyToClipboard(context.linkURL);
export async function copyLink(context: ContextInfo, win: any) {
await copyToClipboard(context.linkURL);
/* or:
copyToClipboard({
bookmark: context.linkText,
Expand All @@ -242,12 +242,12 @@ export async function copyImage(context: ContextInfo, win: any) {
win.copyImageAt(context.x, context.y);
}

export function copyImageURL(context: ContextInfo, win: any) {
copyToClipboard(context.srcURL);
export async function copyImageURL(context: ContextInfo, win: any) {
await copyToClipboard(context.srcURL);
}

export function copyVideoURL(context: ContextInfo, win: any) {
copyToClipboard(context.srcURL);
export async function copyVideoURL(context: ContextInfo, win: any) {
await copyToClipboard(context.srcURL);
}

export function learnSpelling(context: ContextInfo, win: any) {
Expand All @@ -261,9 +261,9 @@ export function inspect(context: ContextInfo, win: any) {
}
}

export function copyToClipboard(text: string | Object) {
export async function copyToClipboard(text: string | Object) {
if (typeof (text) == "string") {
navigator.clipboard.writeText(text);
await appGlobal.remoteApp.writeTextToClipboard(text);
} else {
throw new NotImplemented();
}
Expand Down
12 changes: 11 additions & 1 deletion backend/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ImapFlow } from 'imapflow';
import { Database } from "@radically-straightforward/sqlite"; // formerly @leafac/sqlite
import Zip from "adm-zip";
import ky from 'ky';
import { shell, nativeTheme, Notification, Tray, nativeImage, app, BrowserWindow, webContents, Menu, MenuItemConstructorOptions } from "electron";
import { shell, nativeTheme, Notification, Tray, nativeImage, app, BrowserWindow, webContents, Menu, MenuItemConstructorOptions, clipboard } from "electron";
import nodemailer from 'nodemailer';
import MailComposer from 'nodemailer/lib/mail-composer';
import { createType1Message, decodeType2Message, createType3Message } from "./ntlm";
Expand Down Expand Up @@ -47,6 +47,7 @@ async function createSharedAppObject() {
unminimizeMainWindow,
addEventListenerWebContents,
getWebContents,
writeTextToClipboard,
shell,
restartApp,
setTheme,
Expand Down Expand Up @@ -349,6 +350,15 @@ function getWebContents(webContentsID: number) {
return new WebContents(win);
}

/**
* Writes to system clipboard
* Don't expose reading the clipboard because the user may have sensitive data
* on their system clipboard e.g. passwords
*/
function writeTextToClipboard(text: string) {
clipboard.writeText(text);
}

function setBadgeCount(count: number) {
app.setBadgeCount(count);
}
Expand Down