Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MM-60232] Fix a crash in Linux when trying to create a thumbnail from an image #3147

Merged
merged 4 commits into from
Sep 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/main/downloadsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,15 @@ export class DownloadsManager extends JsonFileManager<DownloadedItems> {

let thumbnailData;
if (state === 'completed' && item.getMimeType().toLowerCase().startsWith('image/')) {
thumbnailData = (await nativeImage.createThumbnailFromPath(overridePath ?? item.getSavePath(), {height: 32, width: 32})).toDataURL();
// Linux doesn't support the thumbnail creation so we have to use the base function
if (process.platform === 'linux') {
// We also will cap this at 1MB so as to not inflate the memory usage of the downloads dropdown
if (item.getReceivedBytes() < 1000000) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please clarify

to not inflate the memory usage of the downloads

Does it mean if image size is greater than 1mb we wont show the preview in the download dropdown

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. This is a bit of pre-emptive safety, but I did notice that if you do have a really large image stored in the JSON (like I had before) it will slow down the app significantly, so I want to avoid that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is for images only dont we have access to preview url of the image?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not anymore, we can't use the file:/// protocol which would facilitate that. And we don't want to open up mattermost-desktop: to arbitrary files, or else security becomes a concern.

I'd be up for trying to figure out a better solution in the future, but this works for now.

thumbnailData = (await nativeImage.createFromPath(overridePath ?? item.getSavePath())).toDataURL();
}
} else {
thumbnailData = (await nativeImage.createThumbnailFromPath(overridePath ?? item.getSavePath(), {height: 32, width: 32})).toDataURL();
}
}

return {
Expand Down
Loading