11use std:: {
2- cell:: { LazyCell , RefCell } , collections:: BTreeMap , io, path:: { Path , PathBuf } , process:: Output , rc:: Rc , str:: FromStr
2+ cell:: LazyCell , collections:: BTreeMap , future :: Future , io, path:: { Path , PathBuf } , pin :: Pin , process:: Output , rc:: Rc , str:: FromStr
33} ;
44use tracing:: { debug, error, info, warn} ;
5+ use crate :: fakers:: { CommandRunner , NullCommandRunnerBuilder , Command , Child , InnerCommandRunner , FdMode } ;
56
6- mod command;
7- mod command_runner;
87mod desktop_file;
98
10- pub use command:: * ;
11- pub use command_runner:: * ;
129pub use desktop_file:: * ;
1310
14- #[ derive( Default , Clone , Debug ) ]
15- pub struct OutputTracker < T > {
16- store : Rc < RefCell < Option < Vec < T > > > > ,
17- }
1811
19- impl < T > OutputTracker < T > {
20- pub fn new ( ) -> Self {
21- OutputTracker {
22- store : Rc :: new ( RefCell :: new ( None ) ) ,
23- }
12+ #[ derive( Clone ) ]
13+ pub struct FlatpakCommandRunner {
14+ pub command_runner : Rc < dyn InnerCommandRunner > ,
15+ }
16+ impl FlatpakCommandRunner {
17+ pub fn new ( command_runner : Rc < dyn InnerCommandRunner > ) -> Self {
18+ FlatpakCommandRunner { command_runner }
2419 }
25- pub fn len ( & self ) -> usize {
26- if let Some ( v) = & * self . store . borrow ( ) {
27- v. len ( )
28- } else {
29- 0
30- }
20+
21+ pub fn wrap_flatpak_cmd ( mut prev : Command ) -> Command {
22+ let mut args = vec ! [ "--host" . into( ) , prev. program] ;
23+ args. extend ( prev. args ) ;
24+
25+ prev. args = args;
26+ prev. program = "flatpak-spawn" . into ( ) ;
27+ prev
3128 }
3229}
3330
34- impl < T : Clone + std:: fmt:: Debug > OutputTracker < T > {
35- pub fn enable ( & self ) {
36- let mut inner = self . store . borrow_mut ( ) ;
37- if inner. is_none ( ) {
38- * inner = Some ( vec ! [ ] ) ;
39- }
40- }
41- pub fn push ( & self , item : T ) {
42- if let Some ( v) = & mut * self . store . borrow_mut ( ) {
43- v. push ( item) ;
44- }
31+ impl InnerCommandRunner for FlatpakCommandRunner {
32+ fn spawn ( & self , command : Command ) -> io:: Result < Box < dyn Child + Send > > {
33+ self . command_runner . spawn ( Self :: wrap_flatpak_cmd ( command) )
4534 }
46- pub fn items ( & self ) -> Vec < T > {
47- if let Some ( v) = & * self . store . borrow ( ) {
48- v. clone ( )
49- } else {
50- vec ! [ ]
51- }
35+ fn output (
36+ & self ,
37+ command : Command ,
38+ ) -> Pin < Box < dyn Future < Output = io:: Result < std:: process:: Output > > > > {
39+ self . command_runner . output ( Self :: wrap_flatpak_cmd ( command) )
5240 }
5341}
5442
43+
5544pub struct Distrobox {
5645 cmd_runner : CommandRunner ,
5746}
@@ -497,7 +486,8 @@ impl Distrobox {
497486 }
498487
499488 pub fn cmd_spawn ( & self , mut cmd : Command ) -> Result < Box < dyn Child + Send > , Error > {
500- wrap_capture_cmd ( & mut cmd) ;
489+ cmd. stdout = FdMode :: Pipe ;
490+ cmd. stderr = FdMode :: Pipe ;
501491
502492 let program = cmd. program . to_string_lossy ( ) . to_string ( ) ;
503493 let args = cmd
@@ -520,7 +510,8 @@ impl Distrobox {
520510 }
521511
522512 async fn cmd_output ( & self , mut cmd : Command ) -> Result < Output , Error > {
523- wrap_capture_cmd ( & mut cmd) ;
513+ cmd. stdout = FdMode :: Pipe ;
514+ cmd. stderr = FdMode :: Pipe ;
524515
525516 let program = cmd. program . to_string_lossy ( ) . to_string ( ) ;
526517 let args = cmd
0 commit comments