From 56030a0e77aff2455ad19688cfa14a2aec5f017e Mon Sep 17 00:00:00 2001 From: TomZz Date: Tue, 9 Jun 2026 03:47:24 +0800 Subject: [PATCH] feat: change system theme sync interval to 1s --- src/main.rs | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5c63c1b..c416b4f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -169,6 +169,7 @@ struct Ashell { system_sampler: SystemSampler, system: SystemSnapshot, last_system_sample: Instant, + last_theme_sync: Instant, remote_sample_in_flight: bool, runtime: Runtime, events_rx: mpsc::Receiver, @@ -296,6 +297,7 @@ impl Ashell { system_sampler, system, last_system_sample: Instant::now(), + last_theme_sync: Instant::now(), remote_sample_in_flight: false, runtime: Runtime::new().expect("create tokio runtime"), events_rx, @@ -303,21 +305,6 @@ impl Ashell { _subscriptions, }; - if follow_system_theme { - cx.spawn(async move |this, cx| { - loop { - cx.background_executor() - .timer(Duration::from_secs(60)) - .await; - if this.update(cx, |_, cx| { - Theme::sync_system_appearance(None, cx); - }).is_err() { - break; - } - } - }).detach(); - } - this.apply_theme_preferences(window, cx); // this.open_local(cx); this.start_event_pump(cx); @@ -358,6 +345,7 @@ impl Ashell { .update(cx, |this, cx| { this.drain_backend_events(); this.sample_system_if_due(); + this.sync_theme_if_due(cx); cx.notify(); }) .is_err() @@ -482,6 +470,13 @@ impl Ashell { } } + fn sync_theme_if_due(&mut self, cx: &mut Context) { + if self.follow_system_theme && self.last_theme_sync.elapsed() >= Duration::from_secs(1) { + Theme::sync_system_appearance(None, cx); + self.last_theme_sync = Instant::now(); + } + } + fn request_active_system_snapshot(&mut self) { if let Some((tab_id, session)) = self.active_ssh_session() { if self.remote_sample_in_flight {