@tauri-apps/plugin-updater 3.0.0-alpha.1 → 3.0.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist-js/index.cjs +124 -14
- package/dist-js/index.d.ts +126 -6
- package/dist-js/index.js +124 -14
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ In-app updates for Tauri applications.
|
|
|
12
12
|
|
|
13
13
|
## Install
|
|
14
14
|
|
|
15
|
-
_This plugin requires a Rust version of at least **1.
|
|
15
|
+
_This plugin requires a Rust version of at least **1.95**_
|
|
16
16
|
|
|
17
17
|
There are three general methods of installation that we can recommend.
|
|
18
18
|
|
package/dist-js/index.cjs
CHANGED
|
@@ -5,19 +5,66 @@ var core = require('@tauri-apps/api/core');
|
|
|
5
5
|
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
|
6
6
|
// SPDX-License-Identifier: Apache-2.0
|
|
7
7
|
// SPDX-License-Identifier: MIT
|
|
8
|
+
/**
|
|
9
|
+
* In-app updates for Tauri applications: check the configured endpoints for a new release,
|
|
10
|
+
* download it and install it.
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* An update announced by the update server, as returned by {@linkcode check}.
|
|
16
|
+
*
|
|
17
|
+
* It holds a resource on the Rust side, so call {@linkcode Update.close} when you are done with it
|
|
18
|
+
* without installing it.
|
|
19
|
+
*
|
|
20
|
+
* @since 2.0.0
|
|
21
|
+
*/
|
|
8
22
|
class Update extends core.Resource {
|
|
23
|
+
/**
|
|
24
|
+
* Creates an update from the metadata returned by the backend.
|
|
25
|
+
* You should not need to call this yourself, use {@linkcode check} instead.
|
|
26
|
+
*
|
|
27
|
+
* @param metadata The update information returned by the backend, including the resource identifier of the update.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* import { check } from '@tauri-apps/plugin-updater';
|
|
32
|
+
* // the update instance is created for you by `check`
|
|
33
|
+
* const update = await check();
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
9
36
|
constructor(metadata) {
|
|
10
37
|
super(metadata.rid);
|
|
11
|
-
this.available = true;
|
|
12
38
|
this.currentVersion = metadata.currentVersion;
|
|
13
39
|
this.version = metadata.version;
|
|
14
40
|
this.date = metadata.date;
|
|
15
41
|
this.body = metadata.body;
|
|
16
42
|
this.rawJson = metadata.rawJson;
|
|
17
43
|
}
|
|
18
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* Downloads the updater package. Call {@linkcode install} later to install it.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* import { check } from '@tauri-apps/plugin-updater';
|
|
50
|
+
*
|
|
51
|
+
* const update = await check();
|
|
52
|
+
* if (update) {
|
|
53
|
+
* let downloaded = 0;
|
|
54
|
+
* await update.download((event) => {
|
|
55
|
+
* if (event.event === 'Progress') {
|
|
56
|
+
* downloaded += event.data.chunkLength;
|
|
57
|
+
* console.log(`downloaded ${downloaded} bytes`);
|
|
58
|
+
* }
|
|
59
|
+
* });
|
|
60
|
+
* await update.install();
|
|
61
|
+
* }
|
|
62
|
+
* ```
|
|
63
|
+
*
|
|
64
|
+
* @param onEvent Callback invoked with a `Started` event when the first chunk is received, a `Progress` event for every downloaded chunk and a `Finished` event when the download completes.
|
|
65
|
+
* @param options The headers and the timeout to use for the download request.
|
|
66
|
+
*/
|
|
19
67
|
async download(onEvent, options) {
|
|
20
|
-
convertToRustHeaders(options);
|
|
21
68
|
const channel = new core.Channel();
|
|
22
69
|
if (onEvent) {
|
|
23
70
|
channel.onmessage = onEvent;
|
|
@@ -25,8 +72,12 @@ class Update extends core.Resource {
|
|
|
25
72
|
const downloadedBytesRid = await core.invoke('plugin:updater|download', {
|
|
26
73
|
onEvent: channel,
|
|
27
74
|
rid: this.rid,
|
|
28
|
-
...options
|
|
75
|
+
...options,
|
|
76
|
+
headers: toRustHeaders(options?.headers)
|
|
29
77
|
});
|
|
78
|
+
// release the bytes of a previous download, which would otherwise be kept
|
|
79
|
+
// in memory until the webview is destroyed
|
|
80
|
+
await this.downloadedBytes?.close().catch(() => { });
|
|
30
81
|
this.downloadedBytes = new core.Resource(downloadedBytesRid);
|
|
31
82
|
}
|
|
32
83
|
/**
|
|
@@ -36,6 +87,19 @@ class Update extends core.Resource {
|
|
|
36
87
|
*
|
|
37
88
|
* - **Windows:** This function exits the app after launching the updater installer successfully
|
|
38
89
|
* - **macOS / Linux:** You need to relaunch the app to run the newly install version
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* import { check } from '@tauri-apps/plugin-updater';
|
|
94
|
+
*
|
|
95
|
+
* const update = await check();
|
|
96
|
+
* if (update) {
|
|
97
|
+
* await update.download();
|
|
98
|
+
* await update.install();
|
|
99
|
+
* }
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* @param options Options for the installation, such as whether the Windows installer should restart the app afterwards.
|
|
39
103
|
*/
|
|
40
104
|
async install(options) {
|
|
41
105
|
if (!this.downloadedBytes) {
|
|
@@ -56,9 +120,23 @@ class Update extends core.Resource {
|
|
|
56
120
|
*
|
|
57
121
|
* - **Windows:** This function exits the app after launching the updater installer successfully
|
|
58
122
|
* - **macOS / Linux:** You need to relaunch the app to run the newly install version
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* import { check } from '@tauri-apps/plugin-updater';
|
|
127
|
+
*
|
|
128
|
+
* const update = await check();
|
|
129
|
+
* if (update) {
|
|
130
|
+
* await update.downloadAndInstall((event) => {
|
|
131
|
+
* console.log(event.event);
|
|
132
|
+
* });
|
|
133
|
+
* }
|
|
134
|
+
* ```
|
|
135
|
+
*
|
|
136
|
+
* @param onEvent Callback invoked with a `Started` event when the first chunk is received, a `Progress` event for every downloaded chunk and a `Finished` event when the download completes.
|
|
137
|
+
* @param options The headers and the timeout to use for the download request, and the installation options.
|
|
59
138
|
*/
|
|
60
139
|
async downloadAndInstall(onEvent, options) {
|
|
61
|
-
convertToRustHeaders(options);
|
|
62
140
|
const channel = new core.Channel();
|
|
63
141
|
if (onEvent) {
|
|
64
142
|
channel.onmessage = onEvent;
|
|
@@ -66,29 +144,61 @@ class Update extends core.Resource {
|
|
|
66
144
|
await core.invoke('plugin:updater|download_and_install', {
|
|
67
145
|
onEvent: channel,
|
|
68
146
|
rid: this.rid,
|
|
69
|
-
...options
|
|
147
|
+
...options,
|
|
148
|
+
headers: toRustHeaders(options?.headers)
|
|
70
149
|
});
|
|
71
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* Releases the update resource and the downloaded bytes held by the backend.
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```typescript
|
|
156
|
+
* import { check } from '@tauri-apps/plugin-updater';
|
|
157
|
+
*
|
|
158
|
+
* const update = await check();
|
|
159
|
+
* if (update) {
|
|
160
|
+
* await update.close();
|
|
161
|
+
* }
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
72
164
|
async close() {
|
|
73
165
|
await this.downloadedBytes?.close();
|
|
74
166
|
await super.close();
|
|
75
167
|
}
|
|
76
168
|
}
|
|
77
|
-
/**
|
|
169
|
+
/**
|
|
170
|
+
* Checks the configured endpoints for an available update.
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```typescript
|
|
174
|
+
* import { check } from '@tauri-apps/plugin-updater';
|
|
175
|
+
*
|
|
176
|
+
* const update = await check();
|
|
177
|
+
* if (update) {
|
|
178
|
+
* console.log(`update ${update.version} is available`);
|
|
179
|
+
* await update.downloadAndInstall();
|
|
180
|
+
* }
|
|
181
|
+
* ```
|
|
182
|
+
*
|
|
183
|
+
* @param options The headers, timeout, proxy and target to use for the update check request.
|
|
184
|
+
*
|
|
185
|
+
* @returns A promise resolving to the available {@linkcode Update}, or `null` when no update is available.
|
|
186
|
+
*
|
|
187
|
+
* @since 2.0.0
|
|
188
|
+
*/
|
|
78
189
|
async function check(options) {
|
|
79
|
-
convertToRustHeaders(options);
|
|
80
190
|
const metadata = await core.invoke('plugin:updater|check', {
|
|
81
|
-
...options
|
|
191
|
+
...options,
|
|
192
|
+
headers: toRustHeaders(options?.headers)
|
|
82
193
|
});
|
|
83
194
|
return metadata ? new Update(metadata) : null;
|
|
84
195
|
}
|
|
85
196
|
/**
|
|
86
|
-
* Converts
|
|
197
|
+
* Converts headers to an {@linkcode Array<[string, string]>}, which is what the Rust side expects,
|
|
198
|
+
* without modifying the caller's options.
|
|
87
199
|
*/
|
|
88
|
-
function
|
|
89
|
-
|
|
90
|
-
options.headers = Array.from(new Headers(options.headers).entries());
|
|
91
|
-
}
|
|
200
|
+
function toRustHeaders(headers) {
|
|
201
|
+
return headers ? Array.from(new Headers(headers).entries()) : undefined;
|
|
92
202
|
}
|
|
93
203
|
|
|
94
204
|
exports.Update = Update;
|
package/dist-js/index.d.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-app updates for Tauri applications: check the configured endpoints for a new release,
|
|
3
|
+
* download it and install it.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
1
7
|
import { Resource } from '@tauri-apps/api/core';
|
|
2
8
|
/** Options used when checking for updates */
|
|
3
9
|
interface CheckOptions {
|
|
4
10
|
/**
|
|
5
|
-
*
|
|
11
|
+
* The headers to send along with the update check request.
|
|
6
12
|
*/
|
|
7
13
|
headers?: HeadersInit;
|
|
8
14
|
/**
|
|
@@ -21,7 +27,7 @@ interface CheckOptions {
|
|
|
21
27
|
/** Options used when downloading an update */
|
|
22
28
|
interface DownloadOptions {
|
|
23
29
|
/**
|
|
24
|
-
*
|
|
30
|
+
* The headers to send along with the update download request.
|
|
25
31
|
*/
|
|
26
32
|
headers?: HeadersInit;
|
|
27
33
|
/**
|
|
@@ -58,17 +64,71 @@ type DownloadEvent = {
|
|
|
58
64
|
} | {
|
|
59
65
|
event: 'Finished';
|
|
60
66
|
};
|
|
67
|
+
/**
|
|
68
|
+
* An update announced by the update server, as returned by {@linkcode check}.
|
|
69
|
+
*
|
|
70
|
+
* It holds a resource on the Rust side, so call {@linkcode Update.close} when you are done with it
|
|
71
|
+
* without installing it.
|
|
72
|
+
*
|
|
73
|
+
* @since 2.0.0
|
|
74
|
+
*/
|
|
61
75
|
declare class Update extends Resource {
|
|
62
|
-
/** @deprecated This is always true, check if the return value is `null` instead when using {@linkcode check} */
|
|
63
|
-
available: boolean;
|
|
64
76
|
currentVersion: string;
|
|
77
|
+
/**
|
|
78
|
+
* The version announced by the update server.
|
|
79
|
+
*/
|
|
65
80
|
version: string;
|
|
81
|
+
/**
|
|
82
|
+
* The publish date of the update as an RFC 3339 string, when the server provided one.
|
|
83
|
+
*/
|
|
66
84
|
date?: string;
|
|
85
|
+
/**
|
|
86
|
+
* The release notes of the update, when the server provided them.
|
|
87
|
+
*/
|
|
67
88
|
body?: string;
|
|
89
|
+
/**
|
|
90
|
+
* The raw update manifest returned by the server, useful when it contains
|
|
91
|
+
* additional fields that the updater itself does not handle.
|
|
92
|
+
*/
|
|
68
93
|
rawJson: Record<string, unknown>;
|
|
69
94
|
private downloadedBytes?;
|
|
95
|
+
/**
|
|
96
|
+
* Creates an update from the metadata returned by the backend.
|
|
97
|
+
* You should not need to call this yourself, use {@linkcode check} instead.
|
|
98
|
+
*
|
|
99
|
+
* @param metadata The update information returned by the backend, including the resource identifier of the update.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* import { check } from '@tauri-apps/plugin-updater';
|
|
104
|
+
* // the update instance is created for you by `check`
|
|
105
|
+
* const update = await check();
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
70
108
|
constructor(metadata: UpdateMetadata);
|
|
71
|
-
/**
|
|
109
|
+
/**
|
|
110
|
+
* Downloads the updater package. Call {@linkcode install} later to install it.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* import { check } from '@tauri-apps/plugin-updater';
|
|
115
|
+
*
|
|
116
|
+
* const update = await check();
|
|
117
|
+
* if (update) {
|
|
118
|
+
* let downloaded = 0;
|
|
119
|
+
* await update.download((event) => {
|
|
120
|
+
* if (event.event === 'Progress') {
|
|
121
|
+
* downloaded += event.data.chunkLength;
|
|
122
|
+
* console.log(`downloaded ${downloaded} bytes`);
|
|
123
|
+
* }
|
|
124
|
+
* });
|
|
125
|
+
* await update.install();
|
|
126
|
+
* }
|
|
127
|
+
* ```
|
|
128
|
+
*
|
|
129
|
+
* @param onEvent Callback invoked with a `Started` event when the first chunk is received, a `Progress` event for every downloaded chunk and a `Finished` event when the download completes.
|
|
130
|
+
* @param options The headers and the timeout to use for the download request.
|
|
131
|
+
*/
|
|
72
132
|
download(onEvent?: (progress: DownloadEvent) => void, options?: DownloadOptions): Promise<void>;
|
|
73
133
|
/**
|
|
74
134
|
* Install downloaded updater package. Must be called after {@linkcode download}.
|
|
@@ -77,6 +137,19 @@ declare class Update extends Resource {
|
|
|
77
137
|
*
|
|
78
138
|
* - **Windows:** This function exits the app after launching the updater installer successfully
|
|
79
139
|
* - **macOS / Linux:** You need to relaunch the app to run the newly install version
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```typescript
|
|
143
|
+
* import { check } from '@tauri-apps/plugin-updater';
|
|
144
|
+
*
|
|
145
|
+
* const update = await check();
|
|
146
|
+
* if (update) {
|
|
147
|
+
* await update.download();
|
|
148
|
+
* await update.install();
|
|
149
|
+
* }
|
|
150
|
+
* ```
|
|
151
|
+
*
|
|
152
|
+
* @param options Options for the installation, such as whether the Windows installer should restart the app afterwards.
|
|
80
153
|
*/
|
|
81
154
|
install(options?: InstallOptions): Promise<void>;
|
|
82
155
|
/**
|
|
@@ -86,11 +159,58 @@ declare class Update extends Resource {
|
|
|
86
159
|
*
|
|
87
160
|
* - **Windows:** This function exits the app after launching the updater installer successfully
|
|
88
161
|
* - **macOS / Linux:** You need to relaunch the app to run the newly install version
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* import { check } from '@tauri-apps/plugin-updater';
|
|
166
|
+
*
|
|
167
|
+
* const update = await check();
|
|
168
|
+
* if (update) {
|
|
169
|
+
* await update.downloadAndInstall((event) => {
|
|
170
|
+
* console.log(event.event);
|
|
171
|
+
* });
|
|
172
|
+
* }
|
|
173
|
+
* ```
|
|
174
|
+
*
|
|
175
|
+
* @param onEvent Callback invoked with a `Started` event when the first chunk is received, a `Progress` event for every downloaded chunk and a `Finished` event when the download completes.
|
|
176
|
+
* @param options The headers and the timeout to use for the download request, and the installation options.
|
|
89
177
|
*/
|
|
90
178
|
downloadAndInstall(onEvent?: (progress: DownloadEvent) => void, options?: DownloadOptions & InstallOptions): Promise<void>;
|
|
179
|
+
/**
|
|
180
|
+
* Releases the update resource and the downloaded bytes held by the backend.
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```typescript
|
|
184
|
+
* import { check } from '@tauri-apps/plugin-updater';
|
|
185
|
+
*
|
|
186
|
+
* const update = await check();
|
|
187
|
+
* if (update) {
|
|
188
|
+
* await update.close();
|
|
189
|
+
* }
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
91
192
|
close(): Promise<void>;
|
|
92
193
|
}
|
|
93
|
-
/**
|
|
194
|
+
/**
|
|
195
|
+
* Checks the configured endpoints for an available update.
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```typescript
|
|
199
|
+
* import { check } from '@tauri-apps/plugin-updater';
|
|
200
|
+
*
|
|
201
|
+
* const update = await check();
|
|
202
|
+
* if (update) {
|
|
203
|
+
* console.log(`update ${update.version} is available`);
|
|
204
|
+
* await update.downloadAndInstall();
|
|
205
|
+
* }
|
|
206
|
+
* ```
|
|
207
|
+
*
|
|
208
|
+
* @param options The headers, timeout, proxy and target to use for the update check request.
|
|
209
|
+
*
|
|
210
|
+
* @returns A promise resolving to the available {@linkcode Update}, or `null` when no update is available.
|
|
211
|
+
*
|
|
212
|
+
* @since 2.0.0
|
|
213
|
+
*/
|
|
94
214
|
declare function check(options?: CheckOptions): Promise<Update | null>;
|
|
95
215
|
export type { CheckOptions, DownloadOptions, DownloadEvent };
|
|
96
216
|
export { check, Update };
|
package/dist-js/index.js
CHANGED
|
@@ -3,19 +3,66 @@ import { Resource, Channel, invoke } from '@tauri-apps/api/core';
|
|
|
3
3
|
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
|
4
4
|
// SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
// SPDX-License-Identifier: MIT
|
|
6
|
+
/**
|
|
7
|
+
* In-app updates for Tauri applications: check the configured endpoints for a new release,
|
|
8
|
+
* download it and install it.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* An update announced by the update server, as returned by {@linkcode check}.
|
|
14
|
+
*
|
|
15
|
+
* It holds a resource on the Rust side, so call {@linkcode Update.close} when you are done with it
|
|
16
|
+
* without installing it.
|
|
17
|
+
*
|
|
18
|
+
* @since 2.0.0
|
|
19
|
+
*/
|
|
6
20
|
class Update extends Resource {
|
|
21
|
+
/**
|
|
22
|
+
* Creates an update from the metadata returned by the backend.
|
|
23
|
+
* You should not need to call this yourself, use {@linkcode check} instead.
|
|
24
|
+
*
|
|
25
|
+
* @param metadata The update information returned by the backend, including the resource identifier of the update.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* import { check } from '@tauri-apps/plugin-updater';
|
|
30
|
+
* // the update instance is created for you by `check`
|
|
31
|
+
* const update = await check();
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
7
34
|
constructor(metadata) {
|
|
8
35
|
super(metadata.rid);
|
|
9
|
-
this.available = true;
|
|
10
36
|
this.currentVersion = metadata.currentVersion;
|
|
11
37
|
this.version = metadata.version;
|
|
12
38
|
this.date = metadata.date;
|
|
13
39
|
this.body = metadata.body;
|
|
14
40
|
this.rawJson = metadata.rawJson;
|
|
15
41
|
}
|
|
16
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* Downloads the updater package. Call {@linkcode install} later to install it.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* import { check } from '@tauri-apps/plugin-updater';
|
|
48
|
+
*
|
|
49
|
+
* const update = await check();
|
|
50
|
+
* if (update) {
|
|
51
|
+
* let downloaded = 0;
|
|
52
|
+
* await update.download((event) => {
|
|
53
|
+
* if (event.event === 'Progress') {
|
|
54
|
+
* downloaded += event.data.chunkLength;
|
|
55
|
+
* console.log(`downloaded ${downloaded} bytes`);
|
|
56
|
+
* }
|
|
57
|
+
* });
|
|
58
|
+
* await update.install();
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @param onEvent Callback invoked with a `Started` event when the first chunk is received, a `Progress` event for every downloaded chunk and a `Finished` event when the download completes.
|
|
63
|
+
* @param options The headers and the timeout to use for the download request.
|
|
64
|
+
*/
|
|
17
65
|
async download(onEvent, options) {
|
|
18
|
-
convertToRustHeaders(options);
|
|
19
66
|
const channel = new Channel();
|
|
20
67
|
if (onEvent) {
|
|
21
68
|
channel.onmessage = onEvent;
|
|
@@ -23,8 +70,12 @@ class Update extends Resource {
|
|
|
23
70
|
const downloadedBytesRid = await invoke('plugin:updater|download', {
|
|
24
71
|
onEvent: channel,
|
|
25
72
|
rid: this.rid,
|
|
26
|
-
...options
|
|
73
|
+
...options,
|
|
74
|
+
headers: toRustHeaders(options?.headers)
|
|
27
75
|
});
|
|
76
|
+
// release the bytes of a previous download, which would otherwise be kept
|
|
77
|
+
// in memory until the webview is destroyed
|
|
78
|
+
await this.downloadedBytes?.close().catch(() => { });
|
|
28
79
|
this.downloadedBytes = new Resource(downloadedBytesRid);
|
|
29
80
|
}
|
|
30
81
|
/**
|
|
@@ -34,6 +85,19 @@ class Update extends Resource {
|
|
|
34
85
|
*
|
|
35
86
|
* - **Windows:** This function exits the app after launching the updater installer successfully
|
|
36
87
|
* - **macOS / Linux:** You need to relaunch the app to run the newly install version
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* import { check } from '@tauri-apps/plugin-updater';
|
|
92
|
+
*
|
|
93
|
+
* const update = await check();
|
|
94
|
+
* if (update) {
|
|
95
|
+
* await update.download();
|
|
96
|
+
* await update.install();
|
|
97
|
+
* }
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
100
|
+
* @param options Options for the installation, such as whether the Windows installer should restart the app afterwards.
|
|
37
101
|
*/
|
|
38
102
|
async install(options) {
|
|
39
103
|
if (!this.downloadedBytes) {
|
|
@@ -54,9 +118,23 @@ class Update extends Resource {
|
|
|
54
118
|
*
|
|
55
119
|
* - **Windows:** This function exits the app after launching the updater installer successfully
|
|
56
120
|
* - **macOS / Linux:** You need to relaunch the app to run the newly install version
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* import { check } from '@tauri-apps/plugin-updater';
|
|
125
|
+
*
|
|
126
|
+
* const update = await check();
|
|
127
|
+
* if (update) {
|
|
128
|
+
* await update.downloadAndInstall((event) => {
|
|
129
|
+
* console.log(event.event);
|
|
130
|
+
* });
|
|
131
|
+
* }
|
|
132
|
+
* ```
|
|
133
|
+
*
|
|
134
|
+
* @param onEvent Callback invoked with a `Started` event when the first chunk is received, a `Progress` event for every downloaded chunk and a `Finished` event when the download completes.
|
|
135
|
+
* @param options The headers and the timeout to use for the download request, and the installation options.
|
|
57
136
|
*/
|
|
58
137
|
async downloadAndInstall(onEvent, options) {
|
|
59
|
-
convertToRustHeaders(options);
|
|
60
138
|
const channel = new Channel();
|
|
61
139
|
if (onEvent) {
|
|
62
140
|
channel.onmessage = onEvent;
|
|
@@ -64,29 +142,61 @@ class Update extends Resource {
|
|
|
64
142
|
await invoke('plugin:updater|download_and_install', {
|
|
65
143
|
onEvent: channel,
|
|
66
144
|
rid: this.rid,
|
|
67
|
-
...options
|
|
145
|
+
...options,
|
|
146
|
+
headers: toRustHeaders(options?.headers)
|
|
68
147
|
});
|
|
69
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* Releases the update resource and the downloaded bytes held by the backend.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* import { check } from '@tauri-apps/plugin-updater';
|
|
155
|
+
*
|
|
156
|
+
* const update = await check();
|
|
157
|
+
* if (update) {
|
|
158
|
+
* await update.close();
|
|
159
|
+
* }
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
70
162
|
async close() {
|
|
71
163
|
await this.downloadedBytes?.close();
|
|
72
164
|
await super.close();
|
|
73
165
|
}
|
|
74
166
|
}
|
|
75
|
-
/**
|
|
167
|
+
/**
|
|
168
|
+
* Checks the configured endpoints for an available update.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```typescript
|
|
172
|
+
* import { check } from '@tauri-apps/plugin-updater';
|
|
173
|
+
*
|
|
174
|
+
* const update = await check();
|
|
175
|
+
* if (update) {
|
|
176
|
+
* console.log(`update ${update.version} is available`);
|
|
177
|
+
* await update.downloadAndInstall();
|
|
178
|
+
* }
|
|
179
|
+
* ```
|
|
180
|
+
*
|
|
181
|
+
* @param options The headers, timeout, proxy and target to use for the update check request.
|
|
182
|
+
*
|
|
183
|
+
* @returns A promise resolving to the available {@linkcode Update}, or `null` when no update is available.
|
|
184
|
+
*
|
|
185
|
+
* @since 2.0.0
|
|
186
|
+
*/
|
|
76
187
|
async function check(options) {
|
|
77
|
-
convertToRustHeaders(options);
|
|
78
188
|
const metadata = await invoke('plugin:updater|check', {
|
|
79
|
-
...options
|
|
189
|
+
...options,
|
|
190
|
+
headers: toRustHeaders(options?.headers)
|
|
80
191
|
});
|
|
81
192
|
return metadata ? new Update(metadata) : null;
|
|
82
193
|
}
|
|
83
194
|
/**
|
|
84
|
-
* Converts
|
|
195
|
+
* Converts headers to an {@linkcode Array<[string, string]>}, which is what the Rust side expects,
|
|
196
|
+
* without modifying the caller's options.
|
|
85
197
|
*/
|
|
86
|
-
function
|
|
87
|
-
|
|
88
|
-
options.headers = Array.from(new Headers(options.headers).entries());
|
|
89
|
-
}
|
|
198
|
+
function toRustHeaders(headers) {
|
|
199
|
+
return headers ? Array.from(new Headers(headers).entries()) : undefined;
|
|
90
200
|
}
|
|
91
201
|
|
|
92
202
|
export { Update, check };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tauri-apps/plugin-updater",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.3",
|
|
4
4
|
"license": "MIT OR Apache-2.0",
|
|
5
5
|
"authors": [
|
|
6
6
|
"Tauri Programme within The Commons Conservancy"
|
|
@@ -24,6 +24,6 @@
|
|
|
24
24
|
"LICENSE"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@tauri-apps/api": "^3.0.0-alpha.
|
|
27
|
+
"@tauri-apps/api": "^3.0.0-alpha.2"
|
|
28
28
|
}
|
|
29
29
|
}
|