@@ -39,10 +39,13 @@ use crate::state::ServiceState;
3939const APP_WINDOW_TITLE : & str = "Linux.do Accelerator" ;
4040const APP_ID : & str = "linuxdo-accelerator" ;
4141const APP_VERSION : & str = env ! ( "CARGO_PKG_VERSION" ) ;
42+ const 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 ) ;
4245
4346pub fn run ( config_path : PathBuf ) -> Result < ( ) > {
4447 let native_options = eframe:: NativeOptions {
45- renderer : eframe :: Renderer :: Wgpu ,
48+ renderer : default_renderer ( ) ,
4649 viewport : egui:: ViewportBuilder :: default ( )
4750 . with_title ( APP_WINDOW_TITLE )
4851 . with_app_id ( APP_ID )
@@ -64,6 +67,14 @@ pub fn run(config_path: PathBuf) -> Result<()> {
6467 . map_err ( |error| anyhow:: anyhow!( error. to_string( ) ) )
6568}
6669
70+ fn default_renderer ( ) -> eframe:: Renderer {
71+ if cfg ! ( target_os = "windows" ) {
72+ eframe:: Renderer :: Glow
73+ } else {
74+ eframe:: Renderer :: Wgpu
75+ }
76+ }
77+
6778#[ cfg( target_os = "linux" ) ]
6879pub fn run_tray_shell ( config_path : PathBuf ) -> Result < ( ) > {
6980 log_linux_tray_event ( & format ! (
@@ -1048,6 +1059,16 @@ impl AcceleratorApp {
10481059 }
10491060 self . last_minimized = minimized && !self . hidden_to_tray ;
10501061 }
1062+
1063+ fn repaint_interval ( & self ) -> Duration {
1064+ if self . busy || self . action_rx . is_some ( ) || self . confirm_action . is_some ( ) {
1065+ ACTIVE_REPAINT_INTERVAL
1066+ } else if self . hidden_to_tray {
1067+ TRAY_REPAINT_INTERVAL
1068+ } else {
1069+ IDLE_REPAINT_INTERVAL
1070+ }
1071+ }
10511072}
10521073
10531074impl eframe:: App for AcceleratorApp {
@@ -1060,7 +1081,8 @@ impl eframe::App for AcceleratorApp {
10601081
10611082 self . poll_action ( ) ;
10621083
1063- if self . last_refresh . elapsed ( ) >= Duration :: from_secs ( 1 ) {
1084+ let repaint_interval = self . repaint_interval ( ) ;
1085+ if self . last_refresh . elapsed ( ) >= repaint_interval {
10641086 self . refresh_status ( ) ;
10651087 self . last_refresh = Instant :: now ( ) ;
10661088 }
@@ -1193,7 +1215,7 @@ impl eframe::App for AcceleratorApp {
11931215 } ) ;
11941216 }
11951217
1196- ctx. request_repaint_after ( Duration :: from_millis ( 250 ) ) ;
1218+ ctx. request_repaint_after ( repaint_interval ) ;
11971219 }
11981220}
11991221
0 commit comments