Skip to content

Commit b055d27

Browse files
feat: Add getWorkspaceMeta plugin API
Add a new plugin API endpoint that allows plugins to retrieve workspace metadata including sync directory setting. - Add GetWorkspaceMetaRequest/Response types to Rust events - Handle GetWorkspaceMetaRequest in plugin events handler - Add getMeta() method to workspace context in plugin runtime - Update TypeScript bindings for both yaak-plugins and plugin-runtime-types
1 parent e4828e1 commit b055d27

6 files changed

Lines changed: 47 additions & 10 deletions

File tree

crates-tauri/yaak-app/src/plugin_events.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,7 @@ use yaak_models::queries::any_request::AnyRequest;
2121
use crate::models_ext::QueryManagerExt;
2222
use yaak_models::util::UpdateSource;
2323
use yaak_plugins::error::Error::PluginErr;
24-
use yaak_plugins::events::{
25-
Color, DeleteKeyValueResponse, EmptyPayload, ErrorResponse, FindHttpResponsesResponse,
26-
GetCookieValueResponse, GetHttpRequestByIdResponse, GetKeyValueResponse, Icon, InternalEvent,
27-
InternalEventPayload, ListCookieNamesResponse, ListHttpRequestsResponse,
28-
ListWorkspacesResponse, RenderGrpcRequestResponse, RenderHttpRequestResponse,
29-
SendHttpRequestResponse, SetKeyValueResponse, ShowToastRequest, TemplateRenderResponse,
30-
WindowInfoResponse, WindowNavigateEvent, WorkspaceInfo,
31-
};
24+
use yaak_plugins::events::{Color, DeleteKeyValueResponse, EmptyPayload, ErrorResponse, FindHttpResponsesResponse, GetCookieValueResponse, GetHttpRequestByIdResponse, GetKeyValueResponse, GetWorkspaceMetaResponse, Icon, InternalEvent, InternalEventPayload, ListCookieNamesResponse, ListHttpRequestsResponse, ListWorkspacesResponse, RenderGrpcRequestResponse, RenderHttpRequestResponse, SendHttpRequestResponse, SetKeyValueResponse, ShowToastRequest, TemplateRenderResponse, WindowInfoResponse, WindowNavigateEvent, WorkspaceInfo};
3225
use yaak_plugins::manager::PluginManager;
3326
use yaak_plugins::plugin_handle::PluginHandle;
3427
use yaak_plugins::template_callback::PluginTemplateCallback;
@@ -474,6 +467,17 @@ pub(crate) async fn handle_plugin_event<R: Runtime>(
474467
})))
475468
}
476469

470+
InternalEventPayload::GetWorkspaceMetaRequest(_) => {
471+
let window = get_window_from_plugin_context(app_handle, &plugin_context)?;
472+
let workspace = workspace_from_window(&window)
473+
.ok_or(PluginErr("Failed to get workspace from window".into()))?;
474+
let workspace_meta = app_handle.db().get_or_create_workspace_meta(&workspace.id)?;
475+
Ok(Some(InternalEventPayload::GetWorkspaceMetaResponse(GetWorkspaceMetaResponse {
476+
id: workspace_meta.id,
477+
setting_sync_dir: workspace_meta.setting_sync_dir,
478+
})))
479+
}
480+
477481
_ => Ok(None),
478482
}
479483
}

crates/yaak-plugins/bindings/gen_events.ts

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/yaak-plugins/src/events.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ pub enum InternalEventPayload {
166166
ListWorkspacesRequest(ListWorkspacesRequest),
167167
ListWorkspacesResponse(ListWorkspacesResponse),
168168

169+
GetWorkspaceMetaRequest(GetWorkspaceMetaRequest),
170+
GetWorkspaceMetaResponse(GetWorkspaceMetaResponse),
171+
169172
GetHttpRequestByIdRequest(GetHttpRequestByIdRequest),
170173
GetHttpRequestByIdResponse(GetHttpRequestByIdResponse),
171174

@@ -618,6 +621,19 @@ pub struct WindowInfoResponse {
618621
#[ts(export, export_to = "gen_events.ts")]
619622
pub struct ListWorkspacesRequest {}
620623

624+
#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)]
625+
#[serde(default, rename_all = "camelCase")]
626+
#[ts(export, export_to = "gen_events.ts")]
627+
pub struct GetWorkspaceMetaRequest {}
628+
629+
#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)]
630+
#[serde(default, rename_all = "camelCase")]
631+
#[ts(export, export_to = "gen_events.ts")]
632+
pub struct GetWorkspaceMetaResponse {
633+
pub id: String,
634+
pub setting_sync_dir: Option<String>,
635+
}
636+
621637
#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)]
622638
#[serde(default, rename_all = "camelCase")]
623639
#[ts(export, export_to = "gen_events.ts")]

0 commit comments

Comments
 (0)