mirror of
https://github.com/laurent22/joplin.git
synced 2026-06-18 20:16:34 +02:00
Desktop: Fixes #15100: Fix pasting images from clipboard when no image/* format is reported (#15101)
This commit is contained in:
@@ -90,6 +90,19 @@ export function resourcesStatus(resourceInfos: any) {
|
||||
return joplinRendererUtils.resourceStatusName(lowestIndex);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
||||
const clipboardImageToResource = async (image: any, mime: string) => {
|
||||
const fileExt = mimeUtils.toFileExtension(mime);
|
||||
const filePath = `${Setting.value('tempDir')}/${md5(Date.now())}.${fileExt}`;
|
||||
await shim.writeImageToFile(image, mime, filePath);
|
||||
try {
|
||||
const md = await commandAttachFileToBody('', [filePath]);
|
||||
return md;
|
||||
} finally {
|
||||
await shim.fsDriver().remove(filePath);
|
||||
}
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
||||
export async function getResourcesFromPasteEvent(event: any) {
|
||||
const output = [];
|
||||
@@ -104,19 +117,22 @@ export async function getResourcesFromPasteEvent(event: any) {
|
||||
continue;
|
||||
}
|
||||
if (event) event.preventDefault();
|
||||
|
||||
const image = clipboard.readImage();
|
||||
|
||||
const fileExt = mimeUtils.toFileExtension(format);
|
||||
const filePath = `${Setting.value('tempDir')}/${md5(Date.now())}.${fileExt}`;
|
||||
|
||||
await shim.writeImageToFile(image, format, filePath);
|
||||
const md = await commandAttachFileToBody('', [filePath]);
|
||||
await shim.fsDriver().remove(filePath);
|
||||
|
||||
const md = await clipboardImageToResource(clipboard.readImage(), format);
|
||||
if (md) output.push(md);
|
||||
}
|
||||
}
|
||||
|
||||
// Some applications (e.g. macshot) copy images to the clipboard without
|
||||
// an image/* format, but clipboard.readImage() can still read them.
|
||||
if (!output.length) {
|
||||
const image = clipboard.readImage();
|
||||
if (!image.isEmpty()) {
|
||||
if (event) event.preventDefault();
|
||||
const md = await clipboardImageToResource(image, 'image/png');
|
||||
if (md) output.push(md);
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
@@ -491,7 +491,7 @@ const shim = {
|
||||
},
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
||||
writeImageToFile: (_image: any, _format: any, _filePath: string): void => {
|
||||
writeImageToFile: (_image: any, _format: any, _filePath: string): Promise<void> => {
|
||||
throw new Error('Not implemented');
|
||||
},
|
||||
|
||||
|
||||
@@ -262,4 +262,5 @@ bgcolor
|
||||
bordercolor
|
||||
togglefullscreen
|
||||
onestore
|
||||
macshot
|
||||
pdate
|
||||
Reference in New Issue
Block a user