Skip to content

Commit b432a98

Browse files
committed
Reduce desktop GUI idle overhead
1 parent 5a6b06d commit b432a98

3 files changed

Lines changed: 36 additions & 23 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,13 @@ time = { version = "0.3", default-features = false, features = ["std"] }
7171
x509-parser = "0.16"
7272
md5 = "0.7"
7373

74-
[target.'cfg(any(windows, target_os = "linux", target_os = "macos"))'.dependencies]
75-
eframe = { version = "0.31", default-features = false, features = ["default_fonts", "glow", "wgpu", "x11", "wayland"] }
74+
[target.'cfg(any(windows, target_os = "macos"))'.dependencies]
75+
eframe = { version = "0.31", default-features = false, features = ["default_fonts", "glow"] }
7676
tray-icon = "0.19"
7777

7878
[target.'cfg(target_os = "linux")'.dependencies]
79+
eframe = { version = "0.31", default-features = false, features = ["default_fonts", "glow", "x11", "wayland"] }
80+
tray-icon = "0.19"
7981
gtk = "0.18"
8082

8183
[target.'cfg(windows)'.dependencies]

src/gui.rs

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
use std::fs;
12
use std::path::{Path, PathBuf};
23
use std::sync::mpsc::{self, Receiver};
34
use std::thread;
4-
use std::time::{Duration, Instant};
5+
use std::time::{Duration, Instant, SystemTime};
56
#[cfg(target_os = "linux")]
67
use std::{fs::OpenOptions, io::Write};
78

@@ -40,8 +41,8 @@ const APP_WINDOW_TITLE: &str = "Linux.do Accelerator";
4041
const APP_ID: &str = "linuxdo-accelerator";
4142
const APP_VERSION: &str = env!("CARGO_PKG_VERSION");
4243
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);
44+
const IDLE_REPAINT_INTERVAL: Duration = Duration::from_secs(5);
45+
const TRAY_REPAINT_INTERVAL: Duration = Duration::from_secs(15);
4546

4647
pub 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

7071
fn 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")]
14011422
fn spawn_linux_tray_shell(config_path: &Path) -> Result<()> {
14021423
let gui_binary = locate_gui_binary()?;

0 commit comments

Comments
 (0)