diff --git a/packages/app-desktop/bridge.ts b/packages/app-desktop/bridge.ts index a545ac1b21c..48634e0f713 100644 --- a/packages/app-desktop/bridge.ts +++ b/packages/app-desktop/bridge.ts @@ -1,22 +1,18 @@ import ElectronAppWrapper from './ElectronAppWrapper'; import shim from '@joplin/lib/shim'; import { _, setLocale } from '@joplin/lib/locale'; +import { BrowserWindow, nativeTheme, nativeImage } from 'electron'; const { dirname, toSystemSlashes } = require('@joplin/lib/path-utils'); -const { BrowserWindow, nativeTheme } = require('electron'); interface LastSelectedPath { file: string; directory: string; } -interface LastSelectedPaths { - [key: string]: LastSelectedPath; -} - export class Bridge { private electronWrapper_: ElectronAppWrapper; - private lastSelectedPaths_: LastSelectedPaths; + private lastSelectedPaths_: LastSelectedPath; constructor(electronWrapper: ElectronAppWrapper) { this.electronWrapper_ = electronWrapper; @@ -164,11 +160,11 @@ export class Bridge { if (!options) options = {}; let fileType = 'file'; if (options.properties && options.properties.includes('openDirectory')) fileType = 'directory'; - if (!('defaultPath' in options) && this.lastSelectedPaths_[fileType]) options.defaultPath = this.lastSelectedPaths_[fileType]; + if (!('defaultPath' in options) && (this.lastSelectedPaths_ as any)[fileType]) options.defaultPath = (this.lastSelectedPaths_ as any)[fileType]; if (!('createDirectory' in options)) options.createDirectory = true; const { filePaths } = await dialog.showOpenDialog(this.window(), options); if (filePaths && filePaths.length) { - this.lastSelectedPaths_[fileType] = dirname(filePaths[0]); + (this.lastSelectedPaths_ as any)[fileType] = dirname(filePaths[0]); } return filePaths; } @@ -282,6 +278,10 @@ export class Bridge { app.exit(); } + public createImageFromPath(path: string) { + return nativeImage.createFromPath(path); + } + } let bridge_: Bridge = null; diff --git a/packages/app-desktop/gui/NoteEditor/utils/contextMenu.ts b/packages/app-desktop/gui/NoteEditor/utils/contextMenu.ts index e30f300bb62..b9516a41e5e 100644 --- a/packages/app-desktop/gui/NoteEditor/utils/contextMenu.ts +++ b/packages/app-desktop/gui/NoteEditor/utils/contextMenu.ts @@ -1,8 +1,7 @@ import ResourceEditWatcher from '@joplin/lib/services/ResourceEditWatcher/index'; import { _ } from '@joplin/lib/locale'; import { copyHtmlToClipboard } from './clipboardUtils'; - -const bridge = require('@electron/remote').require('./bridge').default; +import bridge from '../../../services/bridge'; const Menu = bridge().Menu; const MenuItem = bridge().MenuItem; import Resource from '@joplin/lib/models/Resource'; @@ -131,6 +130,15 @@ export function menuItems(dispatch: Function): ContextMenuItems { }, isActive: (itemType: ContextMenuItemType) => itemType === ContextMenuItemType.Image || itemType === ContextMenuItemType.Resource, }, + copyImage: { + label: _('Copy image'), + onAction: async (options: ContextMenuOptions) => { + const { resourcePath } = await resourceInfo(options); + const image = bridge().createImageFromPath(resourcePath); + clipboard.writeImage(image); + }, + isActive: (itemType: ContextMenuItemType) => itemType === ContextMenuItemType.Image, + }, cut: { label: _('Cut'), onAction: async (options: ContextMenuOptions) => {