Skip to content

Commit 73ff15d

Browse files
fix(updater): fix headers option in Updater.download (#2757)
1 parent ff19aff commit 73ff15d

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"updater": patch
3+
"updater-js": patch
4+
---
5+
6+
Fix headers option in `Update.download` and `Update.downloadAndInstall` doesn't work with `Record<string, string> | Headers` types

plugins/updater/api-iife.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/updater/guest-js/index.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class Update extends Resource {
8181
onEvent?: (progress: DownloadEvent) => void,
8282
options?: DownloadOptions
8383
): Promise<void> {
84+
convertToRustHeaders(options)
8485
const channel = new Channel<DownloadEvent>()
8586
if (onEvent) {
8687
channel.onmessage = onEvent
@@ -113,6 +114,7 @@ class Update extends Resource {
113114
onEvent?: (progress: DownloadEvent) => void,
114115
options?: DownloadOptions
115116
): Promise<void> {
117+
convertToRustHeaders(options)
116118
const channel = new Channel<DownloadEvent>()
117119
if (onEvent) {
118120
channel.onmessage = onEvent
@@ -132,15 +134,22 @@ class Update extends Resource {
132134

133135
/** Check for updates, resolves to `null` if no updates are available */
134136
async function check(options?: CheckOptions): Promise<Update | null> {
135-
if (options?.headers) {
136-
options.headers = Array.from(new Headers(options.headers).entries())
137-
}
137+
convertToRustHeaders(options)
138138

139139
const metadata = await invoke<UpdateMetadata | null>('plugin:updater|check', {
140140
...options
141141
})
142142
return metadata ? new Update(metadata) : null
143143
}
144144

145+
/**
146+
* Converts the headers in options to be an {@linkcode Array<[string, string]>} which is what the Rust side expects
147+
*/
148+
function convertToRustHeaders(options?: { headers?: HeadersInit }) {
149+
if (options?.headers) {
150+
options.headers = Array.from(new Headers(options.headers).entries())
151+
}
152+
}
153+
145154
export type { CheckOptions, DownloadOptions, DownloadEvent }
146155
export { check, Update }

0 commit comments

Comments
 (0)