mirror of
https://github.com/rust-kotlin/ashell.git
synced 2026-09-25 08:01:03 +00:00
feat: fix Windows flashing, UI thread blocking, and idle redraws (fixes #90)
This commit is contained in:
+12
-14
@@ -1425,9 +1425,7 @@ impl Ashell {
|
||||
this.recording_action = None;
|
||||
this.keybind_error = None;
|
||||
this.config.set_key_binding(&action, &new_key);
|
||||
if let Err(err) = this.config.save() {
|
||||
tracing::error!("failed to save key binding: {err:#}");
|
||||
}
|
||||
this.save_preferences_background();
|
||||
cx.notify();
|
||||
});
|
||||
}
|
||||
@@ -1600,7 +1598,7 @@ impl Ashell {
|
||||
.checked(current_style == crate::session::config::TitleBarStyle::Native)
|
||||
.on_click(window.listener_for(&view, |this, _, _, cx| {
|
||||
this.config.set_title_bar_style(crate::session::config::TitleBarStyle::Native);
|
||||
let _ = this.config.save();
|
||||
this.save_preferences_background();
|
||||
cx.notify();
|
||||
}))
|
||||
)
|
||||
@@ -1609,7 +1607,7 @@ impl Ashell {
|
||||
.checked(current_style == crate::session::config::TitleBarStyle::Integrated)
|
||||
.on_click(window.listener_for(&view, |this, _, _, cx| {
|
||||
this.config.set_title_bar_style(crate::session::config::TitleBarStyle::Integrated);
|
||||
let _ = this.config.save();
|
||||
this.save_preferences_background();
|
||||
cx.notify();
|
||||
}))
|
||||
);
|
||||
@@ -1844,7 +1842,7 @@ impl Ashell {
|
||||
.checked(view.read(cx).config.right_click_copy_paste())
|
||||
.on_click(window.listener_for(&view, |this, checked, _, cx| {
|
||||
this.config.set_right_click_copy_paste(*checked);
|
||||
let _ = this.config.save();
|
||||
this.save_preferences_background();
|
||||
cx.notify();
|
||||
}))
|
||||
.into_any_element()
|
||||
@@ -1863,7 +1861,7 @@ impl Ashell {
|
||||
.checked(view.read(cx).config.keyword_highlight())
|
||||
.on_click(window.listener_for(&view, |this, checked, _, cx| {
|
||||
this.config.set_keyword_highlight(*checked);
|
||||
let _ = this.config.save();
|
||||
this.save_preferences_background();
|
||||
cx.notify();
|
||||
}))
|
||||
.into_any_element()
|
||||
@@ -1882,7 +1880,7 @@ impl Ashell {
|
||||
.checked(view.read(cx).config.lock_layout())
|
||||
.on_click(window.listener_for(&view, |this, checked, _, cx| {
|
||||
this.config.set_lock_layout(*checked);
|
||||
let _ = this.config.save();
|
||||
this.save_preferences_background();
|
||||
cx.notify();
|
||||
}))
|
||||
.into_any_element()
|
||||
@@ -1919,7 +1917,7 @@ impl Ashell {
|
||||
.checked(pos == "Bottom")
|
||||
.on_click(window.listener_for(&view, |this, _, _window, cx| {
|
||||
this.config.set_monitoring_position("Bottom");
|
||||
let _ = this.config.save();
|
||||
this.save_preferences_background();
|
||||
cx.notify();
|
||||
}))
|
||||
)
|
||||
@@ -1928,7 +1926,7 @@ impl Ashell {
|
||||
.checked(pos == "Sidebar")
|
||||
.on_click(window.listener_for(&view, |this, _, _window, cx| {
|
||||
this.config.set_monitoring_position("Sidebar");
|
||||
let _ = this.config.save();
|
||||
this.save_preferences_background();
|
||||
cx.notify();
|
||||
}))
|
||||
)
|
||||
@@ -1937,7 +1935,7 @@ impl Ashell {
|
||||
.checked(pos == "Hidden")
|
||||
.on_click(window.listener_for(&view, |this, _, _window, cx| {
|
||||
this.config.set_monitoring_position("Hidden");
|
||||
let _ = this.config.save();
|
||||
this.save_preferences_background();
|
||||
cx.notify();
|
||||
}))
|
||||
);
|
||||
@@ -2109,7 +2107,7 @@ impl Ashell {
|
||||
.checked(view.read(cx).config.use_proxy())
|
||||
.on_click(window.listener_for(&view, |this, checked, _, cx| {
|
||||
this.config.set_use_proxy(*checked);
|
||||
let _ = this.config.save();
|
||||
this.save_preferences_background();
|
||||
cx.notify();
|
||||
}))
|
||||
.into_any_element()
|
||||
@@ -2128,7 +2126,7 @@ impl Ashell {
|
||||
.checked(view.read(cx).config.read_env_proxy())
|
||||
.on_click(window.listener_for(&view, |this, checked, _, cx| {
|
||||
this.config.set_read_env_proxy(*checked);
|
||||
let _ = this.config.save();
|
||||
this.save_preferences_background();
|
||||
cx.notify();
|
||||
}))
|
||||
.into_any_element()
|
||||
@@ -2197,7 +2195,7 @@ impl Ashell {
|
||||
this.config.set_global_proxy_port(port);
|
||||
this.config.set_global_proxy_user(user);
|
||||
this.config.set_global_proxy_password(password);
|
||||
let _ = this.config.save();
|
||||
this.save_preferences_background();
|
||||
cx.notify();
|
||||
}))
|
||||
)
|
||||
|
||||
+28
-10
@@ -327,6 +327,8 @@ pub(crate) struct Ashell {
|
||||
pub(crate) hovered_url: Option<HoveredUrl>,
|
||||
pub(crate) cmd_ctrl_pressed: bool,
|
||||
pub(crate) _subscriptions: Vec<gpui::Subscription>,
|
||||
pub(crate) save_lock: std::sync::Arc<tokio::sync::Mutex<()>>,
|
||||
pub(crate) save_latest_seq: std::sync::Arc<std::sync::atomic::AtomicU64>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
@@ -718,6 +720,8 @@ impl Ashell {
|
||||
hovered_url: None,
|
||||
cmd_ctrl_pressed: false,
|
||||
_subscriptions,
|
||||
save_lock: std::sync::Arc::new(tokio::sync::Mutex::new(())),
|
||||
save_latest_seq: std::sync::Arc::new(std::sync::atomic::AtomicU64::new(0)),
|
||||
};
|
||||
|
||||
this.apply_theme_preferences(window, cx);
|
||||
@@ -784,9 +788,29 @@ impl Ashell {
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
pub(crate) fn save_preferences_background(&mut self) {
|
||||
let local_config = self.config.cache.clone();
|
||||
let config_store = self.config.clone();
|
||||
let latest_seq = self.save_latest_seq.clone();
|
||||
let current_seq = latest_seq.fetch_add(1, std::sync::atomic::Ordering::SeqCst) + 1;
|
||||
let save_lock = self.save_lock.clone();
|
||||
|
||||
self.runtime.spawn(async move {
|
||||
let _guard = save_lock.lock().await;
|
||||
if current_seq < latest_seq.load(std::sync::atomic::Ordering::SeqCst) {
|
||||
return;
|
||||
}
|
||||
let _ = tokio::task::spawn_blocking(move || {
|
||||
if let Err(err) = config_store.save_merged_preferences(local_config) {
|
||||
tracing::error!("failed to save merged preferences in background: {err:#}");
|
||||
}
|
||||
})
|
||||
.await;
|
||||
});
|
||||
}
|
||||
|
||||
pub(crate) fn start_event_pump(&self, cx: &mut Context<Self>) {
|
||||
cx.spawn(async move |this, cx| {
|
||||
let mut idle_frames = 0u32;
|
||||
let mut last_blink_time = std::time::Instant::now();
|
||||
loop {
|
||||
cx.background_executor()
|
||||
@@ -808,16 +832,9 @@ impl Ashell {
|
||||
>= std::time::Duration::from_millis(600);
|
||||
if changed || system_sampled || blink_due {
|
||||
cx.notify();
|
||||
idle_frames = 0;
|
||||
if blink_due {
|
||||
last_blink_time = now;
|
||||
}
|
||||
} else {
|
||||
idle_frames += 1;
|
||||
if idle_frames >= 60 {
|
||||
cx.notify();
|
||||
idle_frames = 0;
|
||||
}
|
||||
}
|
||||
})
|
||||
.is_err()
|
||||
@@ -1331,8 +1348,9 @@ impl Ashell {
|
||||
};
|
||||
let size = bounds.size;
|
||||
if size.width.as_f32() > 400.0 && size.height.as_f32() > 300.0 {
|
||||
tracing::info!("[ui] saving layout state...");
|
||||
let mut config = ConfigStore::load().unwrap_or_else(|_| ConfigStore::in_memory());
|
||||
self.save_latest_seq
|
||||
.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
|
||||
let mut config = self.config.clone();
|
||||
let saved_bounds = match current_bounds {
|
||||
gpui::WindowBounds::Fullscreen(b) => {
|
||||
crate::session::config::SavedWindowBounds::Fullscreen {
|
||||
|
||||
+2
-6
@@ -126,9 +126,7 @@ impl Ashell {
|
||||
}
|
||||
rust_i18n::set_locale(&active_locale);
|
||||
gpui_component::set_locale(&active_locale);
|
||||
if let Err(err) = self.config.save() {
|
||||
tracing::warn!("failed to save language preferences: {err:#}");
|
||||
}
|
||||
self.save_preferences_background();
|
||||
window.refresh();
|
||||
cx.notify();
|
||||
}
|
||||
@@ -168,8 +166,6 @@ impl Ashell {
|
||||
self.light_theme_name.to_string(),
|
||||
self.dark_theme_name.to_string(),
|
||||
);
|
||||
if let Err(err) = self.config.save() {
|
||||
tracing::warn!("failed to save theme preferences: {err:#}");
|
||||
}
|
||||
self.save_preferences_background();
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -111,7 +111,7 @@ impl Ashell {
|
||||
}
|
||||
self.config
|
||||
.set_sftp_panel_minimized(self.sftp_panel_minimized);
|
||||
let _ = self.config.save();
|
||||
self.save_preferences_background();
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
@@ -293,7 +293,7 @@ impl Ashell {
|
||||
.on_click(cx.listener(|this, checked, _, cx| {
|
||||
this.show_hidden_files = *checked;
|
||||
this.config.set_show_hidden_files(*checked);
|
||||
let _ = this.config.save();
|
||||
this.save_preferences_background();
|
||||
cx.notify();
|
||||
})),
|
||||
)
|
||||
@@ -1593,7 +1593,7 @@ impl Ashell {
|
||||
.on_click(cx.listener(|this, _, _, cx| {
|
||||
this.sidebar_collapsed = true;
|
||||
this.config.set_sidebar_collapsed(true);
|
||||
let _ = this.config.save();
|
||||
this.save_preferences_background();
|
||||
cx.notify();
|
||||
})),
|
||||
)
|
||||
@@ -1833,7 +1833,7 @@ impl Ashell {
|
||||
.on_click(cx.listener(|this, _, _, cx| {
|
||||
this.sidebar_collapsed = false;
|
||||
this.config.set_sidebar_collapsed(false);
|
||||
let _ = this.config.save();
|
||||
this.save_preferences_background();
|
||||
cx.notify();
|
||||
})),
|
||||
),
|
||||
@@ -2797,7 +2797,7 @@ impl Render for Ashell {
|
||||
.on_action(cx.listener(|this, _: &crate::ToggleSidebar, _, cx| {
|
||||
this.sidebar_collapsed = !this.sidebar_collapsed;
|
||||
this.config.set_sidebar_collapsed(this.sidebar_collapsed);
|
||||
let _ = this.config.save();
|
||||
this.save_preferences_background();
|
||||
cx.notify();
|
||||
}))
|
||||
.on_action(cx.listener(|this, _: &crate::ToggleSftpZoom, window, cx| {
|
||||
|
||||
Reference in New Issue
Block a user