Skip to content

Commit

Permalink
feat: add support for static storage provided updates (electron#105)
Browse files Browse the repository at this point in the history
* feat: add support for static storage provided updates

BREAKING CHANGE: This module now exports a named function `updateElectronApp`

* chore: update per feedback

* build: run tsc during prepare

* build: fix readme lint

* fix: capture logger before usage

* oops

* simplify

* stuff

* mock electron
  • Loading branch information
MarshallOfSound authored Oct 22, 2023
1 parent e100aaf commit 107661d
Show file tree
Hide file tree
Showing 13 changed files with 786 additions and 248 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.npmrc
coverage
node_modules
dist
7 changes: 7 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"trailingComma": "all",
"tabWidth": 2,
"singleQuote": true,
"printWidth": 100,
"parser": "typescript"
}
84 changes: 59 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
[![CircleCI build status](https://circleci.com/gh/electron/update-electron-app/tree/master.svg?style=shield)](https://circleci.com/gh/electron/update-electron-app/tree/master)
[![npm version](http://img.shields.io/npm/v/update-electron-app.svg)](https://npmjs.org/package/update-electron-app)

Powered by the free and open-source [update.electronjs.org](https://update.electronjs.org) service.
Supports multiple update sources:
* The free and open-source [update.electronjs.org](https://update.electronjs.org) service.
* Static file storage E.g. S3, Google Cloud Storage, etc.

![screenshot](screenshot.png)

Expand All @@ -14,9 +16,12 @@ Powered by the free and open-source [update.electronjs.org](https://update.elect
Before using this module, make sure your Electron app meets these criteria:

- Your app runs on macOS or Windows
- Your app has a public GitHub repository
- Your builds are published to GitHub Releases
- Your builds are [code signed]
- **If** using `update.electronjs.org`
- Your app has a public GitHub repository
- Your builds are published to GitHub Releases
- **If** using static file storage
- Your builds are published to S3 or other similar static file host using a tool like `@electron-forge/publisher-s3`

## Installation

Expand All @@ -26,39 +31,59 @@ npm i update-electron-app

## Usage

### With `update.electronjs.org`

Drop this anywhere in your main process:

```js
require('update-electron-app')()
const { updateElectronApp } = require('update-electron-app')
updateElectronApp()
```

That's it! Here's what happens by default:

- Repository URL is found in your app's `package.json` file.
- Your app will check for updates at startup, then every ten minutes. This interval is [configurable](#API).
- No need to wait for your app's `ready` event; the module figures that out.
- If an update is found, it will automatically be downloaded in the background.
- When an update is finished downloading, a dialog is displayed allowing the user to restart the app now or later.
By default your repository URL is found in [your app's `package.json` file](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#repository).

You can also specify custom options:

```js
require('update-electron-app')({
repo: 'github-user/repo',
const { updateElectronApp, UpdateSourceType } = require('update-electron-app')
updateElectronApp({
updateSource: {
type: UpdateSourceType.ElectronPublicUpdateService,
repo: 'github-user/repo'
},
updateInterval: '1 hour',
logger: require('electron-log')
})
```

### With static file storage

```js
const { updateElectronApp, UpdateSourceType } = require('update-electron-app')
updateElectronApp({
updateSource: {
type: UpdateSourceType.StaticStorage,
baseUrl: `https://my-bucket.s3.amazonaws.com/my-app-updates/${process.platform}/${process.arch}`
}
})
```

## What happens?

Once you've called `updateElectronApp` as documented above, that's it! Here's what happens by default:

- Your app will check for updates at startup, then every ten minutes. This interval is [configurable](#API).
- No need to wait for your app's `ready` event; the module figures that out.
- If an update is found, it will automatically be downloaded in the background.
- When an update is finished downloading, a dialog is displayed allowing the user to restart the app now or later.

## API

### `update(options)`

Options:
Additional Options:

- `repo` String (optional) - A GitHub repository in the format `owner/repo`. Defaults to your `package.json`'s `"repository"` field
- `host` String (optional) - Defaults to `https://update.electronjs.org`
- `updateInterval` String (optional) - How frequently to check for updates. Defaults to `10 minutes`. Minimum allowed interval is `5 minutes`.
- `updateInterval` String (optional) - How frequently to check for updates. Defaults to `10 minutes`. Minimum allowed interval is `5 minutes`. This is a human readable interval supported by the [`ms`](https://github.com/vercel/ms#readme) module
- `logger` Object (optional) - A custom logger object that defines a `log` function. Defaults to `console`. See [electron-log](https://github.com/megahertz/electron-log), a module that aggregates logs from main and renderer processes into a single file.
- `notifyUser` Boolean (optional) - Defaults to `true`. When enabled the user will be
prompted to apply the update immediately after download.
Expand All @@ -67,10 +92,10 @@ Options:

#### What kinds of assets do I need to build?

For macOS, you'll need to build a `.zip` file and include it in your GitHub Release.
For macOS, you'll need to build a `.zip` file.
Use [electron-forge] or [electron-installer-zip] to package your app as a zip.

For Windows, you'll need to build a `.exe` file and include it in your GitHub Release.
For Windows, you'll need to build a `.exe` and `.nupkg` files with [electron-forge] or [electron-winstaller].

#### Why is my app launching multiple times?

Expand All @@ -82,16 +107,25 @@ behavior.

Yes :)

#### I want to manually upload my builds to a static storage solution, where do I put them?

If you publish your builds manually ensure the file structure is:
* `**/{platform}/{arch}/{artifact}`

For example that means that these files should exist:
* `**/win32/x64/RELEASES`
* `**/darwin/arm64/RELEASES.json`
* `**/darwin/arm64/My App v1.0.0.zip` (or something similar)
* ...


## License

MIT

## See Also

If your app is packaged with `electron-builder`, you may not need this module.
Builder has its own built-in mechanism for updating apps. Find out more at
[electron.build/auto-update](https://www.electron.build/auto-update).

[electron-forge]: https://github.com/electron/forge
[electron-installer-zip]: https://github.com/mongodb-js/electron-installer-zip
[code signed]: https://github.com/electron/electron/blob/main/docs/tutorial/code-signing.md
[electron-installer-zip]: https://github.com/electron-userland/electron-installer-zip
[electron-winstaller]: https://github.com/electron/windows-installer
[code signed]: https://www.electronjs.org/docs/latest/tutorial/code-signing
42 changes: 0 additions & 42 deletions index.d.ts

This file was deleted.

147 changes: 0 additions & 147 deletions index.js

This file was deleted.

16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,29 @@
"version": "0.0.0-development",
"description": "A drop-in module that adds autoUpdating capabilities to Electron apps",
"repository": "https://github.com/electron/update-electron-app",
"main": "index.js",
"types": "index.d.ts",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"license": "MIT",
"dependencies": {
"electron-is-dev": "^0.3.0",
"github-url-to-object": "^4.0.4",
"is-url": "^1.2.4",
"ms": "^2.1.1"
},
"peerDependencies": {
"electron": ">= 6.0.0"
},
"devDependencies": {
"@continuous-auth/semantic-release-npm": "^3.0.0",
"@types/github-url-to-object": "^4.0.1",
"@types/is-url": "^1.2.30",
"@types/ms": "^0.7.31",
"electron": "^22.0.0",
"jest": "^29.0.0",
"prettier": "^3.0.3",
"standard": "^14.3.4",
"standard-markdown": "^6.0.0",
"tsd": "^0.25.0",
"typescript": "^4.8.3"
"typescript": "^4.9.4"
},
"scripts": {
"prepare": "tsc",
"test": "jest && tsd && standard --fix && standard-markdown",
"watch": "jest --watch --notify --notifyMode=change --coverage"
},
Expand Down
Loading

0 comments on commit 107661d

Please sign in to comment.