Do not query db on foreground thread.
Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
parent
818ddbc703
commit
081e340d26
2 changed files with 30 additions and 22 deletions
|
@ -27,7 +27,7 @@ use recent_projects::{build_recent_projects, RecentProjects};
|
||||||
use std::{ops::Range, sync::Arc};
|
use std::{ops::Range, sync::Arc};
|
||||||
use theme::{AvatarStyle, Theme};
|
use theme::{AvatarStyle, Theme};
|
||||||
use util::ResultExt;
|
use util::ResultExt;
|
||||||
use workspace::{FollowNextCollaborator, Workspace};
|
use workspace::{FollowNextCollaborator, Workspace, WORKSPACE_DB};
|
||||||
|
|
||||||
const MAX_PROJECT_NAME_LENGTH: usize = 40;
|
const MAX_PROJECT_NAME_LENGTH: usize = 40;
|
||||||
const MAX_BRANCH_NAME_LENGTH: usize = 40;
|
const MAX_BRANCH_NAME_LENGTH: usize = 40;
|
||||||
|
@ -448,8 +448,21 @@ impl CollabTitlebarItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn toggle_project_menu(&mut self, _: &ToggleProjectMenu, cx: &mut ViewContext<Self>) {
|
pub fn toggle_project_menu(&mut self, _: &ToggleProjectMenu, cx: &mut ViewContext<Self>) {
|
||||||
|
let workspace = self.workspace.clone();
|
||||||
if self.project_popover.take().is_none() {
|
if self.project_popover.take().is_none() {
|
||||||
let view = cx.add_view(|cx| build_recent_projects(self.workspace.clone(), cx));
|
cx.spawn(|this, mut cx| async move {
|
||||||
|
let workspaces = WORKSPACE_DB
|
||||||
|
.recent_workspaces_on_disk()
|
||||||
|
.await
|
||||||
|
.unwrap_or_default()
|
||||||
|
.into_iter()
|
||||||
|
.map(|(_, location)| location)
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let workspace = workspace.clone();
|
||||||
|
this.update(&mut cx, move |this, cx| {
|
||||||
|
let view = cx.add_view(|cx| build_recent_projects(workspace, workspaces, cx));
|
||||||
|
|
||||||
cx.subscribe(&view, |this, _, event, cx| {
|
cx.subscribe(&view, |this, _, event, cx| {
|
||||||
match event {
|
match event {
|
||||||
PickerEvent::Dismiss => {
|
PickerEvent::Dismiss => {
|
||||||
|
@ -460,11 +473,14 @@ impl CollabTitlebarItem {
|
||||||
cx.notify();
|
cx.notify();
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
self.branch_popover.take();
|
this.branch_popover.take();
|
||||||
self.project_popover = Some(view);
|
this.project_popover = Some(view);
|
||||||
}
|
|
||||||
|
|
||||||
cx.notify();
|
cx.notify();
|
||||||
|
})
|
||||||
|
.log_err();
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fn render_toggle_contacts_button(
|
fn render_toggle_contacts_button(
|
||||||
&self,
|
&self,
|
||||||
|
|
|
@ -66,17 +66,9 @@ fn toggle(
|
||||||
|
|
||||||
pub fn build_recent_projects(
|
pub fn build_recent_projects(
|
||||||
workspace: WeakViewHandle<Workspace>,
|
workspace: WeakViewHandle<Workspace>,
|
||||||
|
workspaces: Vec<WorkspaceLocation>,
|
||||||
cx: &mut ViewContext<RecentProjects>,
|
cx: &mut ViewContext<RecentProjects>,
|
||||||
) -> RecentProjects {
|
) -> RecentProjects {
|
||||||
let workspaces = futures::executor::block_on(async {
|
|
||||||
WORKSPACE_DB
|
|
||||||
.recent_workspaces_on_disk()
|
|
||||||
.await
|
|
||||||
.unwrap_or_default()
|
|
||||||
.into_iter()
|
|
||||||
.map(|(_, location)| location)
|
|
||||||
.collect()
|
|
||||||
});
|
|
||||||
Picker::new(RecentProjectsDelegate::new(workspace, workspaces), cx)
|
Picker::new(RecentProjectsDelegate::new(workspace, workspaces), cx)
|
||||||
.with_theme(|theme| theme.picker.clone())
|
.with_theme(|theme| theme.picker.clone())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue