@@ -81,6 +81,7 @@ class Update extends Resource {
81
81
onEvent ?: ( progress : DownloadEvent ) => void ,
82
82
options ?: DownloadOptions
83
83
) : Promise < void > {
84
+ convertToRustHeaders ( options )
84
85
const channel = new Channel < DownloadEvent > ( )
85
86
if ( onEvent ) {
86
87
channel . onmessage = onEvent
@@ -113,6 +114,7 @@ class Update extends Resource {
113
114
onEvent ?: ( progress : DownloadEvent ) => void ,
114
115
options ?: DownloadOptions
115
116
) : Promise < void > {
117
+ convertToRustHeaders ( options )
116
118
const channel = new Channel < DownloadEvent > ( )
117
119
if ( onEvent ) {
118
120
channel . onmessage = onEvent
@@ -132,15 +134,22 @@ class Update extends Resource {
132
134
133
135
/** Check for updates, resolves to `null` if no updates are available */
134
136
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 )
138
138
139
139
const metadata = await invoke < UpdateMetadata | null > ( 'plugin:updater|check' , {
140
140
...options
141
141
} )
142
142
return metadata ? new Update ( metadata ) : null
143
143
}
144
144
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
+
145
154
export type { CheckOptions , DownloadOptions , DownloadEvent }
146
155
export { check , Update }
0 commit comments