@@ -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 */
134136async 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+
145154export type { CheckOptions , DownloadOptions , DownloadEvent }
146155export { check , Update }
0 commit comments