@@ -31,25 +31,21 @@ pub async fn refresh_settings(
3131 path : & str ,
3232 themes : Option < & Themes > ,
3333 layouts : Option < & Layouts > ,
34- ) -> Result < SettingsUpdateType > {
34+ ) -> Result < ( ) > {
35+ info ! ( "Settings is't actual!" ) ;
36+
3537 let mut settings = SSSCliSettings :: load ( path) . await ?;
36- {
37- let current_settings = SETTINGS . read ( ) . await ;
38- if settings == * current_settings {
39- info ! ( "Nothing to update, settings is actual" ) ;
40- return Ok ( SettingsUpdateType :: AlreadyActual ) ;
41- }
42- }
43- info ! ( "Settigns is't actual, updating..." ) ;
4438 if let Some ( themes) = themes {
4539 settings. themes = themes. to_owned ( )
4640 }
4741 if let Some ( layouts) = layouts {
4842 settings. layouts = layouts. to_owned ( )
4943 }
50- * SETTINGS . deref ( ) . write ( ) . await = settings;
44+ {
45+ * SETTINGS . deref ( ) . write ( ) . await = settings;
46+ }
5147 info ! ( "Settings is actual now!" ) ;
52- Ok ( SettingsUpdateType :: NotActual )
48+ Ok ( ( ) )
5349}
5450/// Status of actual data
5551pub enum SettingsUpdateType {
@@ -70,36 +66,33 @@ pub async fn refresh(
7066) -> Result {
7167 debug ! ( "Themes in cli: {:#?}" , & themes) ;
7268 debug ! ( "Layouts in cli: {:#?}" , & layouts) ;
73- match refresh_settings ( path, themes, layouts) . await ? {
74- SettingsUpdateType :: AlreadyActual => Ok ( ( ) ) ,
75- SettingsUpdateType :: NotActual => {
76- refresh_html ( ) . await ?;
77- tokio:: spawn ( async move {
78- if let Err ( e) = refresh_png ( ) . await {
79- error ! ( "Got refresh error: {}" , e) ;
80- }
81- } ) ;
82- tokio:: spawn ( async move {
83- if let Err ( e) = refresh_pdf ( ) . await {
84- error ! ( "Got refresh error: {}" , e) ;
85- }
86- } ) ;
87- Ok ( ( ) )
69+ refresh_settings ( path, themes, layouts) . await ?;
70+ refresh_html ( ) . await ?;
71+ tokio:: spawn ( async move {
72+ if let Err ( e) = refresh_png ( ) . await {
73+ error ! ( "Got refresh error: {}" , e) ;
8874 }
89- }
75+ } ) ;
76+ tokio:: spawn ( async move {
77+ if let Err ( e) = refresh_pdf ( ) . await {
78+ error ! ( "Got refresh error: {}" , e) ;
79+ }
80+ } ) ;
81+ Ok ( ( ) )
9082}
9183
9284#[ instrument]
9385#[ inline]
9486/// Generate final component
9587pub async fn refresh_html ( ) -> Result {
9688 info ! ( "Render HTML" ) ;
97- let settings = SETTINGS . read ( ) . await ;
98- let layout = settings
99- . layouts
100- . to_layout ( & settings. sss_user_settings , ( & settings. themes ) . into ( ) ) ;
101-
102- * HTML . write ( ) . await = layout. finalize ( ) ?;
89+ {
90+ let settings = SETTINGS . read ( ) . await ;
91+ let layout = settings
92+ . layouts
93+ . to_layout ( & settings. sss_user_settings , ( & settings. themes ) . into ( ) ) ;
94+ * HTML . write ( ) . await = layout. finalize ( ) ?;
95+ }
10396 info ! ( "Done HTML" ) ;
10497 Ok ( ( ) )
10598}
@@ -109,9 +102,11 @@ pub async fn refresh_html() -> Result {
109102/// Generate final component
110103pub async fn refresh_png ( ) -> Result {
111104 info ! ( "Render PNG" ) ;
112- let html = HTML . read ( ) . await ;
113- let image = html_to_image ( & html, None , 12 ) . await ?;
114- * PNG . deref ( ) . write ( ) . await = image;
105+ {
106+ let html = HTML . read ( ) . await ;
107+ let image = html_to_image ( & html, None , 12 ) . await ?;
108+ * PNG . deref ( ) . write ( ) . await = image;
109+ }
115110 info ! ( "Done PNG" ) ;
116111 Ok ( ( ) )
117112}
@@ -121,9 +116,11 @@ pub async fn refresh_png() -> Result {
121116/// Generate final component
122117pub async fn refresh_pdf ( ) -> Result {
123118 info ! ( "Render PDF" ) ;
124- let html = HTML . read ( ) . await ;
125- let image = html_to_pdf ( & html, None ) . await ?;
126- * PDF . deref ( ) . write ( ) . await = image;
119+ {
120+ let html = HTML . read ( ) . await ;
121+ let image = html_to_pdf ( & html, None ) . await ?;
122+ * PDF . deref ( ) . write ( ) . await = image;
123+ }
127124 info ! ( "Done PDF" ) ;
128125 Ok ( ( ) )
129126}
0 commit comments