44
55use crate :: { Result , Update , UpdaterExt } ;
66
7+ use http:: { HeaderMap , HeaderName , HeaderValue } ;
78use serde:: Serialize ;
89use tauri:: { ipc:: Channel , Manager , Resource , ResourceId , Runtime , Webview } ;
910
10- use std:: time:: Duration ;
11+ use std:: { str :: FromStr , time:: Duration } ;
1112use url:: Url ;
1213
1314#[ derive( Debug , Clone , Serialize ) ]
@@ -53,7 +54,7 @@ pub(crate) async fn check<R: Runtime>(
5354 }
5455 }
5556 if let Some ( timeout) = timeout {
56- builder = builder. timeout ( Duration :: from_secs ( timeout) ) ;
57+ builder = builder. timeout ( Duration :: from_millis ( timeout) ) ;
5758 }
5859 if let Some ( ref proxy) = proxy {
5960 let url = Url :: parse ( proxy. as_str ( ) ) ?;
@@ -83,8 +84,25 @@ pub(crate) async fn download<R: Runtime>(
8384 webview : Webview < R > ,
8485 rid : ResourceId ,
8586 on_event : Channel < DownloadEvent > ,
87+ headers : Option < Vec < ( String , String ) > > ,
88+ timeout : Option < u64 > ,
8689) -> Result < ResourceId > {
8790 let update = webview. resources_table ( ) . get :: < Update > ( rid) ?;
91+
92+ let mut update = ( * update) . clone ( ) ;
93+
94+ if let Some ( headers) = headers {
95+ let mut map = HeaderMap :: new ( ) ;
96+ for ( k, v) in headers {
97+ map. append ( HeaderName :: from_str ( & k) ?, HeaderValue :: from_str ( & v) ?) ;
98+ }
99+ update. headers = map;
100+ }
101+
102+ if let Some ( timeout) = timeout {
103+ update. timeout = Some ( Duration :: from_millis ( timeout) ) ;
104+ }
105+
88106 let mut first_chunk = true ;
89107 let bytes = update
90108 . download (
@@ -100,6 +118,7 @@ pub(crate) async fn download<R: Runtime>(
100118 } ,
101119 )
102120 . await ?;
121+
103122 Ok ( webview. resources_table ( ) . add ( DownloadedBytes ( bytes) ) )
104123}
105124
@@ -123,9 +142,25 @@ pub(crate) async fn download_and_install<R: Runtime>(
123142 webview : Webview < R > ,
124143 rid : ResourceId ,
125144 on_event : Channel < DownloadEvent > ,
145+ headers : Option < Vec < ( String , String ) > > ,
146+ timeout : Option < u64 > ,
126147) -> Result < ( ) > {
127148 let update = webview. resources_table ( ) . get :: < Update > ( rid) ?;
128149
150+ let mut update = ( * update) . clone ( ) ;
151+
152+ if let Some ( headers) = headers {
153+ let mut map = HeaderMap :: new ( ) ;
154+ for ( k, v) in headers {
155+ map. append ( HeaderName :: from_str ( & k) ?, HeaderValue :: from_str ( & v) ?) ;
156+ }
157+ update. headers = map;
158+ }
159+
160+ if let Some ( timeout) = timeout {
161+ update. timeout = Some ( Duration :: from_millis ( timeout) ) ;
162+ }
163+
129164 let mut first_chunk = true ;
130165
131166 update
0 commit comments