Fixing the Mojave Crash for the Clementine Music Player

Clementine, based off Amarok 1.4 has been one of my favorite music players because of it’s cross platform support, it’s wide format support and it’s clean and easy to use interface. Back when I was in high school I would constantly swap between a Mac and PC and Clementine made it very easy to keep a consistent experience between my computers.

Enter Mojave

While I haven’t owned a Mac for a few years I’ve always loved MacOS and Linux environments for development and I’ve used virtual machines of the two OS (well an Ubuntu image for Linux) to develop just so I can test for all 3 major operating systems. MacOS virtualization isn’t always spot on so after I first created my VM I ran a few basic tests to see what capabilities I had, one of which was sound. To test my sound capabilities I decided to use Clementine to play a FLAC file but sure enough it crashes right after it launched.

Now when Mojave was announced I remembered the hype around the security updates so I thought that a security change was the cause of the crash but I wasn’t sure. However I did remember that previously Clementine would ask me to give it Accessibility permissions to access the media keys so I went into my Security and Privacy panel and allowed Accessibility access to Clementine. Sure enough this fixed the issue, but this leads to the question: Why did the Accessibility prompt not show up and why did Clementine crash without the permission?

I found an issue on Clementine’s Github (issue 6148) which described my exact issue. There a maintainer of the project gave a few code pointers to the code that handled the accessibility prompt.

Before continuing I would like to preface the following by saying this was the first time I touched code for MacOS so this was an entirely new learning experience for me. As I haven’t dealt with Apple’s documentation or APIs before.

During my research I found that the code Clementine used(AXAPIEnabled) was depreciated back when OSX 10.9 (or Mavricks) was released. After looking for how AXAPIEnabled() was replaced I found that AXIsProcessTrustedWithOptions() could be used instead. By looking at the documentation for AXIsProcessTrustedWithOptions() and going to it’s parent header page I found that I had to include the header <ApplicationServices/ApplicationServices.h> to use the function resulting in the following changes.

To test my code I had to build the Clementine dmg file. I did this by following the instructions on the Clementine wiki.

The process involved pulling the Clementine OSX image with docker pull clementine/mac:1.3

SSH-ing into the container using docker run -it clementine/mac:1.3 /bin/bash then following the commands on the Clementine wiki except I pulled my changes into the image. After following this process I was left with an executable dmg which contained the Clementine application.

After running the application I could confirm that there was no crash and when I checked the keyboard controls there was an option to open the System Preferences.

Seeing this, I was confident my fix worked. Unfortunately media keys still does not work in Mojave however that’s another bug. For now, this patch fixes the crash that occurs in Mojave if the Accessibility control was not enabled.