This project lets you deploy an update server for Electron apps with ease: You only need to run a single command and fill out some text fields.
- Pulls the latest release data from GitHub Releases or Forgejo Releases (probably also works for Gitea instances) and caches it in memory
- Refreshes the cache every 15 minutes (custom interval possible)
- When asked for an update, it returns the link to the asset directly, saves bandwidth (GitHub only, Forgejo doesn't have a way to download assets without a token)
- Supports macOS, Windows, and Linux apps
You can easily deploy an update server. As the first step, clone the repository:
git clone https://github.com/AnimeoTV/hazelNext, move into the directory:
cd hazelInside the directory, copy the .env.EXAMPLE file to .env and fill out the text fields.
Then, to deploy it, run the following command :
npm run start"Once it's deployed, for the built-in electron updater, paste the deployment address into your code (please keep in mind that updates should only occur in the production version of the app, not while developing):
const { app, autoUpdater } = require('electron')
const server = <your-deployment-url>
const url = `${server}/update/${process.platform}/${app.getVersion()}`
autoUpdater.setFeedURL({ url })For the electron-updater module, you can read this page, use "generic" for the provider and "/update/electronUpdater//" for the URL.
From now on, the auto updater will ask your Hazel deployment for updates!
Since Hazel routes all the traffic for downloading the actual application files to either GitHub Releases or Forgejo Releases, you can use their API to determine the download count for a certain release.
We find and cache releases for each platform by the file name and extension. it may be obvious but can save quite some times for those who just getting started.
As you can see in platform.js and aliases.js, for each OS, the extensions are expected as below:
| OS | :platform | .Extension |
|---|---|---|
| Windows | win32, windows, win | .exe |
| macOS | dmg | .dmg |
| macOS | darwin | .zip (only if the file name contains "mac" or "darwin") |
| Linux with RPM package manager | fedora | .rpm |
| Linux with DEB package manager | debian | .deb |
| Linux with PACMAN package manager | debian | .pacman |
| Linux | appimage | .AppImage |
Displays an overview page showing the cached repository with the different available platforms and file sizes. Links to the repo, releases, specific cached version and direct downloads for each platform are present.
Returns an object with the property uptime which is the uptime of the update server in seconds.
Return an object with the property version which is the latest version available.
Automatically detects the platform/OS of the visitor by parsing the user agent and then downloads the appropriate copy of your application.
If the latest version of the application wasn't yet pulled from GitHub Releases or Forgejo Releases, it will return a message and the status code 404. The same happens if the latest release doesn't contain a file for the detected platform.
Accepts a platform (like "darwin" or "win32") to download the appropriate copy your app for. I generally suggest using either process.platform (more) or os.platform() (more) to retrieve this string.
If the cache isn't filled yet or doesn't contain a download link for the specified platform, it will respond like /.
Checks if there is an update available by reading from the cache.
If the latest version of the application wasn't yet pulled from GitHub Releases or Forgejo Releases, it will return the 204 status code. The same happens if the latest release doesn't contain a file for the specified platform.
This endpoint was specifically crafted for the Windows platform (called "win32" in Node.js).
Since the Windows version of Squirrel (the software that powers auto updates inside Electron) requires access to a file named "RELEASES" when checking for updates, this endpoint will respond with a cached version of the file that contains a download link to a .nupkg file (the application update).
This endpoint was specifically crafted for electron-updater, which requires access to a file named "latest.yml" (or "latest-mac.yml", or "latest-linux.yml" depending on the platform). The endpoint will respond with a cached version of the requested file that contains a download link to the application's installer for the corresponding platform.
- Fork this repository to your own GitHub account and then clone it to your local device
- Move into the directory of your clone:
cd hazel - Install the packages with
npm iand run the development server:npm run dev
RASTIQ - electron-updater and Forgejo support
Leo Lamprecht (@leo) - Original version of hazel