@@ -28,8 +28,7 @@ pub enum DownloadEvent {
2828#[ derive( Serialize , Default ) ]
2929#[ serde( rename_all = "camelCase" ) ]
3030pub ( crate ) struct Metadata {
31- rid : Option < ResourceId > ,
32- available : bool ,
31+ rid : ResourceId ,
3332 current_version : String ,
3433 version : String ,
3534 date : Option < String > ,
@@ -40,16 +39,14 @@ pub(crate) struct Metadata {
4039struct DownloadedBytes ( pub Vec < u8 > ) ;
4140impl Resource for DownloadedBytes { }
4241
43- // TODO: Align this with the result of `updater.check` to Result<Option<Metadata>>
44- // and remove `available` instead of handling this in the js side
4542#[ tauri:: command]
4643pub ( crate ) async fn check < R : Runtime > (
4744 webview : Webview < R > ,
4845 headers : Option < Vec < ( String , String ) > > ,
4946 timeout : Option < u64 > ,
5047 proxy : Option < String > ,
5148 target : Option < String > ,
52- ) -> Result < Metadata > {
49+ ) -> Result < Option < Metadata > > {
5350 let mut builder = webview. updater_builder ( ) ;
5451 if let Some ( headers) = headers {
5552 for ( k, v) in headers {
@@ -69,18 +66,28 @@ pub(crate) async fn check<R: Runtime>(
6966
7067 let updater = builder. build ( ) ?;
7168 let update = updater. check ( ) . await ?;
72- let mut metadata = Metadata :: default ( ) ;
69+
7370 if let Some ( update) = update {
74- metadata. available = true ;
75- metadata. current_version . clone_from ( & update. current_version ) ;
76- metadata. version . clone_from ( & update. version ) ;
77- metadata. date = update. date . map ( |d| d. to_string ( ) ) ;
78- metadata. body . clone_from ( & update. body ) ;
79- metadata. raw_json . clone_from ( & update. raw_json ) ;
80- metadata. rid = Some ( webview. resources_table ( ) . add ( update) ) ;
71+ let formatted_date = if let Some ( date) = update. date {
72+ let formatted_date = date
73+ . format ( & time:: format_description:: well_known:: Rfc3339 )
74+ . map_err ( |_| crate :: Error :: FormatDate ) ?;
75+ Some ( formatted_date)
76+ } else {
77+ None
78+ } ;
79+ let metadata = Metadata {
80+ current_version : update. current_version . clone ( ) ,
81+ version : update. version . clone ( ) ,
82+ date : formatted_date,
83+ body : update. body . clone ( ) ,
84+ raw_json : update. raw_json . clone ( ) ,
85+ rid : webview. resources_table ( ) . add ( update) ,
86+ } ;
87+ Ok ( Some ( metadata) )
88+ } else {
89+ Ok ( None )
8190 }
82-
83- Ok ( metadata)
8491}
8592
8693#[ tauri:: command]
0 commit comments