55
66#[ cfg( feature = "daemon" ) ]
77use {
8- crate :: constants:: DAEMON_STATE ,
9- crate :: runner:: Runner ,
10- crate :: types:: Platform ,
11- crate :: util:: serde:: value_or_default,
12- crate :: xcode:: { append_build_root, build_with_loggger} ,
13- crate :: Error ,
14- xcodebuild:: runner:: build_settings,
8+ crate :: constants:: DAEMON_STATE , crate :: run:: RunService , crate :: util:: serde:: value_or_default,
159} ;
1610
1711/// Run a project.
1812#[ derive( Debug , Serialize , Deserialize ) ]
19- pub struct Run {
13+ pub struct RunRequest {
2014 pub client : Client ,
2115 pub config : BuildConfiguration ,
2216 #[ cfg_attr( feature = "daemon" , serde( deserialize_with = "value_or_default" ) ) ]
@@ -27,72 +21,29 @@ pub struct Run {
2721
2822#[ cfg( feature = "daemon" ) ]
2923#[ async_trait:: async_trait]
30- impl Handler for Run {
24+ impl Handler for RunRequest {
3125 async fn handle ( self ) -> Result < ( ) > {
32- let Client { root, .. } = & self . client ;
33-
34- tracing:: info!( "⚙️ Running command: {}" , self . config. to_string( ) ) ;
26+ tracing:: info!( "⚙️ Running: {}" , self . config. to_string( ) ) ;
3527
3628 let state = DAEMON_STATE . clone ( ) ;
37- let ref state = state. lock ( ) . await ;
38- let device = state. devices . from_lookup ( self . device ) ;
39-
40- let nvim = self . client . nvim ( state) ?;
41- let args = {
42- let mut args = self . config . as_args ( ) ;
43- if let Some ( ref device) = device {
44- args. extend ( device. special_build_args ( ) )
45- }
46- append_build_root ( & root, args) ?
47- } ;
48-
49- let ref mut logger = nvim. logger ( ) ;
29+ let ref mut state = state. lock ( ) . await ;
5030
51- logger . set_title ( format ! ( "Run:{}" , self . config . target ) ) ;
52- logger . set_direction ( & self . direction ) ;
31+ // TODO: Insert runner into state.runners
32+ RunService :: new ( state , self ) . await ? ;
5333
54- let settings = build_settings ( & root, & args) . await ?;
55- let platform = device
56- . as_ref ( )
57- . map ( |d| d. platform . clone ( ) )
58- . unwrap_or_else ( || Platform :: from_display ( & settings. platform_display_name ) . unwrap ( ) ) ;
59-
60- let success = build_with_loggger ( logger, & root, & args, true , true ) . await ?;
61- if !success {
62- let msg = format ! ( "Failed: {} " , self . config. to_string( ) ) ;
63- nvim. echo_err ( & msg) . await ?;
64- return Err ( Error :: Build ( msg) ) ;
65- }
66-
67- // TODO(daemon): insert handler to state.runners
68- // TODO(nvim): provide mapping to close runners.
69- //
70- // If there is more then one runner then pick, else close from current buffer.
71- // C-c in normal/insert mode should close that process
72- Runner {
73- target : self . config . target ,
74- platform,
75- client : self . client ,
76- args,
77- udid : device. map ( |d| d. udid . clone ( ) ) ,
78- direction : self . direction ,
79- }
80- . run ( state, settings)
81- . await ?;
82-
83- Ok ( ( ) )
34+ todo ! ( ) ;
8435 }
8536}
8637
8738#[ cfg( feature = "lua" ) ]
88- impl < ' a > Requester < ' a , Run > for Run {
89- fn pre ( lua : & Lua , msg : & Run ) -> LuaResult < ( ) > {
39+ impl < ' a > Requester < ' a , RunRequest > for RunRequest {
40+ fn pre ( lua : & Lua , msg : & RunRequest ) -> LuaResult < ( ) > {
9041 lua. print ( & msg. to_string ( ) ) ;
9142 Ok ( ( ) )
9243 }
9344}
9445
95- impl ToString for Run {
46+ impl ToString for RunRequest {
9647 fn to_string ( & self ) -> String {
9748 if let Some ( ref name) = self . device . name {
9849 format ! ( "run [{}] with {}" , name, self . config. to_string( ) )
@@ -103,7 +54,7 @@ impl ToString for Run {
10354}
10455
10556#[ cfg( feature = "lua" ) ]
106- impl < ' a > FromLua < ' a > for Run {
57+ impl < ' a > FromLua < ' a > for RunRequest {
10758 fn from_lua ( lua_value : LuaValue < ' a > , _lua : & ' a Lua ) -> LuaResult < Self > {
10859 let table = match lua_value {
10960 LuaValue :: Table ( t) => Ok ( t) ,
0 commit comments