Desktop: Fixes #15100: Fix pasting images from clipboard when no image/* format is reported (#15101)

This commit is contained in:
Laurent Cozic
2026-04-16 11:42:25 +01:00
committed by GitHub
parent 3279ea227a
commit babea9f388
3 changed files with 28 additions and 11 deletions
@@ -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;
}
+1 -1
View File
@@ -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');
},
+1
View File
@@ -262,4 +262,5 @@ bgcolor
bordercolor
togglefullscreen
onestore
macshot
pdate