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

[AutoUpdater][OSX] add squirrel auto updater #5722

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ tests/tmp-nw
tags
Thumbs.db
/tmp
external_binaries
40 changes: 39 additions & 1 deletion BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import("//build/toolchain/toolchain.gni")
if (is_mac) {
import("//build/util/branding.gni")
chrome_framework_name = chrome_product_full_name + " Framework"
cflags = [
"-F",
"../../content/nw/external_binaries",
]
}
import("//build/util/version.gni")

Expand All @@ -12,7 +16,30 @@ group("nwjs") {
"//third_party/ffmpeg:ffmpeg"
]
if (is_mac) {
deps += [ ":copy_ffmpeg" ]
deps += [ ":copy_ffmpeg", ":copy_external_binaries" ]
}
}

static_library("nw_autoupdater") {
deps = [
"//base",
]
sources = [
"src/browser/auto_updater.h",
"src/browser/auto_updater.cc",
"src/browser/auto_updater_mac.mm",
]
if (is_mac) {
libs = [
"Squirrel.framework",
"ReactiveCocoa.framework",
"Mantle.framework",
]
cflags_objcc = [
"-Wno-error=unused-command-line-argument",
"-fobjc-runtime=macosx-10.8",
"-fobjc-weak",
]
}
}

Expand Down Expand Up @@ -92,6 +119,8 @@ nw_chrome_browser_sources = [
"src/api/object_manager.h",
"src/api/object_manager_factory.cc",
"src/api/object_manager_factory.h",
"src/api/auto_updater/api_auto_updater.cc",
"src/api/auto_updater/api_auto_updater.h",
"src/api/base/base.cc",
"src/api/base/base.h",
"src/api/menu/menu.cc",
Expand Down Expand Up @@ -121,6 +150,7 @@ static_library("nw_browser") {
"//third_party/zlib:minizip",
"//skia",
":nw_base",
":nw_autoupdater",
"//content/nw/src/api:nw_api",
"//content/nw/src/api:nw_api_registration",
"//third_party/protobuf:protobuf_lite",
Expand Down Expand Up @@ -256,6 +286,14 @@ if (is_mac) {
"//third_party/ffmpeg:ffmpeg"
]
}
copy("copy_external_binaries") {
sources = [
"external_binaries/Squirrel.framework",
"external_binaries/ReactiveCocoa.framework",
"external_binaries/Mantle.framework",
]
outputs = [ "$root_out_dir/$chrome_product_full_name.app/Contents/Versions/$chrome_version_full/{{source_file_part}}" ]
}
}

