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

Fix the known issue of saving JPEG to clipboard on macOS #3724

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Ariandr
Copy link

@Ariandr Ariandr commented Sep 15, 2024

I fixed the known issue while setting useJpgForClipboard=true on macOS.

I wrote specific macOS function for this case and re-introduced this setting to GUI.

The code is tested and I run the app on my Mac.

The initial issue is here with more context: #3722

For the quick test, you can use the built app with the fix: #3722 (comment)

Results:
The same screenshot in a .png is 7.6 MB in size, in a .jpeg it's a 850 KB with 90 compression quality.

@Ariandr
Copy link
Author

Ariandr commented Sep 15, 2024

Hi @mmahmoudian
I think it's an important one for all macOS users of Flameshot.

@mmahmoudian
Copy link
Member

@Ariandr thanks for the PR. I'm not quite sold on the idea of using Apple Script to handle this, but perhaps that stems from my lack of familiarity with osascript. Is this a common practice inApple world?

I would rather wait for a dev that knows Apple ecosystem more to decide on this. Regardless of this, the code looks clean to me.

Thanks again for your valuable contribution and the time you have invested in this. I hope this get merged fast if there is mo objections shit the osascript.

@Ariandr
Copy link
Author

Ariandr commented Sep 15, 2024

@mmahmoudian
I can say this:
osascript is safe to use and available on all macOS systems.

It is also built into the OS, so it does not require any special dependencies or installations on the user machine.

Actually, it's a preferred way, because in case the user needs to provide the permission to write to the clipboard, macOS will ask it, because it's Apple's supported tool, while other libraries/ways might not do it.

Apple's Automator Mac app is built on using osascript.

@Ariandr
Copy link
Author

Ariandr commented Sep 15, 2024

Also, while looking for this solution, I've tried some other ways. They (e.g. Qt Clipboard Management) just cannot achieve the same result of saving the compressed JPEG to clipboard. osascript is the only one working.

The only alternative that potentially can work is adding Objective-C runtime and Objective-C files to use NSPasteboard, but I couldn't configure the project correctly for this. I think for such a small task (though an important feature), connecting Objective-C runtime might be an overkill.

@Ariandr
Copy link
Author

Ariandr commented Sep 15, 2024

In any case, until a better approach is found (we can leave a comment to investigate alternatives later or investigation welcome), I think it's good enough. The main thing is that it's reliable and doesn't break anything. By default, all macOS users will have it disabled anyway, since the PNG is the default way of saving to clipboard.

I'm using the app today extensively, the fix works like a charm.

@Ariandr
Copy link
Author

Ariandr commented Sep 15, 2024

Another issue was that my memory usage of Flameshot used to grow fast. In a day of extensive use, it could get to 1-2 GB in memory for whatever reason, while I was taking screenshots and copied them to clipboard as PNGs. So I always killed the app and relaunched it.

With this fix, the positive side effect is that the memory footprint stays the same under 100 MB (actually around 20 MB), apparently it's more efficient than saving PNG to clipboard via QClipboard (probably something doesn't get cleaned up there or because it was run through Rosetta Intel version, now it's arm64 Apple version).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants