From 057572e847e27c569aa453b7237f2f0a8cb7e76b Mon Sep 17 00:00:00 2001 From: Devin Binnie <52460000+devinbinnie@users.noreply.github.com> Date: Tue, 26 Nov 2024 08:11:57 -0500 Subject: [PATCH] [MM-61919] Wrap potential crash in try/catch for thumbnails, fall back to `createFromPath` (#3224) * [MM-61919] Wrap potential crash in try/catch for thumbnails, fall back to `createFromPath` * Fix lint --- src/main/downloadsManager.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/downloadsManager.ts b/src/main/downloadsManager.ts index eb81ca9b..5bfcafbe 100644 --- a/src/main/downloadsManager.ts +++ b/src/main/downloadsManager.ts @@ -630,14 +630,23 @@ export class DownloadsManager extends JsonFileManager { let thumbnailData; if (state === 'completed' && item.getMimeType().toLowerCase().startsWith('image/')) { - // Linux doesn't support the thumbnail creation so we have to use the base function - if (process.platform === 'linux') { + const fallback = async () => { // We also will cap this at 1MB so as to not inflate the memory usage of the downloads dropdown if (item.getReceivedBytes() < 1000000) { thumbnailData = (await nativeImage.createFromPath(overridePath ?? item.getSavePath())).toDataURL(); } + }; + + // Linux doesn't support the thumbnail creation so we have to use the base function + if (process.platform === 'linux') { + await fallback(); } else { - thumbnailData = (await nativeImage.createThumbnailFromPath(overridePath ?? item.getSavePath(), {height: 32, width: 32})).toDataURL(); + // This has been known to fail on Windows, see: https://github.com/mattermost/desktop/issues/3140 + try { + thumbnailData = (await nativeImage.createThumbnailFromPath(overridePath ?? item.getSavePath(), {height: 32, width: 32})).toDataURL(); + } catch { + await fallback(); + } } }