@@ -28,8 +28,7 @@ pub enum DownloadEvent {
28
28
#[ derive( Serialize , Default ) ]
29
29
#[ serde( rename_all = "camelCase" ) ]
30
30
pub ( crate ) struct Metadata {
31
- rid : Option < ResourceId > ,
32
- available : bool ,
31
+ rid : ResourceId ,
33
32
current_version : String ,
34
33
version : String ,
35
34
date : Option < String > ,
@@ -40,16 +39,14 @@ pub(crate) struct Metadata {
40
39
struct DownloadedBytes ( pub Vec < u8 > ) ;
41
40
impl Resource for DownloadedBytes { }
42
41
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
45
42
#[ tauri:: command]
46
43
pub ( crate ) async fn check < R : Runtime > (
47
44
webview : Webview < R > ,
48
45
headers : Option < Vec < ( String , String ) > > ,
49
46
timeout : Option < u64 > ,
50
47
proxy : Option < String > ,
51
48
target : Option < String > ,
52
- ) -> Result < Metadata > {
49
+ ) -> Result < Option < Metadata > > {
53
50
let mut builder = webview. updater_builder ( ) ;
54
51
if let Some ( headers) = headers {
55
52
for ( k, v) in headers {
@@ -69,18 +66,28 @@ pub(crate) async fn check<R: Runtime>(
69
66
70
67
let updater = builder. build ( ) ?;
71
68
let update = updater. check ( ) . await ?;
72
- let mut metadata = Metadata :: default ( ) ;
69
+
73
70
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 )
81
90
}
82
-
83
- Ok ( metadata)
84
91
}
85
92
86
93
#[ tauri:: command]
0 commit comments