diff --git a/apps/yaak-client/components/GlobalHooks.tsx b/apps/yaak-client/components/GlobalHooks.tsx index 44744fef4..240ab9848 100644 --- a/apps/yaak-client/components/GlobalHooks.tsx +++ b/apps/yaak-client/components/GlobalHooks.tsx @@ -1,3 +1,4 @@ +import type { NavigateWorkspace } from "@yaakapp-internal/tauri-client"; import { activeRequestAtom } from "../hooks/useActiveRequest"; import { useSubscribeActiveWorkspaceId } from "../hooks/useActiveWorkspace"; import { useActiveWorkspaceChangedToast } from "../hooks/useActiveWorkspaceChangedToast"; @@ -31,6 +32,16 @@ export function GlobalHooks() { fireAndForget(router.navigate({ to: "/", search: { home: true } })); }); + usePlatformEvent("navigate_workspace", ({ workspaceId, environmentId }) => { + fireAndForget( + router.navigate({ + to: "/workspaces/$workspaceId", + params: { workspaceId }, + search: { environment_id: environmentId }, + }), + ); + }); + useHotKey( "request.rename", async () => { diff --git a/crates-tauri/yaak-app-client/bindings/index.ts b/crates-tauri/yaak-app-client/bindings/index.ts index 6fb02079c..55e7db086 100644 --- a/crates-tauri/yaak-app-client/bindings/index.ts +++ b/crates-tauri/yaak-app-client/bindings/index.ts @@ -1,5 +1,7 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +export type NavigateWorkspace = { workspaceId: string; environmentId: string | null }; + export type PluginUpdateInfo = { name: string; currentVersion: string; latestVersion: string }; export type PluginUpdateNotification = { updateCount: number; plugins: Array }; diff --git a/crates-tauri/yaak-app-client/src/uri_scheme.rs b/crates-tauri/yaak-app-client/src/uri_scheme.rs index e6bd13dab..ee6d51ea3 100644 --- a/crates-tauri/yaak-app-client/src/uri_scheme.rs +++ b/crates-tauri/yaak-app-client/src/uri_scheme.rs @@ -3,16 +3,26 @@ use crate::error::Result; use crate::import::{file_origin, import_data, url_origin}; use crate::models_ext::QueryManagerExt; use log::{info, warn}; +use serde::Serialize; use std::collections::HashMap; use std::fs; use std::sync::Arc; use tauri::{AppHandle, Emitter, Manager, Runtime, Url}; use tauri_plugin_dialog::{DialogExt, MessageDialogButtons, MessageDialogKind}; +use ts_rs::TS; use yaak_api::{ApiClientKind, yaak_api_client}; use yaak_models::util::generate_id; use yaak_plugins::events::{Color, ShowToastRequest}; use yaak_plugins::install::download_and_install; +#[derive(Debug, Clone, Serialize, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export, export_to = "index.ts")] +pub struct NavigateWorkspace { + workspace_id: String, + environment_id: Option, +} + pub(crate) async fn handle_deep_link( app_handle: &AppHandle, url: &Url, @@ -129,6 +139,15 @@ pub(crate) async fn handle_deep_link( timeout: Some(5000), }, )?; + if let Some(workspace) = results.workspaces.first() { + window.emit( + "navigate_workspace", + NavigateWorkspace { + workspace_id: workspace.id.clone(), + environment_id: results.environments.first().map(|e| e.id.clone()), + }, + )?; + } } _ => { warn!("Unknown deep link command: {command}");