1+ use std:: fs;
12use std:: path:: { Path , PathBuf } ;
23use std:: sync:: mpsc:: { self , Receiver } ;
34use std:: thread;
4- use std:: time:: { Duration , Instant } ;
5+ use std:: time:: { Duration , Instant , SystemTime } ;
56#[ cfg( target_os = "linux" ) ]
67use std:: { fs:: OpenOptions , io:: Write } ;
78
@@ -40,8 +41,8 @@ const APP_WINDOW_TITLE: &str = "Linux.do Accelerator";
4041const APP_ID : & str = "linuxdo-accelerator" ;
4142const APP_VERSION : & str = env ! ( "CARGO_PKG_VERSION" ) ;
4243const ACTIVE_REPAINT_INTERVAL : Duration = Duration :: from_millis ( 100 ) ;
43- const IDLE_REPAINT_INTERVAL : Duration = Duration :: from_secs ( 2 ) ;
44- const TRAY_REPAINT_INTERVAL : Duration = Duration :: from_secs ( 5 ) ;
44+ const IDLE_REPAINT_INTERVAL : Duration = Duration :: from_secs ( 5 ) ;
45+ const TRAY_REPAINT_INTERVAL : Duration = Duration :: from_secs ( 15 ) ;
4546
4647pub fn run ( config_path : PathBuf ) -> Result < ( ) > {
4748 let native_options = eframe:: NativeOptions {
@@ -68,11 +69,7 @@ pub fn run(config_path: PathBuf) -> Result<()> {
6869}
6970
7071fn default_renderer ( ) -> eframe:: Renderer {
71- if cfg ! ( target_os = "windows" ) {
72- eframe:: Renderer :: Glow
73- } else {
74- eframe:: Renderer :: Wgpu
75- }
72+ eframe:: Renderer :: Glow
7673}
7774
7875#[ cfg( target_os = "linux" ) ]
@@ -153,6 +150,8 @@ struct AcceleratorApp {
153150 confirm_action : Option < GuiAction > ,
154151 optimistic_running : Option < ( bool , Instant ) > ,
155152 last_refresh : Instant ,
153+ config_modified_at : Option < SystemTime > ,
154+ runtime_log_modified_at : Option < SystemTime > ,
156155 show_about : bool ,
157156 show_config : bool ,
158157 logo : egui:: TextureHandle ,
@@ -203,9 +202,11 @@ impl AcceleratorApp {
203202 install_theme ( & cc. egui_ctx ) ;
204203
205204 let config = AppConfig :: load_or_create ( & config_path) . unwrap_or_default ( ) ;
205+ let config_modified_at = file_modified_at ( & config_path) ;
206206 let status = service:: status ( Some ( config_path. clone ( ) ) ) . unwrap_or_default ( ) ;
207207 let hosts_backup_state = load_hosts_backup_state ( & config_path) ;
208208 let recent_logs = load_recent_runtime_logs ( & config_path) ;
209+ let runtime_log_modified_at = runtime_log_file_modified_at ( & config_path) ;
209210 #[ cfg( target_os = "windows" ) ]
210211 schedule_windows_shortcut_icon_refresh ( & config_path) ;
211212 let logo = cc. egui_ctx . load_texture (
@@ -238,6 +239,8 @@ impl AcceleratorApp {
238239 confirm_action : None ,
239240 optimistic_running : None ,
240241 last_refresh : Instant :: now ( ) - Duration :: from_secs ( 2 ) ,
242+ config_modified_at,
243+ runtime_log_modified_at,
241244 show_about : false ,
242245 show_config : false ,
243246 logo,
@@ -267,9 +270,17 @@ impl AcceleratorApp {
267270 self . status = self . apply_optimistic_state ( status) ;
268271 }
269272 self . hosts_backup_state = load_hosts_backup_state ( & self . config_path ) ;
270- self . recent_logs = load_recent_runtime_logs ( & self . config_path ) ;
271- if let Ok ( config) = AppConfig :: load_or_create ( & self . config_path ) {
272- self . config = config;
273+ let current_log_modified_at = runtime_log_file_modified_at ( & self . config_path ) ;
274+ if current_log_modified_at != self . runtime_log_modified_at {
275+ self . recent_logs = load_recent_runtime_logs ( & self . config_path ) ;
276+ self . runtime_log_modified_at = current_log_modified_at;
277+ }
278+ let current_config_modified_at = file_modified_at ( & self . config_path ) ;
279+ if current_config_modified_at != self . config_modified_at {
280+ if let Ok ( config) = AppConfig :: load_or_create ( & self . config_path ) {
281+ self . config = config;
282+ }
283+ self . config_modified_at = current_config_modified_at;
273284 }
274285 }
275286
@@ -1397,6 +1408,16 @@ fn load_recent_runtime_logs(config_path: &Path) -> Vec<String> {
13971408 . unwrap_or_default ( )
13981409}
13991410
1411+ fn runtime_log_file_modified_at ( config_path : & Path ) -> Option < SystemTime > {
1412+ service:: resolve_paths ( Some ( config_path. to_path_buf ( ) ) )
1413+ . ok ( )
1414+ . and_then ( |paths| file_modified_at ( & paths. runtime_log_path ) )
1415+ }
1416+
1417+ fn file_modified_at ( path : & Path ) -> Option < SystemTime > {
1418+ fs:: metadata ( path) . ok ( ) ?. modified ( ) . ok ( )
1419+ }
1420+
14001421#[ cfg( target_os = "linux" ) ]
14011422fn spawn_linux_tray_shell ( config_path : & Path ) -> Result < ( ) > {
14021423 let gui_binary = locate_gui_binary ( ) ?;
0 commit comments