@@ -33,6 +33,8 @@ pub struct LogViewerApp {
33
33
should_scroll_to_end_on_load : bool ,
34
34
/// Allows the user to dim the warning by clicking on it
35
35
should_highlight_field_warning : bool ,
36
+ /// Max size in bytes of data before saving is disabled
37
+ max_data_save_size : Option < usize > ,
36
38
37
39
#[ serde( skip) ]
38
40
should_focus_search : bool ,
@@ -60,6 +62,7 @@ impl Default for LogViewerApp {
60
62
should_scroll : Default :: default ( ) ,
61
63
show_last_filename : true ,
62
64
last_save_hash : Default :: default ( ) ,
65
+ max_data_save_size : Some ( 2 * 1024 * 1024 ) , // 2 MB
63
66
}
64
67
}
65
68
}
@@ -771,6 +774,20 @@ impl LogViewerApp {
771
774
self . last_save_hash = Some ( new_hash) ;
772
775
true
773
776
}
777
+
778
+ fn should_save ( & mut self ) -> bool {
779
+ // Check if size of data allows saving
780
+ if let ( Some ( data) , Some ( max_data_size) ) =
781
+ ( self . data . as_ref ( ) , self . max_data_save_size . as_ref ( ) )
782
+ {
783
+ if & data. file_size_as_bytes > max_data_size {
784
+ return false ;
785
+ }
786
+ }
787
+
788
+ // Size of data does not prevent saving, check if there are changes to be saved
789
+ self . is_changed_since_last_save ( )
790
+ }
774
791
}
775
792
776
793
#[ cfg( not( target_arch = "wasm32" ) ) ]
@@ -820,13 +837,13 @@ impl eframe::App for LogViewerApp {
820
837
fn save ( & mut self , storage : & mut dyn eframe:: Storage ) {
821
838
#[ cfg( feature = "profiling" ) ]
822
839
puffin:: profile_scope!( "eframe::App::save" ) ;
823
- if self . is_changed_since_last_save ( ) {
840
+ if self . should_save ( ) {
824
841
info ! ( "Saving data" ) ;
825
842
#[ cfg( feature = "profiling" ) ]
826
843
puffin:: profile_scope!( "Saving App State" ) ;
827
844
eframe:: set_value ( storage, eframe:: APP_KEY , self ) ;
828
845
} else {
829
- debug ! ( "Save skipped, no change detected " ) ;
846
+ debug ! ( "Save skipped" ) ;
830
847
}
831
848
}
832
849
0 commit comments