fix(desktop): restore explorer filters and display preferences

This commit is contained in:
DarkSky committed 2026-12-04 20:43:32 +09:00
1 parent 969f0c690e
commit f3551424e8
8 files changed
+685 -211

No files matched your search

@@ -33,6 +33,13 @@ impl SqliteSyncHost {
}
}
/// Return the path of the writable database file, if this host has one.
pub fn writable_database_path(&self) -> Option<&str> {
let storage = self.store.storage();
let path = storage.path();
(!storage.is_read_only() && path != ":memory:").then_some(path)
}
pub fn connect(&self, session: &mut WorkspaceSession, now_ms: i64) -> ClientResult<()> {
if session.space_id() != self.store.space_id() || self.store.storage().is_read_only() {
return Err(ClientError::Store(
@@ -232,20 +232,25 @@ impl WorkspaceExplorerPrefs {
true
}
/// Unpin `col_id`, returning `Some(next_active)` when `col_id` was the active filter.
pub(crate) fn unpin_collection(&mut self, col_id: &str) -> Option<Option<String>> {
let index = self.pinned_collections.iter().position(|id| id == col_id)?;
self.pinned_collections.remove(index);
if self.active_pinned_collection.as_deref() == Some(col_id) {
let next = index
.checked_sub(1)
.and_then(|prev| self.pinned_collections.get(prev))
.cloned();
self.active_pinned_collection = next.clone();
Some(next)
} else {
None
/// Remove the pin after the workspace accepts the change.
pub(crate) fn unpin_collection(&mut self, col_id: &str, remove: impl FnOnce() -> bool) -> bool {
let Some(index) = self.pinned_collections.iter().position(|id| id == col_id) else {
return false;
};
let is_active = self.active_pinned_collection.as_deref() == Some(col_id);
let previous = index
.checked_sub(1)
.filter(|_| is_active)
.and_then(|prev| self.pinned_collections.get(prev))
.cloned();
if !remove() {
return false;
}
self.pinned_collections.remove(index);
if is_active {
self.active_pinned_collection = previous;
}
true
}
/// Drop pinned or active collection IDs that no longer exist in the workspace.
@@ -336,7 +341,7 @@ pub(crate) struct ExplorerPrefsStore {
workspaces: BTreeMap<String, WorkspaceExplorerPrefs>,
last_saved_json: BTreeMap<String, String>,
bound_ids: BTreeMap<String, usize>,
last_db_pinned: BTreeMap<String, Vec<String>>,
pin_revisions: BTreeMap<String, u64>,
storage: Box<dyn PrefsStorageBackend>,
}
@@ -352,7 +357,7 @@ impl ExplorerPrefsStore {
workspaces: BTreeMap::new(),
last_saved_json: BTreeMap::new(),
bound_ids: BTreeMap::new(),
last_db_pinned: BTreeMap::new(),
pin_revisions: BTreeMap::new(),
storage,
}
}
@@ -361,62 +366,56 @@ impl ExplorerPrefsStore {
format!("{STORAGE_PREFIX}{workspace_id}")
}
pub(crate) fn workspace_prefs(
&mut self,
workspace_id: &str,
store: &DesktopDocStore,
) -> &mut WorkspaceExplorerPrefs {
self.workspace_prefs_with_local(workspace_id, store, (0, None), &mut |_, _| {})
pub(crate) fn workspace_prefs(&mut self, workspace_id: &str) -> &mut WorkspaceExplorerPrefs {
self.workspaces.entry(workspace_id.to_owned()).or_default()
}
pub(crate) fn workspace_prefs_with_local(
&mut self,
workspace_id: &str,
store: &DesktopDocStore,
local_bind: (usize, Option<String>),
save_local: &mut dyn FnMut(&str, &str),
bind_id: usize,
load_local: impl FnOnce() -> Option<String>,
save_local: &mut dyn FnMut(&str, &str) -> bool,
) -> &mut WorkspaceExplorerPrefs {
let (bind_id, local_raw) = local_bind;
let new_workspace = !self.workspaces.contains_key(workspace_id);
let bind_changed =
bind_id != 0 && self.bound_ids.get(workspace_id).copied() != Some(bind_id);
if bind_id != 0 {
let local_raw = bind_changed.then(load_local).flatten();
let reload = new_workspace || (bind_changed && local_raw.is_some());
let save_to_new_binding = bind_changed
&& local_raw.is_none()
&& self.last_saved_json.remove(workspace_id).is_some();
if bind_changed {
self.bound_ids.insert(workspace_id.to_owned(), bind_id);
}
let revision = store.derived.meta_rev;
if !reload && !bind_changed && self.pin_revisions.get(workspace_id) == Some(&revision) {
return self.workspaces.entry(workspace_id.to_owned()).or_default();
}
self.pin_revisions.insert(workspace_id.to_owned(), revision);
let has_db_table = store.has_pinned_collections_table();
let db_pinned = store.pinned_collection_ids_from_db();
if !self.workspaces.contains_key(workspace_id)
|| (bind_changed
&& local_raw.is_some()
&& !self.last_saved_json.contains_key(workspace_id))
{
let key = Self::storage_key(workspace_id);
let stored_raw = local_raw.or_else(|| self.storage.get(&key));
let loaded = stored_raw.and_then(|raw| {
if reload {
let raw = if bind_id == 0 {
self.storage.get(&Self::storage_key(workspace_id))
} else {
local_raw
};
let loaded = raw.and_then(|raw| {
let parsed = serde_json::from_str::<WorkspaceExplorerPrefs>(&raw).ok()?;
self.last_saved_json.insert(workspace_id.to_owned(), raw);
Some(parsed)
});
let mut prefs = loaded.unwrap_or_else(|| WorkspaceExplorerPrefs {
pinned_collections: db_pinned.clone(),
pinned_seeded_from_db: true,
..WorkspaceExplorerPrefs::default()
});
if !prefs.pinned_seeded_from_db || has_db_table {
prefs.pinned_collections = db_pinned.clone();
prefs.pinned_seeded_from_db = true;
if let Some(prefs) = loaded {
self.workspaces.insert(workspace_id.to_owned(), prefs);
}
self.last_db_pinned
.insert(workspace_id.to_owned(), db_pinned);
self.workspaces.insert(workspace_id.to_owned(), prefs);
} else if has_db_table && self.last_db_pinned.get(workspace_id) != Some(&db_pinned) {
if let Some(prefs) = self.workspaces.get_mut(workspace_id) {
prefs.pinned_collections = db_pinned.clone();
prefs.pinned_seeded_from_db = true;
}
self.last_db_pinned
.insert(workspace_id.to_owned(), db_pinned);
}
let prefs = self.workspaces.entry(workspace_id.to_owned()).or_default();
if !prefs.pinned_seeded_from_db || has_db_table {
prefs.pinned_collections = store.pinned_collection_ids_from_db();
prefs.pinned_seeded_from_db = true;
}
let valid_ids: HashSet<&str> = store
@@ -424,11 +423,8 @@ impl ExplorerPrefsStore {
.iter()
.map(|col| col.id.as_str())
.collect();
let changed = self
.workspaces
.get_mut(workspace_id)
.is_some_and(|prefs| prefs.reconcile_collections(&valid_ids));
if changed && self.last_saved_json.contains_key(workspace_id) {
let changed = prefs.reconcile_collections(&valid_ids);
if save_to_new_binding || (changed && self.last_saved_json.contains_key(workspace_id)) {
self.persist_with(workspace_id, save_local);
}
self.workspaces.entry(workspace_id.to_owned()).or_default()
@@ -437,7 +433,7 @@ impl ExplorerPrefsStore {
pub(crate) fn persist_with(
&mut self,
workspace_id: &str,
save_local: &mut dyn FnMut(&str, &str),
save_local: &mut dyn FnMut(&str, &str) -> bool,
) -> bool {
let Some(prefs) = self.workspaces.get(workspace_id) else {
return false;
@@ -448,8 +444,11 @@ impl ExplorerPrefsStore {
if self.last_saved_json.get(workspace_id) == Some(&json) {
return false;
}
if !save_local(workspace_id, &json) {
self.last_saved_json.remove(workspace_id);
return false;
}
self.storage.set(&Self::storage_key(workspace_id), &json);
save_local(workspace_id, &json);
self.last_saved_json.insert(workspace_id.to_owned(), json);
true
}
@@ -691,7 +690,8 @@ mod tests {
let mut prefs_store = ExplorerPrefsStore::with_backend(Box::new(storage.clone()));
{
let ws_prefs = prefs_store.workspace_prefs(&ws, &store);
let ws_prefs =
prefs_store.workspace_prefs_with_local(&ws, &store, 0, || None, &mut |_, _| true);
assert_eq!(ws_prefs.pinned_collections, vec!["col-rust-core"]);
let default_list = ws_prefs.route_state(ExplorerRouteScope::AllDocs);
assert_eq!(default_list.list.group_by, Some(ExplorerGroupBy::UpdatedAt));
@@ -712,16 +712,17 @@ mod tests {
}
assert!(store.pin_collection_in_db("col-whiteboards"));
assert!(!store.pin_collection_in_db("col-whiteboards"));
assert!(prefs_store.persist_with(&ws, &mut |_, _| {}));
assert!(prefs_store.persist_with(&ws, &mut |_, _| true));
assert_eq!(*storage.writes.borrow(), 1);
// Repeat save with identical state is diff-gated.
assert!(!prefs_store.persist_with(&ws, &mut |_, _| {}));
assert!(!prefs_store.persist_with(&ws, &mut |_, _| true));
assert_eq!(*storage.writes.borrow(), 1);
// Reload in a fresh store and verify route scopes + explicit None/false overrides + pinned collections restored.
let mut reloaded = ExplorerPrefsStore::with_backend(Box::new(storage.clone()));
{
let ws_prefs = reloaded.workspace_prefs(&ws, &store);
let ws_prefs =
reloaded.workspace_prefs_with_local(&ws, &store, 0, || None, &mut |_, _| true);
assert_eq!(
ws_prefs.pinned_collections,
vec!["col-rust-core", "col-whiteboards"]
@@ -744,7 +745,8 @@ mod tests {
// Deleting a collection automatically prunes pinned_collections and clears active filter.
assert!(store.delete_collection("col-whiteboards"));
assert!(store.unpin_collection_in_db("col-whiteboards"));
let ws_prefs = reloaded.workspace_prefs(&ws, &store);
let ws_prefs =
reloaded.workspace_prefs_with_local(&ws, &store, 0, || None, &mut |_, _| true);
assert_eq!(ws_prefs.pinned_collections, vec!["col-rust-core"]);
assert_eq!(ws_prefs.active_pinned_collection, None);
assert_eq!(*storage.writes.borrow(), 2);
@@ -758,16 +760,24 @@ mod tests {
store.collections.push(col_b.clone());
col_b.id.clear();
assert!(store.pin_collection_in_db("col-extra"));
let ws_prefs = reloaded.workspace_prefs(&ws, &store);
let ws_prefs =
reloaded.workspace_prefs_with_local(&ws, &store, 0, || None, &mut |_, _| true);
assert_eq!(
ws_prefs.pinned_collections,
vec!["col-rust-core", "col-extra"]
);
ws_prefs.active_pinned_collection = Some("col-extra".into());
assert!(!ws_prefs.unpin_collection("col-extra", || false));
assert_eq!(
ws_prefs.unpin_collection("col-extra"),
Some(Some("col-rust-core".into()))
ws_prefs.active_pinned_collection.as_deref(),
Some("col-extra")
);
assert_eq!(ws_prefs.unpin_collection("col-rust-core"), Some(None));
assert!(ws_prefs.unpin_collection("col-extra", || true));
assert_eq!(
ws_prefs.active_pinned_collection.as_deref(),
Some("col-rust-core")
);
assert!(ws_prefs.unpin_collection("col-rust-core", || true));
assert_eq!(ws_prefs.active_pinned_collection, None);
}
}
@@ -114,51 +114,49 @@ pub(super) struct Controls {
pub(super) display_menu: Entity<DisplayMenuState>,
pub(super) overview: Entity<Destination>,
pub(super) focus: FocusHandle,
pub(super) pinned_add_focus: FocusHandle,
pub(super) pinned_menu_focus: FocusHandle,
pub(super) prompt: Entity<TrashPrompt>,
}
impl Controls {
fn hydrate_prefs(prefs: &mut ExplorerPrefsStore, shell: &DesktopShellView, workspace_id: &str) {
prefs.workspace_prefs_with_local(
workspace_id,
&shell.state.store,
shell.explorer_prefs_binding(workspace_id),
|| shell.local_explorer_prefs(workspace_id),
&mut |id, json| shell.save_local_explorer_prefs(id, json),
);
}
pub(super) fn update_ws_prefs<R>(
&self,
app: &mut App,
notify: bool,
change: impl FnOnce(&mut ExplorerPrefsStore, &str, &DesktopDocStore) -> R,
read: impl FnOnce(&mut ExplorerPrefsStore, &str, &DesktopDocStore) -> R,
) -> R {
let shell = self.shell.clone();
self.prefs.update(app, |prefs, cx| {
let shell_view = shell.read(cx);
let store = &shell_view.state.store;
let ws = store.active_workspace().id.clone();
let local = shell_view.local_explorer_prefs(&ws);
let mut save_local = |id: &str, json: &str| {
shell_view.save_local_explorer_prefs(id, json);
};
let _ = prefs.workspace_prefs_with_local(&ws, store, local, &mut save_local);
let result = change(prefs, &ws, store);
if notify {
cx.notify();
}
result
let shell = self.shell.read(cx);
let store = &shell.state.store;
let workspace_id = &store.active_workspace().id;
Self::hydrate_prefs(prefs, shell, workspace_id);
read(prefs, workspace_id, store)
})
}
fn mutate_ws_prefs(
&self,
app: &mut App,
change: impl FnOnce(&mut ExplorerPrefsStore, &str, &DesktopDocStore) -> bool,
change: impl FnOnce(&mut ExplorerPrefsStore, &str) -> bool,
) {
let shell = self.shell.clone();
self.prefs.update(app, |prefs, cx| {
let shell_view = shell.read(cx);
let store = &shell_view.state.store;
let ws = store.active_workspace().id.clone();
let local = shell_view.local_explorer_prefs(&ws);
let mut save_local = |id: &str, json: &str| {
shell_view.save_local_explorer_prefs(id, json);
};
let _ = prefs.workspace_prefs_with_local(&ws, store, local, &mut save_local);
if change(prefs, &ws, store) {
prefs.persist_with(&ws, &mut save_local);
let shell = self.shell.read(cx);
let workspace_id = &shell.state.store.active_workspace().id;
Self::hydrate_prefs(prefs, shell, workspace_id);
if change(prefs, workspace_id) {
prefs.persist_with(workspace_id, &mut |id, json| {
shell.save_local_explorer_prefs(id, json)
});
}
cx.notify();
});
@@ -169,8 +167,8 @@ impl Controls {
scope: ExplorerRouteScope,
app: &mut App,
) -> (ExplorerViewMode, DisplayPreference) {
self.update_ws_prefs(app, false, |prefs, ws, store| {
let (view, active) = prefs.workspace_prefs(ws, store).active_prefs(scope);
self.update_ws_prefs(app, |prefs, ws, _| {
let (view, active) = prefs.workspace_prefs(ws).active_prefs(scope);
(view, active.clone())
})
}
@@ -181,8 +179,8 @@ impl Controls {
app: &mut App,
change: impl FnOnce(&mut RouteExplorerState),
) {
self.mutate_ws_prefs(app, |prefs, ws, store| {
let ws_prefs = prefs.workspace_prefs(ws, store);
self.mutate_ws_prefs(app, |prefs, ws| {
let ws_prefs = prefs.workspace_prefs(ws);
change(ws_prefs.route_state(scope));
true
});
@@ -199,8 +197,8 @@ impl Controls {
}
pub(super) fn set_active_pinned(&self, col_id: Option<String>, app: &mut App) {
self.mutate_ws_prefs(app, |prefs, ws, store| {
let ws_prefs = prefs.workspace_prefs(ws, store);
self.mutate_ws_prefs(app, |prefs, ws| {
let ws_prefs = prefs.workspace_prefs(ws);
if ws_prefs.active_pinned_collection != col_id {
ws_prefs.active_pinned_collection = col_id;
true
@@ -221,8 +219,8 @@ impl Controls {
shell.flush_persistence();
}
});
self.mutate_ws_prefs(app, |prefs, ws, store| {
prefs.workspace_prefs(ws, store).pin_collection(col_id)
self.mutate_ws_prefs(app, |prefs, ws| {
prefs.workspace_prefs(ws).pin_collection(col_id)
});
self.state.update(app, |state, cx| {
state.popup = None;
@@ -231,15 +229,27 @@ impl Controls {
}
pub(super) fn unpin_collection(&self, col_id: &str, app: &mut App) {
self.shell.update(app, |shell, _| {
if shell.state.store.unpin_collection_in_db(col_id) {
let removed = self.shell.update(app, |shell, cx| {
self.prefs.update(cx, |prefs, cx| {
let ws = shell.state.store.active_workspace().id.clone();
Self::hydrate_prefs(prefs, shell, &ws);
let ws_prefs = prefs.workspace_prefs(&ws);
if !ws_prefs
.unpin_collection(col_id, || shell.state.store.unpin_collection_in_db(col_id))
{
return false;
}
shell.flush_persistence();
}
});
self.mutate_ws_prefs(app, |prefs, ws, store| {
prefs.workspace_prefs(ws, store).unpin_collection(col_id);
true
prefs.persist_with(&ws, &mut |id, json| {
shell.save_local_explorer_prefs(id, json)
});
cx.notify();
true
})
});
if !removed {
return;
}
self.state.update(app, |state, cx| {
state.leave_selection();
state.popup = None;
@@ -280,8 +290,8 @@ impl Controls {
new_id
});
if let Some(id) = created_id {
self.mutate_ws_prefs(app, |prefs, ws, store| {
let ws_prefs = prefs.workspace_prefs(ws, store);
self.mutate_ws_prefs(app, |prefs, ws| {
let ws_prefs = prefs.workspace_prefs(ws);
ws_prefs.pin_collection(&id);
ws_prefs.active_pinned_collection = Some(id);
true
@@ -104,6 +104,14 @@ impl RenderOnce for DocsExplorer {
cx.focus_handle()
});
let focus = focus.read(app).clone();
let (pinned_add_focus, pinned_menu_focus) = window
.use_keyed_state(
location.key("desktop.explorer.pinned.focus"),
app,
|_, cx| (cx.focus_handle(), cx.focus_handle()),
)
.read(app)
.clone();
let prompt = TrashPrompt::keyed(location.key("desktop.explorer.trash_prompt"), window, app);
let controls = Controls {
shell: self.shell.clone(),
@@ -113,12 +121,22 @@ impl RenderOnce for DocsExplorer {
display_menu,
overview,
focus,
pinned_add_focus,
pinned_menu_focus,
prompt,
};
let palette = self.palette;
let on_route = controls.location.route.clone();
let scope = ExplorerRouteScope::from_route(&on_route);
let (view_mode, prefs) = controls.read_prefs(scope, app);
let (view_mode, prefs, active_pinned_col) =
controls.update_ws_prefs(app, |store, ws, _| {
let prefs = store.workspace_prefs(ws);
let active_pinned_col = (on_route == DesktopRoute::AllDocs)
.then(|| prefs.active_pinned_collection.clone())
.flatten();
let (view, display) = prefs.active_prefs(scope);
(view, display.clone(), active_pinned_col)
});
let grid = view_mode == ExplorerViewMode::Grid;
let order = match prefs.order {
ExplorerOrder::Updated => DocOrder::Updated,
@@ -126,15 +144,6 @@ impl RenderOnce for DocsExplorer {
ExplorerOrder::Title => DocOrder::Title,
};
let active_pinned_col = if on_route == DesktopRoute::AllDocs {
controls.update_ws_prefs(app, false, |p, ws_id, store| {
p.workspace_prefs(ws_id, store)
.active_pinned_collection
.clone()
})
} else {
None
};
let (writable, today_date, theme) = {
let shell = self.shell.read(app);
(
@@ -184,6 +193,12 @@ impl RenderOnce for DocsExplorer {
("desktop.explorer.nav.tags", "Tags", Destination::Tags),
] {
let active = destination == target;
let clear_hidden_filter = compact_height
&& on_route == DesktopRoute::AllDocs
&& target == Destination::Docs
&& active_pinned_col.is_some();
let navigate = controls.navigate(DesktopRoute::AllDocs, Some(target));
let controls = controls.clone();
header = header.child(
button(id, name, palette, true)
.snapshot(id, Some("desktop.workbench"))
@@ -197,7 +212,12 @@ impl RenderOnce for DocsExplorer {
} else {
ui::transparent_black()
})
.on_click(controls.navigate(DesktopRoute::AllDocs, Some(target))),
.on_click(move |event, window, app| {
if clear_hidden_filter {
controls.set_active_pinned(None, app);
}
navigate(event, window, app);
}),
);
}
@@ -573,9 +593,10 @@ impl RenderOnce for DocsExplorer {
let props = cached.props;
let prefs_for_rows = prefs.clone();
let state_key = controls.location.key(&format!(
"desktop.explorer.scroll.{}.{}",
"desktop.explorer.scroll.{}.{}.{}",
prefs_for_rows.row_layout_hash(),
grouped
grouped,
active_pinned_col.as_deref().unwrap_or_default()
));
root.child(virtual_scroll_shared(
scroll_key,
@@ -18,20 +18,19 @@ pub(super) fn render_pinned_collections(
writable: bool,
app: &mut App,
) -> Stateful<Div> {
let (pinned, active_id, collections) =
controls.update_ws_prefs(app, false, |prefs, ws, store| {
let collections: Vec<(String, String)> = store
.collections
.iter()
.map(|col| (col.id.clone(), col.name.clone()))
.collect();
let ws_prefs = prefs.workspace_prefs(ws, store);
(
ws_prefs.pinned_collections.clone(),
ws_prefs.active_pinned_collection.clone(),
collections,
)
});
let (pinned, active_id, collections) = controls.update_ws_prefs(app, |prefs, ws, store| {
let prefs = prefs.workspace_prefs(ws);
let collections: Vec<(String, String)> = store
.collections
.iter()
.map(|col| (col.id.clone(), col.name.clone()))
.collect();
(
prefs.pinned_collections.clone(),
prefs.active_pinned_collection.clone(),
collections,
)
});
let all_active = active_id.is_none();
let mut row = div()
@@ -175,6 +174,7 @@ pub(super) fn render_pinned_collections(
div()
.id("desktop.explorer.pinned.add")
.snapshot("desktop.explorer.pinned.add", Some("desktop.workbench"))
.track_focus(&controls.pinned_add_focus)
.size(px(24.0))
.rounded(px(4.0))
.flex()
@@ -185,7 +185,7 @@ pub(super) fn render_pinned_collections(
.hover(move |s| s.bg(palette.hover_overlay))
.on_click({
let state = controls.state.clone();
let focus = controls.focus.clone();
let focus = controls.pinned_menu_focus.clone();
move |event, window, app| {
app.stop_propagation();
window.focus(&focus, app);
@@ -250,13 +250,14 @@ pub(super) fn render_add_pinned_menu(
app: &mut App,
) -> (Point<Pixels>, Stateful<Div>) {
let (clamped_pos, max_h) = clamp_popup_position(position, 224.0, 140.0, 320.0, viewport);
let (collections, pinned) = controls.update_ws_prefs(app, false, |prefs, ws, store| {
let (collections, pinned) = controls.update_ws_prefs(app, |prefs, ws, store| {
let prefs = prefs.workspace_prefs(ws);
let collections: Vec<(String, String)> = store
.collections
.iter()
.map(|col| (col.id.clone(), col.name.clone()))
.collect();
let pinned = prefs.workspace_prefs(ws, store).pinned_collections.clone();
let pinned = prefs.pinned_collections.clone();
(collections, pinned)
});
let unpinned: Vec<(String, String)> = collections
@@ -307,8 +308,9 @@ pub(super) fn render_add_pinned_menu(
.text_color(palette.text_primary)
.cursor_pointer()
.hover(move |s| s.bg(palette.hover_color))
.on_click(move |_: &ClickEvent, _, app| {
.on_click(move |_: &ClickEvent, window, app| {
app.stop_propagation();
window.focus(&controls.pinned_add_focus, app);
controls.pin_collection(&id_click, app);
})
.child(
@@ -377,9 +379,23 @@ pub(super) fn render_add_pinned_menu(
scroll.style().max_size.height = Some(px(max_h).into());
let state = controls.state.clone();
let state_escape = state.clone();
let return_focus = controls.pinned_add_focus.clone();
let mut menu = div()
.id("desktop.explorer.menu")
.snapshot("desktop.explorer.menu", Some("desktop.workbench"))
.track_focus(&controls.pinned_menu_focus)
.on_key_down(move |event, window, app| {
if event.keystroke.key == "escape" {
state_escape.update(app, |state, cx| {
state.popup = None;
cx.notify();
});
window.focus(&return_focus, app);
window.prevent_default();
app.stop_propagation();
}
})
.occlude()
.flex()
.flex_col()
@@ -400,3 +416,82 @@ pub(super) fn render_add_pinned_menu(
(clamped_pos, menu)
}
#[cfg(test)]
mod tests {
use crate::{DesktopAppState, views_extra::docs_explorer::tests::ExplorerShell};
use ui::{Keystroke, PlatformInput};
use ui_tokens::ThemeMode;
#[test]
fn escape_closes_add_pinned_menu_and_focuses_its_button() {
let shell = ExplorerShell::open(
1280,
800,
DesktopAppState::seed_showcase(ThemeMode::Light, "2026-12-03"),
);
shell.click("desktop.explorer.pinned.add");
assert!(shell.contains("desktop.explorer.menu"));
shell.key("escape");
assert!(!shell.contains("desktop.explorer.menu"));
let keystroke = Keystroke::parse("enter").expect("Enter key");
shell
.window
.dispatch_input(PlatformInput::KeyDown(ui::KeyDownEvent {
keystroke: keystroke.clone(),
is_held: false,
prefer_character_input: false,
}));
shell
.window
.dispatch_input(PlatformInput::KeyUp(ui::KeyUpEvent { keystroke }));
shell.window.request_frame();
assert!(shell.contains("desktop.explorer.menu"));
}
#[test]
fn pinned_collections_bar_pins_filters_edits_unpins_and_cleans_deleted() {
let state = DesktopAppState::seed_showcase(ThemeMode::Light, "2026-12-03");
let shell = ExplorerShell::open(1280, 800, state);
assert!(shell.contains("desktop.explorer.pinned.all"));
assert!(!shell.contains("desktop.explorer.pinned.item.col-rust-core"));
// Pin `Rust Native Core` and `Design Whiteboards`.
shell.click("desktop.explorer.pinned.add");
shell.click("desktop.explorer.pinned.add_option.col-rust-core");
assert!(shell.contains("desktop.explorer.pinned.item.col-rust-core"));
shell.click("desktop.explorer.pinned.add");
shell.click("desktop.explorer.pinned.add_option.col-whiteboards");
assert!(shell.contains("desktop.explorer.pinned.item.col-whiteboards"));
// Activate `Design Whiteboards` -> filters docs to Edgeless whiteboard only.
shell.click("desktop.explorer.pinned.item.col-whiteboards");
assert!(shell.contains("desktop.list.doc.doc-board"));
assert!(!shell.contains("desktop.list.doc.doc-sync"));
assert!(shell.contains("desktop.explorer.pinned.edit"));
// Edit button opens CollectionEditor for the active pinned collection.
shell.click("desktop.explorer.pinned.edit");
assert!(shell.contains("desktop.collection_editor"));
shell.key("escape");
assert!(!shell.contains("desktop.collection_editor"));
// Deleting the active pinned collection cleans it up automatically and returns to `All`.
shell.update(|s, _, cx| {
assert!(s.state.store.delete_collection("col-whiteboards"));
cx.notify();
});
shell.window.request_frame();
assert!(!shell.contains("desktop.explorer.pinned.item.col-whiteboards"));
assert!(shell.contains("desktop.list.doc.doc-sync"));
// Unpin `col-rust-core` via inline `×`.
shell.click("desktop.explorer.pinned.item.col-rust-core");
shell.click("desktop.explorer.pinned.remove.col-rust-core");
assert!(!shell.contains("desktop.explorer.pinned.item.col-rust-core"));
}
}
@@ -10,14 +10,15 @@ use ui_tokens::ThemeMode;
use crate::{DesktopAppState, DesktopRoute, DesktopShellView, register_desktop_fonts};
struct ExplorerShell {
pub(super) struct ExplorerShell {
app: ApplicationHandle,
handle: WindowHandle<DesktopShellView>,
window: HeadlessWindow,
pub(super) window: HeadlessWindow,
platform: std::rc::Rc<HeadlessPlatform>,
}
impl ExplorerShell {
fn open(width: u32, height: u32, mut state: DesktopAppState) -> Self {
pub(super) fn open(width: u32, height: u32, mut state: DesktopAppState) -> Self {
state.navigate_active_pane(DesktopRoute::AllDocs);
let platform = HeadlessPlatform::new(width, height, 1.0);
let app = Application::with_platform(platform.clone()).run_embedded(|_| {});
@@ -41,10 +42,11 @@ impl ExplorerShell {
app,
handle,
window,
platform,
}
}
fn update<T>(
pub(super) fn update<T>(
&self,
f: impl FnOnce(&mut DesktopShellView, &mut Window, &mut Context<DesktopShellView>) -> T,
) -> T {
@@ -52,7 +54,7 @@ impl ExplorerShell {
.update(|cx| self.handle.update(cx, f).expect("desktop view"))
}
fn contains(&self, id: &str) -> bool {
pub(super) fn contains(&self, id: &str) -> bool {
self.update(|_, window, _| window.frame_snapshot().elements.contains_key(id))
}
@@ -74,7 +76,7 @@ impl ExplorerShell {
})
}
fn click(&self, id: &str) {
pub(super) fn click(&self, id: &str) {
let b = self.bounds(id);
let pos = point(px(b.x + b.width / 2.0), px(b.y + b.height / 2.0));
self.window
@@ -100,7 +102,7 @@ impl ExplorerShell {
self.window.request_frame();
}
fn key(&self, key: &'static str) {
pub(super) fn key(&self, key: &'static str) {
self.app.update(|cx| {
AnyWindowHandle::from(self.handle)
.update(cx, |_, window, cx| {
@@ -124,6 +126,261 @@ impl ExplorerShell {
}
}
fn save_pinned_frame(shell: &ExplorerShell, file: &str, dimensions: (u32, u32)) {
let Some(dir) = std::env::var_os("AFFINE_EXPLORER_PINNED_SHOT_DIR").map(PathBuf::from) else {
return;
};
std::fs::create_dir_all(&dir).expect("create shot dir");
let image = shell.update(|_, window, _| window.render_to_image().expect("render explorer"));
assert_eq!(image.dimensions(), dimensions);
image
.save(dir.join(file))
.expect("save explorer screenshot");
}
#[test]
fn removing_active_pinned_collection_selects_previous_collection() {
let shell = ExplorerShell::open(
1280,
800,
DesktopAppState::seed_showcase(ThemeMode::Light, "2026-12-03"),
);
for id in ["col-rust-core", "col-whiteboards"] {
shell.click("desktop.explorer.pinned.add");
shell.click(&format!("desktop.explorer.pinned.add_option.{id}"));
}
shell.click("desktop.explorer.pinned.item.col-whiteboards");
assert!(shell.contains("desktop.list.doc.doc-board"));
assert!(!shell.contains("desktop.list.doc.doc-sync"));
shell.click("desktop.explorer.pinned.remove.col-whiteboards");
save_pinned_frame(&shell, "pinned-unpin.png", (1280, 800));
assert!(!shell.contains("desktop.explorer.pinned.item.col-whiteboards"));
assert!(shell.contains("desktop.explorer.pinned.remove.col-rust-core"));
assert!(shell.contains("desktop.list.doc.doc-sync"));
assert!(!shell.contains("desktop.list.doc.doc-board"));
}
#[test]
fn compact_all_docs_tab_clears_hidden_collection_filter() {
let mut results = Vec::new();
for (theme, file) in [
(ThemeMode::Light, "compact-all-docs-light.png"),
(ThemeMode::Dark, "compact-all-docs-dark.png"),
] {
let mut state = DesktopAppState::seed_showcase(theme, "2026-12-03");
assert!(
state
.store
.rename_doc("doc-sync", "Offline Sync Protocol", 1_796_385_600_000,)
);
let shell = ExplorerShell::open(1280, 800, state);
shell.click("desktop.explorer.display");
shell.click("desktop.explorer.display.grouping");
shell.click("desktop.explorer.display.group.remove");
shell.key("escape");
shell.click("desktop.explorer.pinned.add");
shell.click("desktop.explorer.pinned.add_option.col-whiteboards");
shell.click("desktop.explorer.pinned.item.col-whiteboards");
assert!(shell.contains("desktop.list.doc.doc-board"));
assert!(!shell.contains("desktop.list.doc.doc-sync"));
ui::PlatformWindow::resize(&mut shell.window.clone(), size(px(640.0), px(204.0)));
shell.window.request_frame();
assert!(!shell.contains("desktop.explorer.pinned.item.col-whiteboards"));
assert!(!shell.contains("desktop.list.doc.doc-sync"));
shell.click("desktop.explorer.nav.docs");
save_pinned_frame(&shell, file, (640, 204));
let visible = shell.update(|_, window, _| {
window
.frame_snapshot()
.elements
.get("desktop.list.doc.doc-sync")
.is_some_and(|row| {
row.content_mask.contains_point(
row.bounds.x + row.bounds.width / 2.0,
row.bounds.center_y(),
)
})
});
results.push((theme, visible));
}
for (theme, visible) in results {
assert!(
visible,
"All Docs must show Offline Sync Protocol in {theme:?}"
);
}
}
#[cfg(not(target_family = "wasm"))]
const PREFS_SPACE_ID: &str = "ws-affine-desktop";
#[cfg(not(target_family = "wasm"))]
#[test]
fn display_preferences_survive_connected_sqlite_reopen_and_skip_read_only() {
use std::process::Command;
let dir = std::env::temp_dir().join(format!("desktop-explorer-prefs-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&dir);
let executable = std::env::current_exe().expect("desktop test executable");
for save_phase in ["save-before-binding", "save-after-binding"] {
let workspace_dir = dir.join(save_phase);
for phase in [save_phase, "reopen"] {
let output = Command::new(&executable)
.args([
"--exact",
"views_extra::docs_explorer::tests::sqlite_explorer_prefs_child",
"--ignored",
"--nocapture",
])
.env("AFFINE_EXPLORER_PREFS_TEST_DIR", &workspace_dir)
.env("AFFINE_EXPLORER_PREFS_TEST_PHASE", phase)
.output()
.expect("run workspace shell process");
let stdout = String::from_utf8_lossy(&output.stdout);
assert!(
output.status.success() && stdout.contains("test result: ok. 1 passed"),
"{save_phase}, {phase}: {stdout}\n{}",
String::from_utf8_lossy(&output.stderr)
);
}
}
let db_path = affine_store::sqlite::resolve_workspace_db_path(
&dir.join("save-after-binding"),
"workspace",
"local",
PREFS_SPACE_ID,
)
.expect("resolve workspace database path");
let prefs_path = db_path.with_extension("db.explorer-prefs.json");
let database = std::fs::read(&db_path).expect("read workspace bytes");
let saved_prefs = std::fs::read(&prefs_path).expect("read saved preferences");
{
let (read_only, _) =
crate::DesktopDocStore::open_sqlite_file(&db_path).expect("open read-only workspace");
assert!(read_only.is_readonly_sqlite());
let state =
DesktopAppState::from_doc_store_in_memory(read_only, ThemeMode::Light, "2026-12-04");
let shell = ExplorerShell::open(1280, 800, state);
shell.click("desktop.explorer.display");
shell.click("desktop.explorer.display.body");
}
assert_eq!(
std::fs::read(&db_path).expect("read workspace bytes"),
database
);
assert_eq!(
std::fs::read(&prefs_path).expect("read saved preferences"),
saved_prefs
);
std::fs::remove_dir_all(&dir).expect("remove explorer test databases");
}
#[cfg(not(target_family = "wasm"))]
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
#[ignore = "run by the connected Explorer preference test"]
async fn sqlite_explorer_prefs_child() {
use affine_client::{HostKind, MemoryHostBridge, SqliteSyncHost, SqliteWorkspaceStore};
use std::sync::{Arc, Mutex};
const NOW_MS: i64 = 1_796_385_600_000;
let dir =
PathBuf::from(std::env::var_os("AFFINE_EXPLORER_PREFS_TEST_DIR").expect("test directory"));
let phase = std::env::var("AFFINE_EXPLORER_PREFS_TEST_PHASE").expect("test phase");
let store = Arc::new(
SqliteWorkspaceStore::open(&dir, "workspace", "local", PREFS_SPACE_ID)
.await
.expect("open workspace database"),
);
let checkpointed_database = async || {
store
.storage()
.checkpoint()
.await
.expect("checkpoint workspace");
std::fs::read(store.storage().path()).expect("read workspace bytes")
};
let session = store
.load_workspace_session(
"desktop",
41,
HostKind::Native,
"local",
"https://example.com",
NOW_MS,
)
.await
.expect("load workspace session");
let bridge = MemoryHostBridge::new(HostKind::Native, "desktop");
let host = SqliteSyncHost::new(
store.clone(),
Arc::new(Mutex::new(bridge)),
"wss://example.com/socket.io/?EIO=4&transport=websocket".into(),
tokio::runtime::Handle::current(),
);
let shell = ExplorerShell::open(
1280,
800,
DesktopAppState::seed_showcase(ThemeMode::Light, "2026-12-04"),
);
let configure_display = || {
shell.click("desktop.explorer.display");
shell.click("desktop.explorer.display.view_grid");
shell.click("desktop.explorer.display.grouping");
shell.click("desktop.explorer.display.group.docPrimaryMode");
shell.click("desktop.explorer.display.grouping");
shell.click("desktop.explorer.display.body");
shell.key("escape");
};
let prefs_path = PathBuf::from(store.storage().path()).with_extension("db.explorer-prefs.json");
let database = checkpointed_database().await;
if phase == "save-before-binding" {
configure_display();
assert!(!prefs_path.exists());
}
shell.update(|view, _, cx| {
view.connect_workspace(Arc::new(Mutex::new(session)), host, NOW_MS, |_| {}, cx)
.expect("connect workspace");
});
shell.window.request_frame();
if phase == "save-after-binding" {
configure_display();
}
let saved = std::fs::read_to_string(&prefs_path)
.expect("preferences saved after binding and one frame");
let saved: serde_json::Value = serde_json::from_str(&saved).expect("saved preference JSON");
let all_docs = &saved["scopes"]["allDocs"];
assert_eq!(all_docs["view"], "grid");
assert_eq!(all_docs["grid"]["groupBy"]["type"], "docPrimaryMode");
assert_eq!(all_docs["grid"]["showDocPreview"], false);
assert!(shell.contains("desktop.explorer.group_header.page"));
assert!(shell.bounds("desktop.list.doc.doc-sync").height >= 148.0);
if phase == "reopen" {
let toggle_body = || {
shell.click("desktop.explorer.display");
shell.click("desktop.explorer.display.body");
shell.key("escape");
shell.update(|_, window, _| window.rendered_scene().monochrome_sprites.len())
};
let shown = toggle_body();
let hidden = toggle_body();
assert!(shown > hidden);
}
assert_eq!(checkpointed_database().await, database);
shell.update(|view, window, _| {
view.disconnect_workspace().expect("disconnect workspace");
window.remove_window();
});
shell.platform.run_until_parked();
drop(shell);
store.close().await;
}
fn seed_with_custom_properties(theme: ThemeMode) -> (DesktopAppState, String, String) {
let mut state = DesktopAppState::seed_showcase(theme, "2026-12-03");
let status_id = state
@@ -294,50 +551,6 @@ fn display_menu_clamps_to_640x400_and_supports_wheel_and_keyboard() {
assert!(!shell.contains("desktop.explorer.menu"));
}
#[test]
fn pinned_collections_bar_pins_filters_edits_unpins_and_cleans_deleted() {
let state = DesktopAppState::seed_showcase(ThemeMode::Light, "2026-12-03");
let shell = ExplorerShell::open(1280, 800, state);
assert!(shell.contains("desktop.explorer.pinned.all"));
assert!(!shell.contains("desktop.explorer.pinned.item.col-rust-core"));
// Pin `Rust Native Core` and `Design Whiteboards`.
shell.click("desktop.explorer.pinned.add");
shell.click("desktop.explorer.pinned.add_option.col-rust-core");
assert!(shell.contains("desktop.explorer.pinned.item.col-rust-core"));
shell.click("desktop.explorer.pinned.add");
shell.click("desktop.explorer.pinned.add_option.col-whiteboards");
assert!(shell.contains("desktop.explorer.pinned.item.col-whiteboards"));
// Activate `Design Whiteboards` -> filters docs to Edgeless whiteboard only.
shell.click("desktop.explorer.pinned.item.col-whiteboards");
assert!(shell.contains("desktop.list.doc.doc-board"));
assert!(!shell.contains("desktop.list.doc.doc-sync"));
assert!(shell.contains("desktop.explorer.pinned.edit"));
// Edit button opens CollectionEditor for the active pinned collection.
shell.click("desktop.explorer.pinned.edit");
assert!(shell.contains("desktop.collection_editor"));
shell.key("escape");
assert!(!shell.contains("desktop.collection_editor"));
// Deleting the active pinned collection cleans it up automatically and returns to `All`.
shell.update(|s, _, cx| {
assert!(s.state.store.delete_collection("col-whiteboards"));
cx.notify();
});
shell.window.request_frame();
assert!(!shell.contains("desktop.explorer.pinned.item.col-whiteboards"));
assert!(shell.contains("desktop.list.doc.doc-sync"));
// Unpin `col-rust-core` via inline `×`.
shell.click("desktop.explorer.pinned.item.col-rust-core");
shell.click("desktop.explorer.pinned.remove.col-rust-core");
assert!(!shell.contains("desktop.explorer.pinned.item.col-rust-core"));
}
#[test]
fn render_explorer_display_and_pinned_light_and_dark_frames() {
let out_dir = std::env::var_os("AFFINE_EXPLORER_DISPLAY_SHOT_DIR").map(PathBuf::from);
@@ -416,6 +629,7 @@ fn render_explorer_display_and_pinned_light_and_dark_frames() {
struct ExplorerTestLocalStore {
docs: std::cell::RefCell<crate::StoredWorkspaces>,
explorer_prefs: std::cell::RefCell<std::collections::BTreeMap<String, String>>,
explorer_reads: std::cell::Cell<usize>,
}
impl crate::LocalDocStore for ExplorerTestLocalStore {
@@ -444,12 +658,13 @@ impl crate::LocalDocStore for ExplorerTestLocalStore {
}
fn explorer_prefs(&self, workspace_id: &str) -> Option<String> {
self.explorer_reads.set(self.explorer_reads.get() + 1);
self.explorer_prefs.borrow().get(workspace_id).cloned()
}
}
#[test]
fn pinned_collections_and_display_prefs_survive_local_workspace_cold_reopen() {
fn pinned_collections_and_display_prefs_load_once_per_local_workspace_open() {
use std::rc::Rc;
const NOW_MS: i64 = 1_796_385_600_000;
@@ -507,6 +722,7 @@ fn pinned_collections_and_display_prefs_survive_local_workspace_cold_reopen() {
shell.update(|s, _, _| s.flush_persistence());
(doc_id, col_id)
};
assert_eq!(local.explorer_reads.get(), 1);
// Cold reopen #1: pinned collection, quick_split, and explicit Remove-group/Body-off survive.
{
@@ -558,4 +774,5 @@ fn pinned_collections_and_display_prefs_survive_local_workspace_cold_reopen() {
assert!(!shell.contains(&format!("desktop.explorer.pinned.item.{col_id}")));
assert!(shell.contains(&format!("desktop.explorer.quick_split.{doc_id}")));
}
assert_eq!(local.explorer_reads.get(), 3);
}
@@ -4,15 +4,94 @@ use super::DesktopShellView;
use crate::doc_store::{PendingUpdates, SessionWriter, merge_pending_updates};
use affine_client::{ClientError, ClientResult, SqliteSyncHost, WorkspaceSession};
use affine_store::sync::SpaceSyncEvent;
use std::sync::{Arc, Mutex};
use std::{
cell::RefCell,
fs::{self, OpenOptions},
io::{self, Write},
path::PathBuf,
sync::{
Arc, Mutex,
atomic::{AtomicUsize, Ordering},
},
};
use ui::Context;
static NEXT_PREFS_BINDING: AtomicUsize = AtomicUsize::new(1);
pub(super) struct ConnectedWorkspace {
pub(super) workspace_id: String,
save: Box<dyn Fn() -> ClientResult<()>>,
explorer_prefs: Option<RefCell<ExplorerPrefsFile>>,
_timer: ui::Task<()>,
}
struct ExplorerPrefsFile {
path: PathBuf,
binding: usize,
saved: Option<String>,
pending: Option<String>,
}
impl ExplorerPrefsFile {
fn open(host: &SqliteSyncHost) -> Option<RefCell<Self>> {
let db_path = host.writable_database_path()?;
let path = PathBuf::from(format!("{db_path}.explorer-prefs.json"));
let saved = fs::read_to_string(&path).ok();
Some(RefCell::new(Self {
path,
binding: NEXT_PREFS_BINDING.fetch_add(1, Ordering::Relaxed),
saved,
pending: None,
}))
}
fn save(&mut self, prefs: &str) -> io::Result<()> {
self.pending = (self.saved.as_deref() != Some(prefs)).then(|| prefs.to_owned());
self.flush()
}
fn flush(&mut self) -> io::Result<()> {
let Some(prefs) = &self.pending else {
return Ok(());
};
let nonce = blocksuite_playground_doc::try_random_client_id().map_err(io::Error::other)?;
let temp = self.path.with_extension(format!("json.{nonce}.tmp"));
let mut file = OpenOptions::new()
.write(true)
.create_new(true)
.open(&temp)?;
let written = file
.write_all(prefs.as_bytes())
.and_then(|()| file.sync_all());
drop(file);
if let Err(error) = written.and_then(|()| fs::rename(&temp, &self.path)) {
let _ = fs::remove_file(&temp);
return Err(error);
}
self.saved = self.pending.take();
Ok(())
}
}
impl ConnectedWorkspace {
pub(super) fn explorer_prefs_binding(&self) -> usize {
self.explorer_prefs
.as_ref()
.map_or(0, |prefs| prefs.borrow().binding)
}
pub(super) fn explorer_prefs(&self) -> Option<String> {
let prefs = self.explorer_prefs.as_ref()?.borrow();
prefs.pending.as_ref().or(prefs.saved.as_ref()).cloned()
}
pub(super) fn save_explorer_prefs(&self, prefs: &str) -> bool {
self.explorer_prefs
.as_ref()
.is_none_or(|file| file.borrow_mut().save(prefs).is_ok())
}
}
impl DesktopShellView {
pub fn connect_workspace(
&mut self,
@@ -32,6 +111,7 @@ impl DesktopShellView {
}
}
self.save_connected_workspace()?;
let explorer_prefs = ExplorerPrefsFile::open(&host);
let origin = {
let mut session = session.lock().unwrap_or_else(|e| e.into_inner());
host.connect(&mut session, now_ms)?;
@@ -41,7 +121,6 @@ impl DesktopShellView {
self.editor_host
.workspace_origins
.insert(workspace_id.clone(), origin);
cx.notify();
}
let clock = cx.background_executor().clone();
let start = clock.now();
@@ -70,6 +149,7 @@ impl DesktopShellView {
self.connection = Some(ConnectedWorkspace {
workspace_id,
save,
explorer_prefs,
_timer: cx.spawn(async move |view, _cx| {
loop {
clock.timer(SqliteSyncHost::INTERVAL).await;
@@ -93,12 +173,19 @@ impl DesktopShellView {
}
}),
});
cx.notify();
Ok(())
}
pub(super) fn save_connected_workspace(&self) -> ClientResult<()> {
if let Some(connection) = &self.connection {
(connection.save)()?;
if let Some(prefs) = &connection.explorer_prefs {
prefs
.borrow_mut()
.flush()
.map_err(|e| ClientError::Store(format!("write explorer preferences: {e}")))?;
}
}
Ok(())
}
@@ -687,26 +687,53 @@ impl DesktopShellView {
}
}
/// Read serialized explorer preferences from the bound `LocalDocStore`, paired with a
/// binding identity token so prefs re-hydrate if `bind_local_workspaces` ran after frame 1.
pub(crate) fn local_explorer_prefs(&self, workspace_id: &str) -> (usize, Option<String>) {
let Some(local) = &self.local else {
return (0, None);
};
(
Rc::as_ptr(&local.workspaces) as usize,
local.workspaces.store.explorer_prefs(workspace_id),
)
/// Return the identity of the workspace preference binding without reading it.
pub(crate) fn explorer_prefs_binding(&self, workspace_id: &str) -> usize {
#[cfg(not(target_family = "wasm"))]
if let Some(connection) = &self.connection
&& connection.workspace_id == workspace_id
{
return connection.explorer_prefs_binding();
}
#[cfg(target_family = "wasm")]
let _ = workspace_id;
self.local
.as_ref()
.map_or(0, |local| Rc::as_ptr(&local.workspaces) as usize)
}
/// Write serialized explorer preferences to the bound `LocalDocStore`.
pub(crate) fn save_local_explorer_prefs(&self, workspace_id: &str, prefs: &str) {
pub(crate) fn local_explorer_prefs(&self, workspace_id: &str) -> Option<String> {
#[cfg(not(target_family = "wasm"))]
if let Some(connection) = &self.connection
&& connection.workspace_id == workspace_id
{
return connection.explorer_prefs();
}
self.local
.as_ref()?
.workspaces
.store
.explorer_prefs(workspace_id)
}
/// Write the explorer preferences to the active workspace binding.
pub(crate) fn save_local_explorer_prefs(&self, workspace_id: &str, prefs: &str) -> bool {
if self.state.store.is_readonly_sqlite() {
return true;
}
#[cfg(not(target_family = "wasm"))]
if let Some(connection) = &self.connection
&& connection.workspace_id == workspace_id
{
return connection.save_explorer_prefs(prefs);
}
if let Some(local) = &self.local {
local
.workspaces
.store
.set_explorer_prefs(workspace_id, prefs);
}
true
}
}