diff --git a/main/background.ts b/main/background.ts index e2a73e7b73..144154972f 100644 --- a/main/background.ts +++ b/main/background.ts @@ -1,5 +1,5 @@ import path from 'path' -import { app, ipcMain, shell, IpcMainInvokeEvent, BrowserWindow, Menu } from 'electron' +import { app, ipcMain, shell, IpcMainInvokeEvent, BrowserWindow, Menu, clipboard } from 'electron' import serve from 'electron-serve' import { createWindow } from './helpers' import { menu } from './menu' @@ -39,6 +39,76 @@ let main: BrowserWindow = null await mainWindow.loadURL(`http://localhost:${port}/`) mainWindow.webContents.openDevTools() } + + mainWindow.webContents.on('context-menu', (_event, properties) => { + const { editFlags } = properties + const hasText = properties.selectionText.length > 0 + const can = (type: string) => editFlags[`can${type}`] && hasText + const contextMenu = Menu.buildFromTemplate([ + { + label: 'Select All', + click: () => { + mainWindow.webContents.selectAll() + } + }, + { + label: 'Copy', + enabled: can('Copy'), + visible: properties.isEditable || hasText, + click: () => { + const target = mainWindow.webContents + if (target) { + target.copy() + } else { + clipboard.writeText(properties.selectionText) + } + } + }, + { + label: 'Cut', + enabled: can('Cut'), + visible: properties.isEditable || hasText, + click: () => { + const target = mainWindow.webContents + if (target) { + target.cut() + } else { + clipboard.writeText(properties.selectionText) + } + } + }, + { + label: 'Paste', + enabled: editFlags.canPaste, + visible: properties.isEditable, + click: () => { + const target = mainWindow.webContents + if (target) { + target.paste() + } + } + }, + { + label: 'Save Image As', + visible: properties.mediaType === 'image', + click: () => { + console.log(properties.srcURL) + mainWindow.webContents.downloadURL(properties.srcURL) + } + }, + { + label: 'Copy Link', + visible: properties.linkURL.length > 0 && properties.mediaType === 'none', + click: () => { + clipboard.write({ + bookmark: properties.linkText, + text: properties.linkURL + }) + } + } + ]) + contextMenu.popup({ window: mainWindow }) + }) })() app.on('window-all-closed', () => { diff --git a/renderer/components/timelines/FollowRequests.tsx b/renderer/components/timelines/FollowRequests.tsx index eceb86879d..d2bc534423 100644 --- a/renderer/components/timelines/FollowRequests.tsx +++ b/renderer/components/timelines/FollowRequests.tsx @@ -54,17 +54,15 @@ export default function FollowRequests(props: Props) {