feat(spaceshd): pinned workspace field

Add a `pinned` bool to the workspace model, threaded through proto
(Workspace + WorkspaceView + SetWorkspaceMeta), the registry, the
set_workspace_meta handler, persistence, the CLI mapping, and the Tauri
bridge. serde(default) keeps existing state.json compatible (pinned=false).
Backs the sidebar Favorites section.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-14 08:56:09 +07:00
parent 2c8ac8ebac
commit 7b47052a6f
7 changed files with 32 additions and 6 deletions
+2 -2
View File
@@ -269,14 +269,14 @@ pub async fn close_workspace(state: BridgeState<'_>, workspace_id: String) -> Re
}
#[tauri::command]
pub async fn set_workspace_meta(state: BridgeState<'_>, workspace_id: String, name: Option<String>, group_id: Option<String>, unread: Option<bool>, order: Option<u32>) -> Result<Value, String> {
pub async fn set_workspace_meta(state: BridgeState<'_>, workspace_id: String, name: Option<String>, group_id: Option<String>, unread: Option<bool>, order: Option<u32>, pinned: Option<bool>) -> Result<Value, String> {
// group_id: None from JS means "no change"; an explicit null is sent as Some("") to mean "ungroup".
let gid = match group_id {
None => None,
Some(s) if s.is_empty() => Some(None),
Some(s) => Some(Some(GroupId(s))),
};
data_of(state.request(Cmd::SetWorkspaceMeta { workspace_id: WorkspaceId(workspace_id), name, group_id: gid, unread, order }).await.map_err(|e| e.to_string())?)
data_of(state.request(Cmd::SetWorkspaceMeta { workspace_id: WorkspaceId(workspace_id), name, group_id: gid, unread, order, pinned }).await.map_err(|e| e.to_string())?)
}
#[tauri::command]
+1
View File
@@ -61,6 +61,7 @@ pub fn to_cmd(sub: Sub) -> Cmd {
group_id: group.map(|g| if g.is_empty() { None } else { Some(GroupId(g)) }),
unread,
order,
pinned: None,
},
Sub::Shutdown => Cmd::Shutdown,
Sub::Completions { .. } => unreachable!("completions handled before dispatch"),
+2
View File
@@ -104,6 +104,8 @@ pub enum Cmd {
unread: Option<bool>,
#[serde(default, skip_serializing_if = "Option::is_none")]
order: Option<u32>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pinned: Option<bool>,
},
CreateGroup { name: String, color: String },
SetGroup {
+22 -1
View File
@@ -39,6 +39,9 @@ pub struct Workspace {
pub order: u32,
#[serde(default)]
pub unread: bool,
/// Pinned to the sidebar's Favorites section.
#[serde(default)]
pub pinned: bool,
/// None = empty workspace (no panels yet).
#[serde(default)]
pub layout: Option<LayoutNode>,
@@ -68,6 +71,8 @@ pub struct WorkspaceView {
pub group_id: Option<GroupId>,
pub order: u32,
pub unread: bool,
#[serde(default)]
pub pinned: bool,
pub layout: Option<LayoutNode>,
#[serde(default)]
pub zoomed: Option<SurfaceId>,
@@ -103,6 +108,7 @@ mod tests {
group_id: None,
order: 0,
unread: false,
pinned: false,
layout: None,
zoomed: None,
surfaces: HashMap::new(),
@@ -112,11 +118,26 @@ mod tests {
assert_eq!(back, w);
}
#[test]
fn workspace_pinned_round_trips_and_defaults_false() {
let w = Workspace {
id: WorkspaceId("w_1".into()), path: "/tmp/p".into(), name: "p".into(),
group_id: None, order: 0, unread: false, pinned: true, layout: None,
zoomed: None, surfaces: HashMap::new(),
};
let back: Workspace = serde_json::from_str(&serde_json::to_string(&w).unwrap()).unwrap();
assert!(back.pinned);
// Old state.json without the field deserializes to pinned=false.
let legacy = r#"{"id":"w_1","path":"/tmp/p","name":"p","order":0,"surfaces":{}}"#;
let old: Workspace = serde_json::from_str(legacy).unwrap();
assert!(!old.pinned);
}
#[test]
fn workspace_round_trips_with_zoom() {
let w = Workspace {
id: WorkspaceId("w_1".into()), path: "/tmp/p".into(), name: "p".into(),
group_id: None, order: 0, unread: false, layout: None,
group_id: None, order: 0, unread: false, pinned: false, layout: None,
zoomed: Some(SurfaceId("s_1".into())), surfaces: HashMap::new(),
};
let back: Workspace = serde_json::from_str(&serde_json::to_string(&w).unwrap()).unwrap();
+2 -2
View File
@@ -51,7 +51,7 @@ impl Registry {
let order = self.workspaces.len() as u32;
self.workspaces.insert(id.clone(), Workspace {
id: id.clone(), path: key.clone(), name, group_id: None, order,
unread: false, layout: None, zoomed: None, surfaces: HashMap::new(),
unread: false, pinned: false, layout: None, zoomed: None, surfaces: HashMap::new(),
});
self.by_path.insert(key, id.clone());
(id, true)
@@ -168,7 +168,7 @@ impl Registry {
}).collect();
WorkspaceView {
id: w.id.clone(), path: w.path.clone(), name: w.name.clone(),
group_id: w.group_id.clone(), order: w.order, unread: w.unread,
group_id: w.group_id.clone(), order: w.order, unread: w.unread, pinned: w.pinned,
layout: w.layout.clone(), zoomed: w.zoomed.clone(), surfaces,
}
}
+2 -1
View File
@@ -461,12 +461,13 @@ async fn handle_request(
let _ = out.send(ok(id, serde_json::Value::Null)).await;
}
Cmd::SetWorkspaceMeta { workspace_id, name, group_id, unread, order } => {
Cmd::SetWorkspaceMeta { workspace_id, name, group_id, unread, order, pinned } => {
let found = reg.workspace_mut(&workspace_id).map(|w| {
if let Some(n) = name { w.name = n; }
if let Some(g) = group_id { w.group_id = g; }
if let Some(u) = unread { w.unread = u; }
if let Some(o) = order { w.order = o; }
if let Some(p) = pinned { w.pinned = p; }
}).is_some();
if found {
if let Some(view) = reg.workspace_view(&workspace_id) {
+1
View File
@@ -92,6 +92,7 @@ mod tests {
group_id: None,
order: 0,
unread: false,
pinned: false,
layout: None,
zoomed: None,
surfaces: std::collections::HashMap::new(),