File size: 1,870 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# Updater

Base class for Auto- and Manual updater.

## Options

- **`confirmLabel`** = `Update & Restart` - Label for the confirm button of the "Update is available" dialog
- **`dialogMessage`** = `{name} {newVersion} is now available — you have {currentVersion}. Would you like to update now?` - Message for the dialog
- **`dialogTitle`** = `A new version of {name} is available!` - Title for the dialog
- **`beta`** = `false` - Check for beta versions

## Methods

### `Updater.ping()`

Checks for updates.

```js
updater.ping();
```

### `Updater.setVersion()`

Sets the new version for the updater dialog.

```js
updater.setVersion( '1.0.1' );
```

### `Updater.notify()`

Prompts the user with the update dialog.
`this.onConfirm` and `this.onCancel` will be executed based on the users confirmation or cancellation.

```js
class MyUpdater extends Updater {
	constructor( { options } ) {
		super( options );
	}

	async ping() {
		// check for update
		if ( shouldUpdate ) {
			this.setVersion( '1.0.0' );
			this.notify();
		}
	}
}
```

### `Updater.expandMacros( text )`

Expands macros.

Available macros are

- **`name`** = `app.getName()`
- **`currentVersion`** = `app.getVersion()`
- **`newVersion`** = `this._version` (defined by `this.setVersion()`)

```js
updater.expandMacros( '{name} {newVersion} is now available' ); // WordPress.com 1.0.1 is now available
```

### `Updater.onConfirm()`

Function that will be triggered when the user click the confirm button.

```js
class MyUpdater extends Updater {
	onConfirm() {
		// Download Update
		autoUpdater.quitAndInstall();
		// or for e.g. manual updater
		shell.openExternal( 'http://...' );
	}
}
```

### `Updater.onCancel()`

Function that will be triggered when the user clicks the cancel button.

```js
class MyUpdater extends Updater {
	onCancel() {
		// The user has cancelled the updater
	}
}
```