What To Keep In Mind When Porting an Electron Desktop App to Mac OS Xcalendar_today Posted 7 months ago · 6 minute-read · Technology
Having to develop an application for the operating system you’re currently using or have access to is a blessing, since you can compile and debug your app right then and there. But what happens when your user base is distributed across multiple operating systems?
I’ve recently had to port an Electron desktop app to Mac OS X, an operating system that I’ve hardly ever used before. I do use Linux every now and then to manage VMs, which can be similar to Mac OS X’s terminal in some ways, but I don’t use GUI Linux distributions. What I mean is that I don’t know how regular consumers use these operating systems, and what users expect from apps running on these platforms.
While Electron does allow you to compile your app for other platforms, there’s no way to test it without setting up virtual machines or by having access to the operating system in question. I believe that virtual machines aren’t ideal for testing GUI applications because it’s just not the real thing. VMs are usually stripped from any form of GPU processing, which makes many apps unrunnable. Also, depending on the OS you’re trying to virtualize, performance is usually subpar, which make apps sluggish.
In order to provide an optimal user experience, you need to get as close to retail as possible. There are a few ways of doing this:
- Using special software that runs OSes in a native manner (for example, Apple’s BootCamp). This software allows for a high performance desktop experience that is very close to the real thing. Some PCs are able to be turned into a Hackintosh, running Mac OS X natively.
- Renting a VM in the cloud that is made for testing applications. Most VMs for sale are made for running application servers, but not for testing applications as regular users. There are however some providers that focus on bringing a virtualized desktop experience that is made for testing apps. For example, MacInCloud provides real Mac hardware with a GPU and the latest Mac OS X versions, accessible from remote control software like VNC.
- Buying real hardware. Obviously, if you buy the real thing, you’ll be able to test your app just like regular users would. This is the best option in terms of performance and quality, but not so much for cost. For example, if you need Mac hardware, be ready to shell out a good amount of cash for it.
So, what did I do in my situation?
- Need to port from an Electron app from Windows to Mac OS X.
- Can’t afford to buy Mac hardware.
- Hackintosh is not possible with my PC.
With these 3 constraints, and after having tried local virtual machines running Mac OS X (even though it is illegal to do so) with really poor performance, I had to decide to go with renting a VM in the cloud. Luckily, for Mac systems there’s MacInCloud available.
This post is not sponsored, but I have to say that the service they offer is pretty great. I’ve used it extensively for the past few weeks. I rented a Dedicated Server from them which turned out to be about 40 EUR a month, which is more than enough time for me to port and test the app (you can order for 1 week as well, if you think 1 month is too much time).
If you end up using MacInCloud, make sure you do not choose the Remote Desktop addon. It just allows you to remote desktop into the VM from your Windows PC, however, you already get VNC remote desktop for free. Performance is not great with VNC, but after your first login you can install TeamViewer which works much better.
MacInCloud was the solution to my problem in terms of having an accurate and performant Mac OS X environment, but I still need to develop the app and test it. After spending days getting used to the Mac ecosystem and developing the app using Visual Studio Code, I have a few cross-platform Electron tips to share with you:
Tips for Electron Apps on Mac OS X
- Directory separators should always be /, since this is supported on Windows and Linux. If possible, never use \.
- By using
electron-installer-dmg, you can create a DMG file for users to install your app easily. Here’s an example of a command to build one:
electron-packager . <AppName> --icon=./AppIcon.icns --platform=darwin --arch=all --overwrite --electron-version=8.2.0 --version-string.FileDescription='<AppDescription>' --out . && electron-installer-dmg ./<AppName>-darwin-x64/<AppName>.app <AppName> --out=. --icon=./AppIcon.icns --background=./DMG_Background.png --title=<AppName> --overwrite
- Electron temporary files are written to ~/Library/Application Support/<AppName> and this directory is created when your app is first run. You’ll also want to write any application-specific files here.
- There’s no concept of Registry in Mac OS X. If your application relies on Registry values in order to function, you’ll need to change this. You can use configuration files that should be created and stored in ~/Library/Application Support/<AppName> in order to achieve the same functionality.
- If your app need to run commands as sudo, there’s a very useful node package named sudo-prompt which prompts the user to allow the app to run a certain command. This is good UX, your app should never run as sudo from the beginning, it should ask for permission right when it needs it.
- Apps don’t need to be published or verified by Apple to run on Mac OS X. At first I thought that I would have a hard time trying to run my application since I have no way of signing it and wasn’t interested in uploading it to the App Store. This turned out not to be an issue: you can distribute your app as a DMG and your users will have no issues installing your application. In fact, you’ll have less problems than on Windows because of the SmartScreen window.
- You can be assured that your app will provide a consistent experience across Mac OS X versions. What I’ve observed is that Mac OS X is great at providing consistency across versions. This has made me confident in that my app will run the same way for every user. Unlike Windows, which has software that can interfere with the normal functioning of the app, such as antiviruses or firewalls, Mac OS X normally doesn’t have any of that.
Those are my tips for developing cross-platform Electron apps for Mac OS X. For the most part, Electron should abstract away anything platform-specific and make the development experience much easier for you, but there’s still a few things you should know about the differences between platforms.
Thanks for reading!