mirror of
https://github.com/rust-kotlin/ashell.git
synced 2026-09-22 08:01:00 +00:00
feat: change system theme sync interval to 1s
This commit is contained in:
+10
-15
@@ -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<BackendEvent>,
|
||||
@@ -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<Self>) {
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user