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:
@@ -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"),
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -92,6 +92,7 @@ mod tests {
|
||||
group_id: None,
|
||||
order: 0,
|
||||
unread: false,
|
||||
pinned: false,
|
||||
layout: None,
|
||||
zoomed: None,
|
||||
surfaces: std::collections::HashMap::new(),
|
||||
|
||||
Reference in New Issue
Block a user