@tauri-apps/plugin-updater 2.13.2 → 2.14.0

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/dist-js/index.cjs CHANGED
@@ -66,7 +66,6 @@ class Update extends core.Resource {
66
66
  * @param options The headers and the timeout to use for the download request.
67
67
  */
68
68
  async download(onEvent, options) {
69
- convertToRustHeaders(options);
70
69
  const channel = new core.Channel();
71
70
  if (onEvent) {
72
71
  channel.onmessage = onEvent;
@@ -74,8 +73,12 @@ class Update extends core.Resource {
74
73
  const downloadedBytesRid = await core.invoke('plugin:updater|download', {
75
74
  onEvent: channel,
76
75
  rid: this.rid,
77
- ...options
76
+ ...options,
77
+ headers: toRustHeaders(options?.headers)
78
78
  });
79
+ // release the bytes of a previous download, which would otherwise be kept
80
+ // in memory until the webview is destroyed
81
+ await this.downloadedBytes?.close().catch(() => { });
79
82
  this.downloadedBytes = new core.Resource(downloadedBytesRid);
80
83
  }
81
84
  /**
@@ -135,7 +138,6 @@ class Update extends core.Resource {
135
138
  * @param options The headers and the timeout to use for the download request, and the installation options.
136
139
  */
137
140
  async downloadAndInstall(onEvent, options) {
138
- convertToRustHeaders(options);
139
141
  const channel = new core.Channel();
140
142
  if (onEvent) {
141
143
  channel.onmessage = onEvent;
@@ -143,7 +145,8 @@ class Update extends core.Resource {
143
145
  await core.invoke('plugin:updater|download_and_install', {
144
146
  onEvent: channel,
145
147
  rid: this.rid,
146
- ...options
148
+ ...options,
149
+ headers: toRustHeaders(options?.headers)
147
150
  });
148
151
  }
149
152
  /**
@@ -185,19 +188,18 @@ class Update extends core.Resource {
185
188
  * @since 2.0.0
186
189
  */
187
190
  async function check(options) {
188
- convertToRustHeaders(options);
189
191
  const metadata = await core.invoke('plugin:updater|check', {
190
- ...options
192
+ ...options,
193
+ headers: toRustHeaders(options?.headers)
191
194
  });
192
195
  return metadata ? new Update(metadata) : null;
193
196
  }
194
197
  /**
195
- * Converts the headers in options to be an {@linkcode Array<[string, string]>} which is what the Rust side expects
198
+ * Converts headers to an {@linkcode Array<[string, string]>}, which is what the Rust side expects,
199
+ * without modifying the caller's options.
196
200
  */
197
- function convertToRustHeaders(options) {
198
- if (options?.headers) {
199
- options.headers = Array.from(new Headers(options.headers).entries());
200
- }
201
+ function toRustHeaders(headers) {
202
+ return headers ? Array.from(new Headers(headers).entries()) : undefined;
201
203
  }
202
204
 
203
205
  exports.Update = Update;
package/dist-js/index.js CHANGED
@@ -64,7 +64,6 @@ class Update extends Resource {
64
64
  * @param options The headers and the timeout to use for the download request.
65
65
  */
66
66
  async download(onEvent, options) {
67
- convertToRustHeaders(options);
68
67
  const channel = new Channel();
69
68
  if (onEvent) {
70
69
  channel.onmessage = onEvent;
@@ -72,8 +71,12 @@ class Update extends Resource {
72
71
  const downloadedBytesRid = await invoke('plugin:updater|download', {
73
72
  onEvent: channel,
74
73
  rid: this.rid,
75
- ...options
74
+ ...options,
75
+ headers: toRustHeaders(options?.headers)
76
76
  });
77
+ // release the bytes of a previous download, which would otherwise be kept
78
+ // in memory until the webview is destroyed
79
+ await this.downloadedBytes?.close().catch(() => { });
77
80
  this.downloadedBytes = new Resource(downloadedBytesRid);
78
81
  }
79
82
  /**
@@ -133,7 +136,6 @@ class Update extends Resource {
133
136
  * @param options The headers and the timeout to use for the download request, and the installation options.
134
137
  */
135
138
  async downloadAndInstall(onEvent, options) {
136
- convertToRustHeaders(options);
137
139
  const channel = new Channel();
138
140
  if (onEvent) {
139
141
  channel.onmessage = onEvent;
@@ -141,7 +143,8 @@ class Update extends Resource {
141
143
  await invoke('plugin:updater|download_and_install', {
142
144
  onEvent: channel,
143
145
  rid: this.rid,
144
- ...options
146
+ ...options,
147
+ headers: toRustHeaders(options?.headers)
145
148
  });
146
149
  }
147
150
  /**
@@ -183,19 +186,18 @@ class Update extends Resource {
183
186
  * @since 2.0.0
184
187
  */
185
188
  async function check(options) {
186
- convertToRustHeaders(options);
187
189
  const metadata = await invoke('plugin:updater|check', {
188
- ...options
190
+ ...options,
191
+ headers: toRustHeaders(options?.headers)
189
192
  });
190
193
  return metadata ? new Update(metadata) : null;
191
194
  }
192
195
  /**
193
- * Converts the headers in options to be an {@linkcode Array<[string, string]>} which is what the Rust side expects
196
+ * Converts headers to an {@linkcode Array<[string, string]>}, which is what the Rust side expects,
197
+ * without modifying the caller's options.
194
198
  */
195
- function convertToRustHeaders(options) {
196
- if (options?.headers) {
197
- options.headers = Array.from(new Headers(options.headers).entries());
198
- }
199
+ function toRustHeaders(headers) {
200
+ return headers ? Array.from(new Headers(headers).entries()) : undefined;
199
201
  }
200
202
 
201
203
  export { Update, check };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tauri-apps/plugin-updater",
3
- "version": "2.13.2",
3
+ "version": "2.14.0",
4
4
  "license": "MIT OR Apache-2.0",
5
5
  "authors": [
6
6
  "Tauri Programme within The Commons Conservancy"