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:
@@ -269,14 +269,14 @@ pub async fn close_workspace(state: BridgeState<'_>, workspace_id: String) -> Re
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[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".
|
// group_id: None from JS means "no change"; an explicit null is sent as Some("") to mean "ungroup".
|
||||||
let gid = match group_id {
|
let gid = match group_id {
|
||||||
None => None,
|
None => None,
|
||||||
Some(s) if s.is_empty() => Some(None),
|
Some(s) if s.is_empty() => Some(None),
|
||||||
Some(s) => Some(Some(GroupId(s))),
|
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]
|
#[tauri::command]
|
||||||
|
|||||||
@@ -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)) }),
|
group_id: group.map(|g| if g.is_empty() { None } else { Some(GroupId(g)) }),
|
||||||
unread,
|
unread,
|
||||||
order,
|
order,
|
||||||
|
pinned: None,
|
||||||
},
|
},
|
||||||
Sub::Shutdown => Cmd::Shutdown,
|
Sub::Shutdown => Cmd::Shutdown,
|
||||||
Sub::Completions { .. } => unreachable!("completions handled before dispatch"),
|
Sub::Completions { .. } => unreachable!("completions handled before dispatch"),
|
||||||
|
|||||||
@@ -104,6 +104,8 @@ pub enum Cmd {
|
|||||||
unread: Option<bool>,
|
unread: Option<bool>,
|
||||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
order: Option<u32>,
|
order: Option<u32>,
|
||||||
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
|
pinned: Option<bool>,
|
||||||
},
|
},
|
||||||
CreateGroup { name: String, color: String },
|
CreateGroup { name: String, color: String },
|
||||||
SetGroup {
|
SetGroup {
|
||||||
|
|||||||
@@ -39,6 +39,9 @@ pub struct Workspace {
|
|||||||
pub order: u32,
|
pub order: u32,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub unread: bool,
|
pub unread: bool,
|
||||||
|
/// Pinned to the sidebar's Favorites section.
|
||||||
|
#[serde(default)]
|
||||||
|
pub pinned: bool,
|
||||||
/// None = empty workspace (no panels yet).
|
/// None = empty workspace (no panels yet).
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub layout: Option<LayoutNode>,
|
pub layout: Option<LayoutNode>,
|
||||||
@@ -68,6 +71,8 @@ pub struct WorkspaceView {
|
|||||||
pub group_id: Option<GroupId>,
|
pub group_id: Option<GroupId>,
|
||||||
pub order: u32,
|
pub order: u32,
|
||||||
pub unread: bool,
|
pub unread: bool,
|
||||||
|
#[serde(default)]
|
||||||
|
pub pinned: bool,
|
||||||
pub layout: Option<LayoutNode>,
|
pub layout: Option<LayoutNode>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub zoomed: Option<SurfaceId>,
|
pub zoomed: Option<SurfaceId>,
|
||||||
@@ -103,6 +108,7 @@ mod tests {
|
|||||||
group_id: None,
|
group_id: None,
|
||||||
order: 0,
|
order: 0,
|
||||||
unread: false,
|
unread: false,
|
||||||
|
pinned: false,
|
||||||
layout: None,
|
layout: None,
|
||||||
zoomed: None,
|
zoomed: None,
|
||||||
surfaces: HashMap::new(),
|
surfaces: HashMap::new(),
|
||||||
@@ -112,11 +118,26 @@ mod tests {
|
|||||||
assert_eq!(back, w);
|
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]
|
#[test]
|
||||||
fn workspace_round_trips_with_zoom() {
|
fn workspace_round_trips_with_zoom() {
|
||||||
let w = Workspace {
|
let w = Workspace {
|
||||||
id: WorkspaceId("w_1".into()), path: "/tmp/p".into(), name: "p".into(),
|
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(),
|
zoomed: Some(SurfaceId("s_1".into())), surfaces: HashMap::new(),
|
||||||
};
|
};
|
||||||
let back: Workspace = serde_json::from_str(&serde_json::to_string(&w).unwrap()).unwrap();
|
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;
|
let order = self.workspaces.len() as u32;
|
||||||
self.workspaces.insert(id.clone(), Workspace {
|
self.workspaces.insert(id.clone(), Workspace {
|
||||||
id: id.clone(), path: key.clone(), name, group_id: None, order,
|
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());
|
self.by_path.insert(key, id.clone());
|
||||||
(id, true)
|
(id, true)
|
||||||
@@ -168,7 +168,7 @@ impl Registry {
|
|||||||
}).collect();
|
}).collect();
|
||||||
WorkspaceView {
|
WorkspaceView {
|
||||||
id: w.id.clone(), path: w.path.clone(), name: w.name.clone(),
|
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,
|
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;
|
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| {
|
let found = reg.workspace_mut(&workspace_id).map(|w| {
|
||||||
if let Some(n) = name { w.name = n; }
|
if let Some(n) = name { w.name = n; }
|
||||||
if let Some(g) = group_id { w.group_id = g; }
|
if let Some(g) = group_id { w.group_id = g; }
|
||||||
if let Some(u) = unread { w.unread = u; }
|
if let Some(u) = unread { w.unread = u; }
|
||||||
if let Some(o) = order { w.order = o; }
|
if let Some(o) = order { w.order = o; }
|
||||||
|
if let Some(p) = pinned { w.pinned = p; }
|
||||||
}).is_some();
|
}).is_some();
|
||||||
if found {
|
if found {
|
||||||
if let Some(view) = reg.workspace_view(&workspace_id) {
|
if let Some(view) = reg.workspace_view(&workspace_id) {
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ mod tests {
|
|||||||
group_id: None,
|
group_id: None,
|
||||||
order: 0,
|
order: 0,
|
||||||
unread: false,
|
unread: false,
|
||||||
|
pinned: false,
|
||||||
layout: None,
|
layout: None,
|
||||||
zoomed: None,
|
zoomed: None,
|
||||||
surfaces: std::collections::HashMap::new(),
|
surfaces: std::collections::HashMap::new(),
|
||||||
|
|||||||
Reference in New Issue
Block a user