Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New guide for implementing updates #10251

Merged
merged 21 commits into from Aug 21, 2017
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 6 additions & 28 deletions docs/api/auto-updater.md
Expand Up @@ -4,24 +4,15 @@

Process: [Main](../glossary.md#main-process)

The `autoUpdater` module provides an interface for the
[Squirrel](https://github.com/Squirrel) framework.
**You can find a detailed guide about how to implement updates into your application [here](../tutorial/updates.md).**

You can quickly launch a multi-platform release server for distributing your
application by using one of these projects:
## Platform Notices

- [nuts][nuts]: *A smart release server for your applications, using GitHub as a backend. Auto-updates with Squirrel (Mac & Windows)*
- [electron-release-server][electron-release-server]: *A fully featured,
self-hosted release server for electron applications, compatible with
auto-updater*
- [squirrel-updates-server][squirrel-updates-server]: *A simple node.js server
for Squirrel.Mac and Squirrel.Windows which uses GitHub releases*
- [squirrel-release-server][squirrel-release-server]: *A simple PHP application for Squirrel.Windows which reads updates from a folder. Supports delta updates.*
Currently, only macOS and Windows are supported. There is no built-in support
for auto-updater on Linux, so it is recommended to use the
distribution's package manager to update your app.

## Platform notices

Though `autoUpdater` provides a uniform API for different platforms, there are
still some subtle differences on each platform.
In addition, there are some subtle differences on each platform:

### macOS

Expand Down Expand Up @@ -50,15 +41,6 @@ The installer generated with Squirrel will create a shortcut icon with an
same ID for your app with `app.setAppUserModelId` API, otherwise Windows will
not be able to pin your app properly in task bar.

Unlike Squirrel.Mac, Windows can host updates on S3 or any other static file host.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leo why did this section on Windows and Linux get removed?

Copy link
Contributor Author

@leo leo Aug 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it wasn't necessary, but now - after thinking about it a bit more - I brought it back just to be sure that we're all on the same page: 3405596 and 78f11df

You can read the documents of [Squirrel.Windows][squirrel-windows] to get more details
about how Squirrel.Windows works.

### Linux

There is no built-in support for auto-updater on Linux, so it is recommended to
use the distribution's package manager to update your app.

## Events

The `autoUpdater` object emits the following events:
Expand Down Expand Up @@ -134,7 +116,3 @@ from the normal quit event sequence.
[installer-lib]: https://github.com/electron/windows-installer
[electron-forge-lib]: https://github.com/electron-userland/electron-forge
[app-user-model-id]: https://msdn.microsoft.com/en-us/library/windows/desktop/dd378459(v=vs.85).aspx
[electron-release-server]: https://github.com/ArekSredzki/electron-release-server
[squirrel-updates-server]: https://github.com/Aluxian/squirrel-updates-server
[nuts]: https://github.com/GitbookIO/nuts
[squirrel-release-server]: https://github.com/Arcath/squirrel-release-server
44 changes: 44 additions & 0 deletions docs/tutorial/updates.md
@@ -0,0 +1,44 @@
# Updating Applications

There are several ways to update an Electron application. The easiest and officially supported one is taking advantage of the built-in [Squirrel](https://github.com/Squirrel) framework and the [autoUpdater](../api/auto-updater.md) module that comes with it.

## Deploying an Update Server

To get started, you firstly need to deploy an update server (that's where the [autoUpdater](../api/auto-updater.md) module will download new updates from).

Depending on your needs, you can choose from one of these:

- [Hazel](https://github.com/zeit/hazel) – Pulls new releases from [GitHub Releases](https://help.github.com/articles/creating-releases/) and is **perfect for getting started**
- [Nuts](https://github.com/GitbookIO/nuts) – Also uses [GitHub Releases](https://help.github.com/articles/creating-releases/), but caches app updates on disk
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but caches app updates on disk, therefore allowing use of private GitHub repositories

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 837a34c

- [electron-release-server](https://github.com/ArekSredzki/electron-release-server) – Provides you with a dashboard for handling releases

## Implementing Updates into Your App

Once you've deployed your update server, continue with importing the required modules in your code (the following code might vary for different server software, but it works like described when using [Hazel](https://github.com/zeit/hazel)).

**Important:** Please ensure that the code below will only be executed in production - you can use [electron-is-dev](https://github.com/sindresorhus/electron-is-dev) to check for the environment).

```js
const { app, autoUpdater } = require('electron')
```

Next, put together the URL of the update server:

```js
const server = <your-deployment-url>
const feed = `${server}/update/${process.platform}/${app.getVersion()}`
```

As the final step, tell [autoUpdater](../api/auto-updater.md) where to ask for updates:

```js
autoUpdater.setFeedURL(feed)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add autoUpdater.checkForUpdates() here as well or people might think it does the checking automagically

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea as well! 👍 235ae09

```

That's all. Once [built](../tutorial/application-distribution.md), your application will receive an update for each new [GitHub Release](https://help.github.com/articles/creating-releases/) that you create.

## Further Steps

Now that you've configured the basic update mechanism for your application, you need to ensure that the user will get notified when there's an update (this can be achieved using [events](../api/auto-updater.md#events)).

Also make sure that potential errors are [being handled](../api/auto-updater.md#event-error).