@@ -20,6 +20,8 @@ use std::cell::RefCell;
2020use std:: path:: Path ;
2121
2222mod imp {
23+ use std:: time:: Duration ;
24+
2325 use super :: * ;
2426
2527 // This contains all the container informations given by distrobox, plus an associated KnownDistro struct
@@ -36,10 +38,10 @@ mod imp {
3638 pub status_detail : RefCell < String > ,
3739 #[ property( get, set) ]
3840 pub image : RefCell < String > ,
39- #[ property( get, set) ]
41+ #[ property( get, set, nullable ) ]
4042 pub distro : RefCell < Option < KnownDistro > > ,
41- pub apps : Query < TypedListStore < glib:: BoxedAnyObject > , anyhow :: Error > ,
42- pub binaries : Query < TypedListStore < glib:: BoxedAnyObject > , anyhow :: Error > ,
43+ pub apps : Query < TypedListStore < glib:: BoxedAnyObject > > ,
44+ pub binaries : Query < TypedListStore < glib:: BoxedAnyObject > > ,
4345 }
4446
4547 impl Default for Container {
@@ -51,11 +53,26 @@ mod imp {
5153 status_detail : RefCell :: new ( String :: new ( ) ) ,
5254 image : RefCell :: new ( String :: new ( ) ) ,
5355 distro : RefCell :: new ( None ) ,
56+
57+ // Fetching apps often fails when the container is not running and distrobox has to start it,
58+ // so we add retries
5459 apps : Query :: new ( "apps" . into ( ) , || async {
5560 Ok ( TypedListStore :: new ( ) )
61+ } )
62+ . with_timeout ( Duration :: from_secs ( 1 ) )
63+ . with_retry_strategy ( |n| if n < 3 {
64+ Some ( Duration :: from_secs ( n as u64 ) )
65+ } else {
66+ None
5667 } ) ,
5768 binaries : Query :: new ( "binaries" . into ( ) , || async {
5869 Ok ( TypedListStore :: new ( ) )
70+ } )
71+ . with_timeout ( Duration :: from_secs ( 1 ) )
72+ . with_retry_strategy ( |n| if n < 3 {
73+ Some ( Duration :: from_secs ( n as u64 ) )
74+ } else {
75+ None
5976 } ) ,
6077 }
6178 }
@@ -79,23 +96,12 @@ impl Container {
7996 glib:: Object :: builder ( ) . build ( )
8097 }
8198 pub fn from_info ( root_store : & RootStore , value : ContainerInfo ) -> Self {
82- let distro = known_distro_by_image ( & value. image ) ;
83-
84- let ( status_tag, status_detail) = match value. status {
85- Status :: Up ( v) => ( "up" , v) ,
86- Status :: Created ( v) => ( "created" , v) ,
87- Status :: Exited ( v) => ( "exited" , v) ,
88- Status :: Other ( v) => ( "other" , v) ,
89- } ;
9099 let this: Self = glib:: Object :: builder ( )
91100 . property ( "root-store" , root_store)
92- . property ( "name" , value. name )
93- . property ( "image" , value. image )
94- . property ( "distro" , distro)
95- . property ( "status-tag" , status_tag)
96- . property ( "status-detail" , status_detail)
97101 . build ( ) ;
98102
103+ this. apply_container_info ( value) ;
104+
99105 let this_clone = this. clone ( ) ;
100106 this. apps ( ) . set_fetcher ( move || {
101107 let this = this_clone. clone ( ) ;
@@ -135,11 +141,28 @@ impl Container {
135141 this
136142 }
137143
138- pub fn apps ( & self ) -> Query < TypedListStore < BoxedAnyObject > , anyhow:: Error > {
144+ pub fn apply_container_info ( & self , value : ContainerInfo ) {
145+ let distro = known_distro_by_image ( & value. image ) ;
146+
147+ let ( status_tag, status_detail) = match value. status {
148+ Status :: Up ( v) => ( "up" , v) ,
149+ Status :: Created ( v) => ( "created" , v) ,
150+ Status :: Exited ( v) => ( "exited" , v) ,
151+ Status :: Other ( v) => ( "other" , v) ,
152+ } ;
153+
154+ self . set_name ( value. name ) ;
155+ self . set_image ( value. image ) ;
156+ self . set_distro ( distro) ;
157+ self . set_status_tag ( status_tag. to_string ( ) ) ;
158+ self . set_status_detail ( status_detail) ;
159+ }
160+
161+ pub fn apps ( & self ) -> Query < TypedListStore < BoxedAnyObject > > {
139162 self . imp ( ) . apps . clone ( )
140163 }
141164
142- pub fn binaries ( & self ) -> Query < TypedListStore < BoxedAnyObject > , anyhow :: Error > {
165+ pub fn binaries ( & self ) -> Query < TypedListStore < BoxedAnyObject > > {
143166 self . imp ( ) . binaries . clone ( )
144167 }
145168
0 commit comments