I try to develop add-ons to use the webcam in Anki for desktop.
It is already working fine on Windows and Linux, but on Mac I cannot display the screen or encounter crashes. Like this:
I’ve looked into the cause, it looks like Macs are security-conscious and apps need to be set up with camera permissions in advance, and Anki probably doesn’t allow this. (But I have not built Anki so I do not know if this is the exact cause or not).
For now a workaround is to start Anki from the terminal. The user can give permission for the camera to the terminal and the add-on will work fine.
If so, this change does not seem to be possible with add-on. Are there any plans to allow the use of the camera in Anki for Mac?
This is a minimal add-on for reproducing the problem. Use Qt5 or Qt6 to display the webcam video. If a crash occurs, you need to press Shift to restart Anki and disable the add-on:
As a heads up: I tested your addon in debian linux (oldstable) with gnome and anki doesn’t even ask for camera permission here. Your addon thus doesn’t work for me, I only get a blank white screen.
I tested it on Ubuntu 24 and it was giving me the same problem as the guy above, with the white screen, but I remembered that I installed Anki with Flatpak there
so I had to use these 2 commands in the terminal to make it work on Linux Ubuntu
sudo flatpak override net.ankiweb.Anki --device=all
flatpak install flathub com.github.tchx84.Flatseal
Thanks! That’s very helpful. I’m a little concerned about security if the user allows everything, so it looks like it would be good to have a code to allow only the camera and a code to revoke the permission. I’ll look into it later.
When I typed this into the terminal and started Anki, a popup automatically appeared asking if I wanted to allow the camera. /Applications/Anki.app/Contents/MacOS/anki
After that privacy & security will show that I have allowed the terminal. Until the popup is shown, nothing is displayed in privacy & security.
This only worked on my debugging device, so it has not been tested to work on other Mac devices.
Thanks for testing!
Would it be possible to add that change as is to the plist and have it included in the next Anki for desktop? If there is something wrong with the current test add-on code or camera connection setting, it may work fine if I fix the add-on code.
I tried the camera in pre-release Anki25.01 and the error message says that “com.apple.security.device.camera” is needed for camera permissions.
The “com.apple.security.device.audio-input” for the microphone is already written in “anki/qt/bundle/mac/entitlements.python.xml”, so I think it might be needed to be set in this file (I don’t develop on a Mac so I don’t know if this is accurate or not), like this:
Thanks for commit and testing! I think basically the camera permission is the same as the microphone so that is an odd problem. I may need to build Anki on Mac and look into it.
I tried the new pre-release Anki25.01 and successfully working on my device with the improved test camera add-on. Thanks for the quick update!
It seems I was missing the code to ask permission for the camera with Qt6. (Qt5 and other camera modules do not need such code.)
I tested it on the Intel version so I’m not sure if it works with Apple Sillicon.
Both “NSCameraUsageDescription” and “com.apple.security.device.camera” seem to be required.
If I build Anki myself the entitlements.python.xml will not run because there is no code sign, so it seems possible to debug this only by developers who are developing apps with Apple (paid Registration).