@tauri-apps/plugin-updater 3.0.0-alpha.1 → 3.0.0-alpha.2

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 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.77.2**_
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,17 +5,65 @@ 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
- /** Download the updater package. Call {@linkcode install} later to install it */
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
68
  convertToRustHeaders(options);
21
69
  const channel = new core.Channel();
@@ -36,6 +84,19 @@ class Update extends core.Resource {
36
84
  *
37
85
  * - **Windows:** This function exits the app after launching the updater installer successfully
38
86
  * - **macOS / Linux:** You need to relaunch the app to run the newly install version
87
+ *
88
+ * @example
89
+ * ```typescript
90
+ * import { check } from '@tauri-apps/plugin-updater';
91
+ *
92
+ * const update = await check();
93
+ * if (update) {
94
+ * await update.download();
95
+ * await update.install();
96
+ * }
97
+ * ```
98
+ *
99
+ * @param options Options for the installation, such as whether the Windows installer should restart the app afterwards.
39
100
  */
40
101
  async install(options) {
41
102
  if (!this.downloadedBytes) {
@@ -56,6 +117,21 @@ class Update extends core.Resource {
56
117
  *
57
118
  * - **Windows:** This function exits the app after launching the updater installer successfully
58
119
  * - **macOS / Linux:** You need to relaunch the app to run the newly install version
120
+ *
121
+ * @example
122
+ * ```typescript
123
+ * import { check } from '@tauri-apps/plugin-updater';
124
+ *
125
+ * const update = await check();
126
+ * if (update) {
127
+ * await update.downloadAndInstall((event) => {
128
+ * console.log(event.event);
129
+ * });
130
+ * }
131
+ * ```
132
+ *
133
+ * @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.
134
+ * @param options The headers and the timeout to use for the download request, and the installation options.
59
135
  */
60
136
  async downloadAndInstall(onEvent, options) {
61
137
  convertToRustHeaders(options);
@@ -69,12 +145,44 @@ class Update extends core.Resource {
69
145
  ...options
70
146
  });
71
147
  }
148
+ /**
149
+ * Releases the update resource and the downloaded bytes held by the backend.
150
+ *
151
+ * @example
152
+ * ```typescript
153
+ * import { check } from '@tauri-apps/plugin-updater';
154
+ *
155
+ * const update = await check();
156
+ * if (update) {
157
+ * await update.close();
158
+ * }
159
+ * ```
160
+ */
72
161
  async close() {
73
162
  await this.downloadedBytes?.close();
74
163
  await super.close();
75
164
  }
76
165
  }
77
- /** Check for updates, resolves to `null` if no updates are available */
166
+ /**
167
+ * Checks the configured endpoints for an available update.
168
+ *
169
+ * @example
170
+ * ```typescript
171
+ * import { check } from '@tauri-apps/plugin-updater';
172
+ *
173
+ * const update = await check();
174
+ * if (update) {
175
+ * console.log(`update ${update.version} is available`);
176
+ * await update.downloadAndInstall();
177
+ * }
178
+ * ```
179
+ *
180
+ * @param options The headers, timeout, proxy and target to use for the update check request.
181
+ *
182
+ * @returns A promise resolving to the available {@linkcode Update}, or `null` when no update is available.
183
+ *
184
+ * @since 2.0.0
185
+ */
78
186
  async function check(options) {
79
187
  convertToRustHeaders(options);
80
188
  const metadata = await core.invoke('plugin:updater|check', {
@@ -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
- * Request headers
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
- * Request headers
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
- /** Download the updater package. Call {@linkcode install} later to install it */
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
- /** Check for updates, resolves to `null` if no updates are available */
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,17 +3,65 @@ 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
- /** Download the updater package. Call {@linkcode install} later to install it */
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
66
  convertToRustHeaders(options);
19
67
  const channel = new Channel();
@@ -34,6 +82,19 @@ class Update extends Resource {
34
82
  *
35
83
  * - **Windows:** This function exits the app after launching the updater installer successfully
36
84
  * - **macOS / Linux:** You need to relaunch the app to run the newly install version
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * import { check } from '@tauri-apps/plugin-updater';
89
+ *
90
+ * const update = await check();
91
+ * if (update) {
92
+ * await update.download();
93
+ * await update.install();
94
+ * }
95
+ * ```
96
+ *
97
+ * @param options Options for the installation, such as whether the Windows installer should restart the app afterwards.
37
98
  */
38
99
  async install(options) {
39
100
  if (!this.downloadedBytes) {
@@ -54,6 +115,21 @@ class Update extends Resource {
54
115
  *
55
116
  * - **Windows:** This function exits the app after launching the updater installer successfully
56
117
  * - **macOS / Linux:** You need to relaunch the app to run the newly install version
118
+ *
119
+ * @example
120
+ * ```typescript
121
+ * import { check } from '@tauri-apps/plugin-updater';
122
+ *
123
+ * const update = await check();
124
+ * if (update) {
125
+ * await update.downloadAndInstall((event) => {
126
+ * console.log(event.event);
127
+ * });
128
+ * }
129
+ * ```
130
+ *
131
+ * @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.
132
+ * @param options The headers and the timeout to use for the download request, and the installation options.
57
133
  */
58
134
  async downloadAndInstall(onEvent, options) {
59
135
  convertToRustHeaders(options);
@@ -67,12 +143,44 @@ class Update extends Resource {
67
143
  ...options
68
144
  });
69
145
  }
146
+ /**
147
+ * Releases the update resource and the downloaded bytes held by the backend.
148
+ *
149
+ * @example
150
+ * ```typescript
151
+ * import { check } from '@tauri-apps/plugin-updater';
152
+ *
153
+ * const update = await check();
154
+ * if (update) {
155
+ * await update.close();
156
+ * }
157
+ * ```
158
+ */
70
159
  async close() {
71
160
  await this.downloadedBytes?.close();
72
161
  await super.close();
73
162
  }
74
163
  }
75
- /** Check for updates, resolves to `null` if no updates are available */
164
+ /**
165
+ * Checks the configured endpoints for an available update.
166
+ *
167
+ * @example
168
+ * ```typescript
169
+ * import { check } from '@tauri-apps/plugin-updater';
170
+ *
171
+ * const update = await check();
172
+ * if (update) {
173
+ * console.log(`update ${update.version} is available`);
174
+ * await update.downloadAndInstall();
175
+ * }
176
+ * ```
177
+ *
178
+ * @param options The headers, timeout, proxy and target to use for the update check request.
179
+ *
180
+ * @returns A promise resolving to the available {@linkcode Update}, or `null` when no update is available.
181
+ *
182
+ * @since 2.0.0
183
+ */
76
184
  async function check(options) {
77
185
  convertToRustHeaders(options);
78
186
  const metadata = await invoke('plugin:updater|check', {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tauri-apps/plugin-updater",
3
- "version": "3.0.0-alpha.1",
3
+ "version": "3.0.0-alpha.2",
4
4
  "license": "MIT OR Apache-2.0",
5
5
  "authors": [
6
6
  "Tauri Programme within The Commons Conservancy"