gpui(windows): Move jumplist creation to background thread (#47956)

This can block the main thread too much otherwise

Release Notes:

- N/A *or* Added/Fixed/Improved ...
This commit is contained in:
Lukas Wirth authored and GitHub committed 2026-01-30 08:10:19 +00:00
1 parent 28f0461e94
commit 19765cd0b4
5 files changed
+77 -51

No files matched your search

+27 -26
View File
@@ -2,7 +2,7 @@ use std::path::PathBuf;
use gpui::{AppContext, Entity, Global, MenuItem};
use smallvec::SmallVec;
use ui::App;
use ui::{App, Context};
use util::{ResultExt, paths::PathExt};
use crate::{
@@ -71,7 +71,12 @@ impl HistoryManager {
cx.set_global(GlobalHistoryManager(history_manager));
}
pub fn update_history(&mut self, id: WorkspaceId, entry: HistoryManagerEntry, cx: &App) {
pub fn update_history(
&mut self,
id: WorkspaceId,
entry: HistoryManagerEntry,
cx: &mut Context<'_, HistoryManager>,
) {
if let Some(pos) = self.history.iter().position(|e| e.id == id) {
self.history.remove(pos);
}
@@ -79,7 +84,7 @@ impl HistoryManager {
self.update_jump_list(cx);
}
pub fn delete_history(&mut self, id: WorkspaceId, cx: &App) {
pub fn delete_history(&mut self, id: WorkspaceId, cx: &mut Context<'_, HistoryManager>) {
let Some(pos) = self.history.iter().position(|e| e.id == id) else {
return;
};
@@ -87,7 +92,7 @@ impl HistoryManager {
self.update_jump_list(cx);
}
fn update_jump_list(&mut self, cx: &App) {
fn update_jump_list(&mut self, cx: &mut Context<'_, HistoryManager>) {
let menus = vec![MenuItem::action("New Window", NewWindow)];
let entries = self
.history
@@ -96,29 +101,25 @@ impl HistoryManager {
.map(|entry| entry.path.clone())
.collect::<Vec<_>>();
let user_removed = cx.update_jump_list(menus, entries);
self.remove_user_removed_workspaces(user_removed, cx);
}
pub fn remove_user_removed_workspaces(
&mut self,
user_removed: Vec<SmallVec<[PathBuf; 2]>>,
cx: &App,
) {
if user_removed.is_empty() {
return;
}
let mut deleted_ids = Vec::new();
for idx in (0..self.history.len()).rev() {
if let Some(entry) = self.history.get(idx)
&& user_removed.contains(&entry.path)
{
deleted_ids.push(entry.id);
self.history.remove(idx);
cx.spawn(async move |this, cx| {
let user_removed = user_removed.await;
if user_removed.is_empty() {
return;
}
}
cx.spawn(async move |_| {
for id in deleted_ids.iter() {
WORKSPACE_DB.delete_workspace_by_id(*id).await.log_err();
let mut deleted_ids = Vec::new();
if let Ok(()) = this.update(cx, |this, _| {
for idx in (0..this.history.len()).rev() {
if let Some(entry) = this.history.get(idx)
&& user_removed.contains(&entry.path)
{
deleted_ids.push(entry.id);
this.history.remove(idx);
}
}
}) {
for id in deleted_ids.iter() {
WORKSPACE_DB.delete_workspace_by_id(*id).await.log_err();
}
}
})
.detach();