Add experimental electron support#152
Merged
gabrieldonadel merged 17 commits intomainfrom Jan 31, 2024
Merged
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
We want to expand Orbit's support for more platforms, focusing primarily on Windows given that it is the platform that most users use to access the Expo website.
Options:
1. react-native-windows
The first choice that comes to mind is react-native-windows, considering that we have already implemented everything using react-native-macos and we know the strength of react native when it comes to shipping an app that feels native.
We did some proof of concepts using react-native-windows, but in its current form, a standard react-native-windows app has too many limitations for our use case.
By default, react-native-windows generates Universal Windows Platform (UWP) apps which have quite a few limitations regarding accessing specific Windows APIs as they run as sandbox apps, which would be a problem for Orbit.
Orbit needs to perform tasks that are only supported by the Win32 ecosystem such as: working with any file on the disk without user intervention, reading keys from the registry, and using the system tray API. The
react-native-windows initcommand used to support a flag to target WinUI 3 (through the Windows App SDK instead of UWP XAML) but this flag was deprecated in favor of ongoing Fabric implementation for react-native-windows and no longer works.Although win32 applications will be the default for Fabric, unfortunately it is still a ways off from being complete enough for most apps. Considering this, plus the fact that at this point in time, there isn't an official template for creating a win32 application, react-native-windows wouldn't really fit our needs.
2. electron
The second obvious option would be using electron, as it has gained widespread adoption in the software industry as "the" framework for building cross-platform desktop applications, and a lot of big desktop apps like Slack, Visual Studio Code, Linear and Discord use it.
Taking into account the fact that Expo already has great support for web, with electron we can just export Orbit using react-native-web and load it using electron, this would not only add support for Windows but also for Linux ("for free")
Electron comes with full support for things such as the tray API and as it essentially runs a nodejs process we can directly invoke the CLI without having to rely on pkg to create a single executable application.
Given all these facts it was opted to use electron.
How
This PR is the first of a series of PRs adding support for electron and it implements the most basic functionalities to get orbit running, which includes:
electronfolder under menu-barnpm init electron-app@latest my-app -- --template=vite-typescriptto set up the basic templatereact-native-electron-modulespackageregisterMainModulesandexposeElectronModulesTest Plan
npx expo startapps/menu-bar/electronand runyarn startOn Windows:
And we can also use macOS for debugging: