@@ -196,13 +196,32 @@ impl Config {
196196
197197 std:: fs:: create_dir_all ( path. clone ( ) ) ?;
198198
199- let shaders_directory = path. join ( SHADER_DIRECTORY_NAME ) ;
199+ * state. config_path . write ( ) . await = path;
200+
201+ Ok ( ( ) )
202+ }
203+
204+ /// Make sure all the shader directories and files exist.
205+ fn ensure_shader_assets ( config_base : & std:: path:: Path ) -> Result < ( ) > {
206+ let shaders_directory = config_base. join ( SHADER_DIRECTORY_NAME ) ;
200207 std:: fs:: create_dir_all ( shaders_directory) ?;
201208
202- let animated_cursor_directory = path . join ( CURSOR_SHADER_DIRECTORY_NAME ) ;
209+ let animated_cursor_directory = config_base . join ( CURSOR_SHADER_DIRECTORY_NAME ) ;
203210 std:: fs:: create_dir_all ( animated_cursor_directory) ?;
204211
205- * state. config_path . write ( ) . await = path;
212+ let shader_path = config_base
213+ . join ( SHADER_DIRECTORY_NAME )
214+ . join ( DEFAULT_SHADER_FILENAME ) ;
215+ if !shader_path. exists ( ) {
216+ std:: fs:: write ( shader_path, EXAMPLE_SHADER ) ?;
217+ }
218+
219+ let animated_cursor_path = config_base
220+ . join ( CURSOR_SHADER_DIRECTORY_NAME )
221+ . join ( DEFAULT_CURSOR_SHADER_FILENAME ) ;
222+ if !animated_cursor_path. exists ( ) {
223+ std:: fs:: write ( animated_cursor_path, EXAMPLE_CURSOR_SHADER ) ?;
224+ }
206225
207226 Ok ( ( ) )
208227 }
@@ -223,20 +242,11 @@ impl Config {
223242 . file_name ( )
224243 . context ( "Couldn't get file name from config path" ) ?;
225244 let is_default_config = config_file_name == crate :: cli_args:: DEFAULT_CONFIG_FILE_NAME ;
226- if is_default_config && !config_path. exists ( ) {
227- std:: fs:: write ( config_path. clone ( ) , DEFAULT_CONFIG ) ?;
228-
229- let shader_path = Self :: directory ( state)
230- . await
231- . join ( SHADER_DIRECTORY_NAME )
232- . join ( DEFAULT_SHADER_FILENAME ) ;
233- std:: fs:: write ( shader_path, EXAMPLE_SHADER ) ?;
234-
235- let animated_cursor_path = Self :: directory ( state)
236- . await
237- . join ( CURSOR_SHADER_DIRECTORY_NAME )
238- . join ( DEFAULT_CURSOR_SHADER_FILENAME ) ;
239- std:: fs:: write ( animated_cursor_path, EXAMPLE_CURSOR_SHADER ) ?;
245+ if is_default_config {
246+ if !config_path. exists ( ) {
247+ std:: fs:: write ( config_path. clone ( ) , DEFAULT_CONFIG ) ?;
248+ }
249+ Self :: ensure_shader_assets ( & Self :: default_directory ( ) ?) ?;
240250 }
241251
242252 tracing:: info!( "(Re)loading the main Tattoy config from: {config_path:?}" ) ;
0 commit comments