@@ -6,9 +6,40 @@ use color_eyre::eyre::Result;
66
77use crate :: { run:: FrameUpdate , tattoys:: gpu:: shaderer:: Shaderer as _} ;
88
9+ /// Start all the enabled tattoys.
10+ pub ( crate ) async fn start_tattoys (
11+ enabled_tattoys : Vec < String > ,
12+ output : tokio:: sync:: mpsc:: Sender < FrameUpdate > ,
13+ state : Arc < crate :: shared_state:: SharedState > ,
14+ ) -> std:: thread:: JoinHandle < Result < ( ) , color_eyre:: eyre:: Error > > {
15+ convert_cli_enabled_args ( & enabled_tattoys, & state) . await ;
16+ let handle = spawn ( enabled_tattoys. clone ( ) , output, Arc :: clone ( & state) ) ;
17+ wait_for_enabled_tattoys_to_start ( enabled_tattoys, & state) . await ;
18+ handle
19+ }
20+
21+ /// Centralise all "enabled" settings into the state config. Saves us having to check both the CLI
22+ /// and state everytime.
23+ async fn convert_cli_enabled_args (
24+ enabled_tattoys : & Vec < String > ,
25+ state : & Arc < crate :: shared_state:: SharedState > ,
26+ ) {
27+ for tattoy in enabled_tattoys {
28+ match tattoy. as_ref ( ) {
29+ "startup_logo" => state. config . write ( ) . await . show_startup_logo = true ,
30+ "notifications" => state. config . write ( ) . await . notifications . enabled = true ,
31+ "minimap" => state. config . write ( ) . await . minimap . enabled = true ,
32+ "shaders" => state. config . write ( ) . await . shader . enabled = true ,
33+ "animated_cursor" => state. config . write ( ) . await . animated_cursor . enabled = true ,
34+ "bg_command" => state. config . write ( ) . await . bg_command . enabled = true ,
35+ _ => ( ) ,
36+ }
37+ }
38+ }
39+
940/// Start the main loader thread
1041#[ expect( clippy:: too_many_lines, reason = "It's mostly repetitive" ) ]
11- pub ( crate ) fn start_tattoys (
42+ pub ( crate ) fn spawn (
1243 enabled_tattoys : Vec < String > ,
1344 output : tokio:: sync:: mpsc:: Sender < FrameUpdate > ,
1445 state : Arc < crate :: shared_state:: SharedState > ,
@@ -21,9 +52,7 @@ pub(crate) fn start_tattoys(
2152 let palette = crate :: config:: main:: Config :: load_palette ( Arc :: clone ( & state) ) . await ?;
2253 let mut tattoy_futures = tokio:: task:: JoinSet :: new ( ) ;
2354
24- if enabled_tattoys. contains ( & "startup_logo" . to_owned ( ) )
25- || state. config . read ( ) . await . show_startup_logo
26- {
55+ if state. config . read ( ) . await . show_startup_logo {
2756 tracing:: info!( "Starting 'startup_logo' tattoy..." ) ;
2857 tattoy_futures. spawn ( crate :: tattoys:: startup_logo:: StartupLogo :: start (
2958 output. clone ( ) ,
@@ -32,9 +61,7 @@ pub(crate) fn start_tattoys(
3261 ) ) ;
3362 }
3463
35- if enabled_tattoys. contains ( & "notifications" . to_owned ( ) )
36- || state. config . read ( ) . await . notifications . enabled
37- {
64+ if state. config . read ( ) . await . notifications . enabled {
3865 tracing:: info!( "Starting 'notifications' tattoy..." ) ;
3966 tattoy_futures. spawn ( crate :: tattoys:: notifications:: main:: Notifications :: start (
4067 output. clone ( ) ,
@@ -58,39 +85,31 @@ pub(crate) fn start_tattoys(
5885 ) ) ;
5986 }
6087
61- if enabled_tattoys. contains ( & "minimap" . to_owned ( ) )
62- || state. config . read ( ) . await . minimap . enabled
63- {
88+ if state. config . read ( ) . await . minimap . enabled {
6489 tracing:: info!( "Starting 'minimap' tattoy..." ) ;
6590 tattoy_futures. spawn ( crate :: tattoys:: minimap:: Minimap :: start (
6691 output. clone ( ) ,
6792 Arc :: clone ( & state) ,
6893 ) ) ;
6994 }
7095
71- if enabled_tattoys. contains ( & "shaders" . to_owned ( ) )
72- || state. config . read ( ) . await . shader . enabled
73- {
96+ if state. config . read ( ) . await . shader . enabled {
7497 tracing:: info!( "Starting 'shaders' tattoy..." ) ;
7598 tattoy_futures. spawn ( crate :: tattoys:: shader:: Shaders :: start (
7699 output. clone ( ) ,
77100 Arc :: clone ( & state) ,
78101 ) ) ;
79102 }
80103
81- if enabled_tattoys. contains ( & "animated_cursor" . to_owned ( ) )
82- || state. config . read ( ) . await . animated_cursor . enabled
83- {
104+ if state. config . read ( ) . await . animated_cursor . enabled {
84105 tracing:: info!( "Starting 'animated_cursor' tattoy..." ) ;
85106 tattoy_futures. spawn ( crate :: tattoys:: animated_cursor:: AnimatedCursor :: start (
86107 output. clone ( ) ,
87108 Arc :: clone ( & state) ,
88109 ) ) ;
89110 }
90111
91- if enabled_tattoys. contains ( & "bg_command" . to_owned ( ) )
92- || state. config . read ( ) . await . bg_command . enabled
93- {
112+ if state. config . read ( ) . await . bg_command . enabled {
94113 tracing:: info!( "Starting 'bg_command' tattoy..." ) ;
95114 tattoy_futures. spawn ( crate :: tattoys:: bg_command:: BGCommand :: start (
96115 output. clone ( ) ,
@@ -140,3 +159,25 @@ pub(crate) fn start_tattoys(
140159 } )
141160 } )
142161}
162+
163+ /// Wait for tattoys that need to be running before the PTY starts.
164+ async fn wait_for_enabled_tattoys_to_start (
165+ enabled_tattoys : Vec < String > ,
166+ state : & Arc < crate :: shared_state:: SharedState > ,
167+ ) {
168+ if enabled_tattoys. contains ( & "random_walker" . to_owned ( ) ) {
169+ crate :: run:: wait_for_system ( state, "random_walker" ) . await ;
170+ }
171+
172+ if state. config . read ( ) . await . shader . enabled {
173+ crate :: run:: wait_for_system ( state, "shader" ) . await ;
174+ }
175+
176+ if state. config . read ( ) . await . minimap . enabled {
177+ crate :: run:: wait_for_system ( state, "minimap" ) . await ;
178+ }
179+
180+ if state. config . read ( ) . await . animated_cursor . enabled {
181+ crate :: run:: wait_for_system ( state, "animated_cursor" ) . await ;
182+ }
183+ }
0 commit comments