agent_hub_runtime/commands/
workspaces.rs1use crate::{core::error::AppError, desktop::workspaces};
3
4#[derive(serde::Serialize)]
5pub struct WorkspaceProject {
6 project: super::projects::ProjectDto,
7 directory: String,
8 visits: Vec<(String, Option<i64>)>,
9}
10
11#[tauri::command]
12pub async fn resolve_workspace_project(
13 app: tauri::AppHandle,
14 store: tauri::State<'_, std::sync::Arc<crate::core::skill_store::SkillStore>>,
15 path: String,
16) -> Result<WorkspaceProject, AppError> {
17 let store = store.inner().clone();
18 let opened =
19 tauri::async_runtime::spawn_blocking(move || -> Result<WorkspaceProject, AppError> {
20 let directory = std::path::Path::new(&path)
21 .canonicalize()
22 .map_err(AppError::io)?;
23 let id = crate::core::workspace_registration::resolve_project(&store, &directory)
24 .map_err(AppError::io)?;
25 store.touch_project_visited(&id).map_err(AppError::db)?;
26 let project = store
27 .get_project_by_id(&id)
28 .map_err(AppError::db)?
29 .ok_or_else(|| AppError::invalid_input("Project is no longer registered"))?;
30 Ok(WorkspaceProject {
31 project: super::projects::project_metadata(&project),
32 directory: directory.to_string_lossy().into(),
33 visits: store.project_visit_history().map_err(AppError::db)?,
34 })
35 })
36 .await??;
37 tauri::Emitter::emit(&app, "project-visits-changed", &opened.visits).map_err(AppError::io)?;
38 Ok(opened)
39}
40
41#[tauri::command]
42pub async fn open_workspace_window(
43 app: tauri::AppHandle,
44 path: String,
45) -> Result<String, AppError> {
46 workspaces::open(app, path).await
47}
48#[tauri::command]
49pub fn workspace_window_count(app: tauri::AppHandle) -> usize {
50 workspaces::count(&app)
51}
52#[tauri::command]
53pub fn close_workspace_window(webview: tauri::Webview) -> Result<(), AppError> {
54 workspaces::close(webview)
55}
56#[tauri::command]
57pub fn workspace_quit_reply(
58 webview: tauri::Webview,
59 token: String,
60 ready: bool,
61) -> Result<(), AppError> {
62 workspaces::quit_reply(webview, token, ready)
63}