@@ -5,13 +5,18 @@ pub struct ProgressInfo {
55 app_ref : String ,
66 message : String ,
77 progress : f32 ,
8- app : RunApp ,
98 temp_repo : PathBuf ,
109 deps_repo : PathBuf ,
11- is_loading : bool ,
10+ app_state : AppState ,
1211 process : Option < rustix:: process:: Pid > ,
1312}
1413
14+ #[ derive( Clone , Debug ) ]
15+ pub enum AppState {
16+ LoadingFile ( RunApp ) ,
17+ Done ,
18+ }
19+
1520#[ derive( Clone , Debug ) ]
1621pub enum RunApp {
1722 Bundle ( PathBuf ) ,
@@ -25,20 +30,20 @@ pub enum Message {
2530 Close ,
2631}
2732
28- use std:: { path:: PathBuf , process:: Child } ;
33+ use std:: { future :: IntoFuture , path:: PathBuf , process:: Child } ;
2934
3035use async_std:: task:: spawn;
3136use iced:: {
3237 command, executor,
3338 futures:: SinkExt ,
3439 subscription,
3540 widget:: { button, column, row, text} ,
36- window, Alignment , Application , Command , Element , Length , Theme ,
41+ window, Alignment , Application , Command , Element , Length , Subscription , Theme ,
3742} ;
3843
3944impl Application for ProgressInfo {
4045 type Executor = executor:: Default ;
41- type Flags = ( RunApp , PathBuf , PathBuf ) ;
46+ type Flags = ( PathBuf , PathBuf , AppState ) ;
4247 type Message = Message ;
4348 type Theme = Theme ;
4449
@@ -50,10 +55,9 @@ impl Application for ProgressInfo {
5055 app_ref : "" . into ( ) ,
5156 message : "" . into ( ) ,
5257 progress : 0.0 ,
53- app : flags. 0 ,
54- temp_repo : flags. 1 ,
55- deps_repo : flags. 2 ,
56- is_loading : true ,
58+ temp_repo : flags. 0 ,
59+ deps_repo : flags. 1 ,
60+ app_state : flags. 2 ,
5761 process : None ,
5862 } ,
5963 Command :: none ( ) ,
@@ -65,45 +69,48 @@ impl Application for ProgressInfo {
6569 }
6670
6771 fn view ( & self ) -> Element < Message > {
68- if self . is_loading {
69- column ! [
70- text( "Flatrun: Run flatpaks without installing" )
71- . horizontal_alignment( iced:: alignment:: Horizontal :: Center ) ,
72- row![
73- text( & self . repo)
74- . horizontal_alignment( iced:: alignment:: Horizontal :: Left )
75- . width( Length :: Fill ) ,
76- text( & self . action)
77- . horizontal_alignment( iced:: alignment:: Horizontal :: Right )
78- . width( Length :: Fill ) ,
79- ]
80- . width( Length :: Fill ) ,
81- row![
82- text( & self . app_ref)
83- . horizontal_alignment( iced:: alignment:: Horizontal :: Left )
84- . width( Length :: Fill ) ,
85- text( & self . message)
86- . horizontal_alignment( iced:: alignment:: Horizontal :: Right )
87- . width( Length :: Fill ) ,
72+ match self . app_state {
73+ AppState :: LoadingFile ( _) => {
74+ column ! [
75+ text( "Flatrun: Run flatpaks without installing" )
76+ . horizontal_alignment( iced:: alignment:: Horizontal :: Center ) ,
77+ row![
78+ text( & self . repo)
79+ . horizontal_alignment( iced:: alignment:: Horizontal :: Left )
80+ . width( Length :: Fill ) ,
81+ text( & self . action)
82+ . horizontal_alignment( iced:: alignment:: Horizontal :: Right )
83+ . width( Length :: Fill ) ,
84+ ]
85+ . width( Length :: Fill ) ,
86+ row![
87+ text( & self . app_ref)
88+ . horizontal_alignment( iced:: alignment:: Horizontal :: Left )
89+ . width( Length :: Fill ) ,
90+ text( & self . message)
91+ . horizontal_alignment( iced:: alignment:: Horizontal :: Right )
92+ . width( Length :: Fill ) ,
93+ ]
94+ . width( Length :: Fill ) ,
95+ iced:: widget:: progress_bar( 0.0 ..=1.0 , self . progress) . width( Length :: Fill ) ,
8896 ]
89- . width( Length :: Fill ) ,
90- iced:: widget:: progress_bar( 0.0 ..=1.0 , self . progress) . width( Length :: Fill ) ,
91- ]
92- } else {
93- column ! [
94- text( "Flatrun: Run flatpaks without installing" )
95- . horizontal_alignment( iced:: alignment:: Horizontal :: Center ) ,
96- row![
97- text( & self . app_ref)
98- . horizontal_alignment( iced:: alignment:: Horizontal :: Left )
99- . width( Length :: Fill ) ,
100- text( "Running Application" )
101- . horizontal_alignment( iced:: alignment:: Horizontal :: Right )
102- . width( Length :: Fill ) ,
97+ }
98+ AppState :: Done => {
99+ column ! [
100+ text( "Flatrun: Run flatpaks without installing" )
101+ . horizontal_alignment( iced:: alignment:: Horizontal :: Center ) ,
102+ row![
103+ text( & self . app_ref)
104+ . horizontal_alignment( iced:: alignment:: Horizontal :: Left )
105+ . width( Length :: Fill ) ,
106+ text( "Running Application" )
107+ . horizontal_alignment( iced:: alignment:: Horizontal :: Right )
108+ . width( Length :: Fill ) ,
109+ ]
110+ . width( Length :: Fill ) ,
111+ button( text( format!( "Close {}" , & self . app_ref) ) ) . on_press( Message :: Close )
103112 ]
104- . width( Length :: Fill ) ,
105- button( text( format!( "Close {}" , & self . app_ref) ) ) . on_press( Message :: Close )
106- ]
113+ }
107114 }
108115 . padding ( 32 )
109116 . align_items ( Alignment :: Center )
@@ -124,7 +131,7 @@ impl Application for ProgressInfo {
124131 Command :: none ( )
125132 }
126133 Message :: Finished ( pid) => {
127- self . is_loading = false ;
134+ self . app_state = AppState :: Done ;
128135 self . process = Some ( pid) ;
129136 Command :: none ( )
130137 }
@@ -147,34 +154,37 @@ impl Application for ProgressInfo {
147154 }
148155
149156 fn subscription ( & self ) -> iced:: Subscription < Self :: Message > {
150- let app = self . app . clone ( ) ;
151- let ( temp_repo, deps_repo) = ( self . temp_repo . clone ( ) , self . deps_repo . clone ( ) ) ;
152- subscription:: channel (
153- std:: any:: TypeId :: of :: < Message > ( ) ,
154- 50 ,
155- move |mut output| async move {
156- match app {
157- RunApp :: Bundle ( path) => {
158- spawn ( async move {
159- crate :: run_bundle_inner (
160- & temp_repo,
161- & deps_repo,
162- & path,
163- & mut Some ( & mut output) ,
164- )
165- . await
166- . unwrap ( ) ;
167- let _ = output. send ( Message :: Close ) . await ;
168- } ) ;
157+ if let AppState :: LoadingFile ( f) = self . app_state . clone ( ) {
158+ let ( temp_repo, deps_repo) = ( self . temp_repo . clone ( ) , self . deps_repo . clone ( ) ) ;
159+ subscription:: channel (
160+ std:: any:: TypeId :: of :: < Message > ( ) ,
161+ 50 ,
162+ move |mut output| async move {
163+ match f {
164+ RunApp :: Bundle ( path) => {
165+ spawn ( async move {
166+ crate :: run_bundle_inner (
167+ & temp_repo,
168+ & deps_repo,
169+ & path,
170+ & mut Some ( & mut output) ,
171+ )
172+ . await
173+ . unwrap ( ) ;
174+ let _ = output. send ( Message :: Close ) . await ;
175+ } ) ;
176+ }
177+ RunApp :: Download ( appid) => {
178+ // TODO
179+ }
169180 }
170- RunApp :: Download ( appid ) => {
171- // TODO
181+ loop {
182+ async_std :: future :: pending :: < i32 > ( ) . await ;
172183 }
173- }
174- loop {
175- async_std:: future:: pending :: < i32 > ( ) . await ;
176- }
177- } ,
178- )
184+ } ,
185+ )
186+ } else {
187+ Subscription :: none ( )
188+ }
179189 }
180190}
0 commit comments