11use crate :: {
22 distrobox:: { ContainerInfo , ExportableApp , Status } ,
33 distrobox_task:: DistroboxTask ,
4+ fakers:: CommandRunner ,
45 known_distros:: { known_distro_by_image, KnownDistro } ,
5- remote_resource :: RemoteResource ,
6+ query :: Query ,
67 root_store:: RootStore ,
78 fakers:: Command
89} ;
@@ -15,15 +16,14 @@ use gtk::{
1516use adw:: prelude:: * ;
1617use glib:: subclass:: prelude:: * ;
1718use gtk:: glib;
18- use std:: { cell:: RefCell , path:: Path } ;
19+ use std:: cell:: RefCell ;
20+ use std:: path:: Path ;
1921
2022mod imp {
21- use crate :: remote_resource:: RemoteResource ;
22-
2323 use super :: * ;
2424
2525 // This contains all the container informations given by distrobox, plus an associated KnownDistro struct
26- #[ derive( Default , Properties ) ]
26+ #[ derive( Properties ) ]
2727 #[ properties( wrapper_type=super :: Container ) ]
2828 pub struct Container {
2929 #[ property( get, set) ]
@@ -38,10 +38,27 @@ mod imp {
3838 pub image : RefCell < String > ,
3939 #[ property( get, set) ]
4040 pub distro : RefCell < Option < KnownDistro > > ,
41- #[ property( get, set) ]
42- pub apps : RefCell < RemoteResource > ,
43- #[ property( get, set) ]
44- pub binaries : RefCell < RemoteResource > ,
41+ pub apps : Query < gio:: ListStore , anyhow:: Error > ,
42+ pub binaries : Query < gio:: ListStore , anyhow:: Error > ,
43+ }
44+
45+ impl Default for Container {
46+ fn default ( ) -> Self {
47+ Self {
48+ root_store : RefCell :: new ( RootStore :: new ( CommandRunner :: new_null ( ) ) ) ,
49+ name : RefCell :: new ( String :: new ( ) ) ,
50+ status_tag : RefCell :: new ( String :: new ( ) ) ,
51+ status_detail : RefCell :: new ( String :: new ( ) ) ,
52+ image : RefCell :: new ( String :: new ( ) ) ,
53+ distro : RefCell :: new ( None ) ,
54+ apps : Query :: new ( "apps" . into ( ) , || async {
55+ Ok ( gio:: ListStore :: new :: < BoxedAnyObject > ( ) )
56+ } ) ,
57+ binaries : Query :: new ( "binaries" . into ( ) , || async {
58+ Ok ( gio:: ListStore :: new :: < BoxedAnyObject > ( ) )
59+ } ) ,
60+ }
61+ }
4562 }
4663
4764 #[ derived_properties]
@@ -80,54 +97,54 @@ impl Container {
8097 . build ( ) ;
8198
8299 let this_clone = this. clone ( ) ;
83- let loader = move |apps_list : Option < & gio :: ListStore > | {
100+ this . apps ( ) . set_fetcher ( move || {
84101 let this = this_clone. clone ( ) ;
85- let mut apps_list = apps_list
86- . cloned ( )
87- . unwrap_or_else ( gio:: ListStore :: new :: < BoxedAnyObject > ) ;
88102 async move {
89103 let apps = this
90104 . root_store ( )
91105 . distrobox ( )
92106 . list_apps ( & this. name ( ) )
93107 . await ?;
94108
95- apps_list. remove_all ( ) ;
109+ let mut apps_list = gio :: ListStore :: new :: < BoxedAnyObject > ( ) ;
96110 apps_list. extend ( apps. into_iter ( ) . map ( BoxedAnyObject :: new) ) ;
97111
98112 // Listing the apps starts the container, we need to update its status
99113 this. root_store ( ) . load_containers ( ) ;
100114 Ok ( apps_list)
101115 }
102- } ;
103- this. set_apps ( RemoteResource :: new :: < gio:: ListStore , _ > ( loader) ) ;
116+ } ) ;
104117
105118 let this_clone = this. clone ( ) ;
106- let binaries_loader = move |binaries_list : Option < & gio :: ListStore > | {
119+ this . binaries ( ) . set_fetcher ( move || {
107120 let this = this_clone. clone ( ) ;
108- let mut binaries_list = binaries_list
109- . cloned ( )
110- . unwrap_or_else ( gio:: ListStore :: new :: < BoxedAnyObject > ) ;
111121 async move {
112122 let binaries = this
113123 . root_store ( )
114124 . distrobox ( )
115125 . get_exported_binaries ( & this. name ( ) )
116126 . await ?;
117127
118- binaries_list. remove_all ( ) ;
128+ let mut binaries_list = gio :: ListStore :: new :: < BoxedAnyObject > ( ) ;
119129 binaries_list. extend ( binaries. into_iter ( ) . map ( BoxedAnyObject :: new) ) ;
120130
121131 // Listing the binaries starts the container, we need to update its status
122132 this. root_store ( ) . load_containers ( ) ;
123133 Ok ( binaries_list)
124134 }
125- } ;
126- this. set_binaries ( RemoteResource :: new :: < gio:: ListStore , _ > ( binaries_loader) ) ;
135+ } ) ;
127136
128137 this
129138 }
130139
140+ pub fn apps ( & self ) -> Query < gio:: ListStore , anyhow:: Error > {
141+ self . imp ( ) . apps . clone ( )
142+ }
143+
144+ pub fn binaries ( & self ) -> Query < gio:: ListStore , anyhow:: Error > {
145+ self . imp ( ) . binaries . clone ( )
146+ }
147+
131148 pub fn upgrade ( & self ) -> DistroboxTask {
132149 let this = self . clone ( ) ;
133150 self . root_store ( )
@@ -192,7 +209,7 @@ impl Container {
192209 . distrobox ( )
193210 . export_app ( & this. name ( ) , & desktop_file_path)
194211 . await ?;
195- this. apps ( ) . reload ( ) ;
212+ this. apps ( ) . refetch ( ) ;
196213 Ok ( ( ) )
197214 } ) ;
198215 }
@@ -205,7 +222,7 @@ impl Container {
205222 . distrobox ( )
206223 . unexport_app ( & this. name ( ) , & desktop_file_path)
207224 . await ?;
208- this. apps ( ) . reload ( ) ;
225+ this. apps ( ) . refetch ( ) ;
209226 Ok ( ( ) )
210227 } ) ;
211228 }
@@ -218,7 +235,7 @@ impl Container {
218235 . distrobox ( )
219236 . export_binary ( & this. name ( ) , & binary_path)
220237 . await ?;
221- this. binaries ( ) . reload ( ) ;
238+ this. binaries ( ) . refetch ( ) ;
222239 Ok ( ( ) )
223240 } )
224241 }
@@ -231,7 +248,7 @@ impl Container {
231248 . distrobox ( )
232249 . unexport_binary ( & this. name ( ) , & binary_path)
233250 . await ?;
234- this. binaries ( ) . reload ( ) ;
251+ this. binaries ( ) . refetch ( ) ;
235252 Ok ( ( ) )
236253 } ) ;
237254 }
0 commit comments