Bringing a react web app to the desktop with Electron, Tauri and OpenFin
September 29, 2024
With the growing demand for more native-like web applications, companies are looking to desktop web container solutions like Electron, Tauri and OpenFin to evolve beyond the browser. Bringing a react web app to the desktop opens up possibilities like improving performance, integrating with native notifications, window management and an overall more flexible experience for apps with advanced user interfaces.
The potential here is exciting because it allows businesses to leverage their existing web assets, tech stacks and developer expertise to deliver an experience that feels more powerful and responsive on the desktop.
In this article, I will walk through bringing a web app to the desktop using frameworks such as Progressive Web App, OpenFin, Electron and Tauri. I will also use progressive enhancement techniques to enable a the basic experience when viewing the app in a browser and then detect when running in a desktop container for a more immersive experience on the desktop.
Setting the Target
For comparison, I'll be targeting desktop web app parity with one of my existing native desktop apps, Desktop MP3. The goal is to have the web desktop version achieve as much parity with the native desktop version as possible.
The existing native app supports functionality unique to desktops such as: installing an app icon, browsing for a local folder of music, maintaining a reference to the local folder across sessions, and even advanced windowing techniques including transparent native window regions and hiding the native window's titlebar.
Starting With a Web App
For the starting point of bringing a web app to the desktop, I have created a web-based version of the app using React with Redux. In the next steps, I will start with the web-based version as I walk through the steps of bringing it into parity with the native desktop version.
Web app running in a browser tab |
How does the baseline version of the web app compare to the native app?
Desktop icon: By dragging the website icon to the desktop, we can launch the web app from the desktop later on. However, as seen in the screenshot above, the app icon uses a system icon instead of the one provided by the web app.
Opening a local folder: In order for a web app to open a folder from the local desktop, we can use FileSystem API. However, the browser shows a security prompt when selecting the local folder.
Browser showing security prompt when choosing a local folder |
Maintaining reference to local folder: The FileSystem API does not allow for saving a reference to a local folder across sessions. So the next time the user closes and reopens the browser to the web app, the user will need to browse for the folder and accept the security prompt again.
Browser preventing window from going smaller than 500x300 pixels |
Native transparent window regions: Browsers do not support native desktop transparent regions. As a tradeoff, we can used a gradient background to start with and employ progressive enhancement techniques to switch to a transparent background when the app detects it is running in a desktop container which supports it.
Hiding the native window titlebar: Browsers do not support hiding the native window titlebar.
Using a Progressive Web App (PWA)
By setting up the proper configuration to run the web app as a Progressive Web App, we can get a step closer to a native desktop experience.
Desktop Icon: When installing a PWA, the browser provides an app icon that can be added to the desktop. Unlike the regular browser shortcut, this desktop icon actually uses the icon from the web app.
Opening a local folder: In order for a progressive web app to open a folder from the local desktop, we can use the same FileSystem API as a regular webapp. However, since the app is still technically running in a browser window, the browser still shows a security prompt when selecting the local folder.
PWA showing browser security prompt when selecting a local folder |
Maintaining reference to local folder: The FileSystem API does not allow for saving a reference to a local folder across sessions. So the next time the user closes and reopens the browser to the web app, the user will need to browse for the folder again. However, unlike a regular web app which shows the security prompt for each session, the PWA only shows the prompt on the first session -- unless the user chooses a different local folder in a new session.
Extra-small native window dimensions: Just like the regular browser window, the PWA window won't go as small as desired, leaving extra unintended padding.
PWA preventing window from going smaller than 500x300 pixels |
Native transparent window regions: Since the PWA is running in a browser window, it still cannot support native desktop transparent regions, so for this version we are still using a gradient background to start with and employing progressive enhancement techniques to switch to a transparent background when the app detects it is running in a desktop container which supports it.
Hiding the native window titlebar: Browsers do not support hiding the native window's titlebar. However, as a tradeoff for this version, we can set the titlebar color match the look-and-feel of the rest of the app by adding an entry to the PWA manifest file.
PWA using a custom titlebar color to match the background of the app |
Using OpenFin
OpenFin installer page |
If the user has OpenFin already installed, visiting the special link shows browser prompt to launch the web app on the desktop. Users can check the box to always allow it and avoid future prompts.
Using Electron
Filesize of Electron app |
Using Tauri
Alternatives
FinSemble
WebUI
Did we achieve parity with native app?
Screenshots
Screenshots comparing web app, desktop web apps, and native |
Related post: Cross-platform desktop app filesize comparison