GithubHelp home page GithubHelp logo

kryndex / hazel Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vercel/hazel

0.0 1.0 0.0 86 KB

Lightweight update server for Electron apps

Home Page: https://twitter.com/notquiteleo/status/893547786255421441

License: MIT License

JavaScript 100.00%

hazel's Introduction

Hazel

Build Status XO code style Slack Channel

This project lets you deploy an update server for Electron apps with ease: You only need to run a single command and fill out two text fields.

The result will be faster and more lightweight than any other solution out there! πŸš€

  • Built on top of micro, the tiniest HTTP framework for Node.js
  • Pulls the latest release data from GitHub Releases 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 GitHub asset directly (saves bandwidth)
  • Supports macOS and Windows apps
  • Scales very nicely across multiple Now instances

Usage

With Now CLI, you can deploy an update server like this:

now -e NODE_ENV="production" zeit/hazel

You'll be asked for the value of two environment variables:

  • ACCOUNT: Your username or organisation name on GitHub
  • REPOSITORY: The name of the repository to pull releases from
  • PORT: The port on which Hazel should run

Once it's deployed, 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 feed = `${server}/update/${process.platform}/${app.getVersion()}`

autoUpdater.setFeedURL(feed)

That's it! βœ…

From now on, the auto updater will ask your Hazel deployment for updates!

Options

The following environment variables can be used optionally:

  • INTERVAL: Refreshes the cache every x minutes (restrictions)
  • NODE_ENV: Should always be "production", which ensures that only required dependencies are installed
  • PRE: When defined with a value of 1, only prereleases will be cached

Statistics

Since Hazel routes all the traffic for downloading the actual application files to GitHub Releases, you can use their API to determine the download count for a certain release.

As an example, check out the latest Now Desktop release and search for mac.zip. You'll find a release containing a sub property named download_count with the amount of downloads as its value.

Routes

/

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, 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.

/download

Does the same as / (basically an alias).

/download/: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 /.

/update/:platform/:version

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, it will return the 204 status code. The same happens if the latest release doesn't contain a file for the specified platform.

/update/win32/:version/RELEASES

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).

Contributing

  1. Fork this repository to your own GitHub account and then clone it to your local device
  2. Move into the directory of your clone: cd hazel
  3. Run the development server: npm run dev

Credits

Huge thanks to my (@leo's) friend Andy, who suggested the name "Hazel" (since the auto updater software inside Electron is called "Squirrel") and Matheus for collecting ideas with me.

Author

Leo Lamprecht (@notquiteleo) - β–²ZEIT

hazel's People

Contributors

1000ch avatar bhageena avatar leo avatar safinn avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.