copy("copy_node") {
Expand Down
142 changes: 142 additions & 0 deletions docs/References/AutoUpdater.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# AutoUpdater {: .doctitle}
---

[TOC]

`AutoUpdater` Enable apps to automatically update themselves.


The `AutoUpdater` module provides an interface for the
[Squirrel](https://github.com/Squirrel) framework.

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

- [nuts][nuts]: *A smart release server for your applications, using GitHub as a backend. Auto-updates with Squirrel (Mac & Windows)*
- [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.*

## Synopsis
```javascript
// listen to error events
nw.AutoUpdater.on('error', function(msg){
console.log(msg);
});

// listen to update-downloaded event
nw.AutoUpdater.on('update-downloaded', function(releaseNotes, releaseName, releaseDate, updateURL){
console.log(releaseNotes);
console.log(releaseName);
console.log(releaseDate);
console.log(updateURL);
nw.AutoUpdater.QuitAndInstall();
});

// set the update feed url
nw.AutoUpdater.SetFeedURL('file:///tmp/nwjs.autoupdate.json');
// the real autoupdate
nw.AutoUpdater.CheckForUpdates();
```

## Platform notices

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

### macOS

On macOS, the `AutoUpdater` module is built upon [Squirrel.Mac][squirrel-mac],
meaning you don't need any special setup to make it work. For server-side
requirements, you can read [Server Support][server-support]. Note that [App
Transport Security](https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW35) (ATS) applies to all requests made as part of the
update process. Apps that need to disable ATS can add the
`NSAllowsArbitraryLoads` key to their app's plist.

**Note:** Your application must be signed for automatic updates on macOS.
This is a requirement of `Squirrel.Mac`.

We have a [test suite](../../test/manual/autoupdate) to quickly test if the autoupdate feature is working.
Run `autoupdate.sh` from the folder, it needs 2 parameters:
* `IDENTITY` is your developer id, to sign the app
* `DIRECTORY` is your nwjs.app location

### Windows

On Windows, you have to install your app into a user's machine before you can
use the `AutoUpdater`, so it is recommended that you use the
[electron-winstaller][installer-lib], [electron-builder][electron-builder-lib] or the [grunt-electron-installer][installer] package to generate a Windows installer.

When using [electron-winstaller][installer-lib] or [electron-builder][electron-builder-lib] make sure you do not try to update your app [the first time it runs](https://github.com/electron/windows-installer#handling-squirrel-events) (Also see [this issue for more info](https://github.com/electron/electron/issues/7155)). It's also recommended to use [electron-squirrel-startup](https://github.com/mongodb-js/electron-squirrel-startup) to get desktop shortcuts for your app.

The installer generated with Squirrel will create a shortcut icon with an
[Application User Model ID][app-user-model-id] in the format of
`com.squirrel.PACKAGE_ID.YOUR_EXE_WITHOUT_DOT_EXE`, examples are
`com.squirrel.slack.Slack` and `com.squirrel.code.Code`. You have to use the
same ID for your app with `app.setAppUserModelId` API, otherwise Windows will
not be able to pin your app properly in task bar.

The server-side setup is also different from macOS. You can read the documents of
[Squirrel.Windows][squirrel-windows] to get more details.

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

## AutoUpdater.SetFeedURL(url)

* `url` String

Sets the `url` and initialize the auto updater.

## AutoUpdater.GetFeedURL()

Returns `String` - The current update feed URL.

## AutoUpdater.CheckForUpdates()

Asks the server whether there is an update. You must call `setFeedURL` before
using this API.

## AutoUpdater.QuitAndInstall()

Restarts the app and installs the update after it has been downloaded. It
should only be called after `update-downloaded` has been emitted.

## Event: error (msg)

Emitted when there is an error while updating.

## Event: checking-for-update

Emitted when checking if an update has started.

## Event: update-available

Emitted when there is an available update. The update is downloaded
automatically.

## Event: update-not-available

Emitted when there is no available update.

## Event: update-downloaded (releaseNotes, releaseName, releaseDate, updateURL)

Emitted when an update has been downloaded, with following parameters:

* `releaseNotes` String
* `releaseName` String, macOS only, NOT available on windows
* `releaseDate` Date
* `updateURL` String

[squirrel-mac]: https://github.com/Squirrel/Squirrel.Mac
[server-support]: https://github.com/Squirrel/Squirrel.Mac#server-support
[squirrel-windows]: https://github.com/Squirrel/Squirrel.Windows
[installer]: https://github.com/electron/grunt-electron-installer
[installer-lib]: https://github.com/electron/windows-installer
[electron-builder-lib]: https://github.com/electron-userland/electron-builder
[app-user-model-id]: https://msdn.microsoft.com/en-us/library/windows/desktop/dd378459(v=vs.85).aspx
[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
46 changes: 46 additions & 0 deletions nw.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,46 @@
},
},
},
'conditions': [
['OS=="mac"', {
'mac_framework_dirs': [
'<(DEPTH)/../content/nw/external_binaries',
],
}],
],

},
'targets': [
{
'target_name': 'nw_autoupdater',
'type': 'static_library',
'dependencies': [
'<(DEPTH)/base/base.gyp:base',
],
'sources': [
'src/browser/auto_updater.h',
'src/browser/auto_updater.cc',
'src/browser/auto_updater_mac.mm',
],
'conditions': [
['OS == "mac"', {
'link_settings': {
'libraries': [
'external_binaries/Squirrel.framework',
'external_binaries/ReactiveCocoa.framework',
'external_binaries/Mantle.framework',
],
},
'xcode_settings': {
'OTHER_CFLAGS': [
'-Wno-error=unused-command-line-argument',
'-fobjc-runtime=macosx-10.8',
'-fobjc-weak',
],
},
}],
],
},
{
'target_name': 'nw_base',
'type': '<(component)',
Expand Down Expand Up @@ -71,6 +109,7 @@
'<(DEPTH)/third_party/zlib/zlib.gyp:minizip',
'<(DEPTH)/skia/skia.gyp:skia',
'nw_base',
'nw_autoupdater',
'<(DEPTH)/content/nw/src/api/api.gyp:nw_api',
'<(DEPTH)/content/nw/src/api/api_registration.gyp:nw_api_registration',
'<(DEPTH)/extensions/browser/api/api_registration.gyp:extensions_api_registration',
Expand Down Expand Up @@ -107,6 +146,8 @@
'src/api/object_manager.h',
'src/api/object_manager_factory.cc',
'src/api/object_manager_factory.h',
'src/api/auto_updater/api_auto_updater.cc',
'src/api/auto_updater/api_auto_updater.h',
'src/api/base/base.cc',
'src/api/base/base.h',
'src/api/menu/menu.cc',
Expand Down Expand Up @@ -574,5 +615,10 @@
},
}
],
'xcode_settings': {
'LD_RUNPATH_SEARCH_PATHS': [
'@loader_path/..',
],
},
}

4 changes: 4 additions & 0 deletions src/api/_api_features.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"channel": "stable",
"contexts": ["blessed_extension"]
},
"nw.AutoUpdater": {
"channel": "stable",
"contexts": ["blessed_extension"]
},
"nw.Window": {
"channel": "stable",
"contexts": ["blessed_extension"]
Expand Down
Loading