-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathutils.ts
More file actions
35 lines (31 loc) · 947 Bytes
/
utils.ts
File metadata and controls
35 lines (31 loc) · 947 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { open, showHUD } from "@raycast/api";
const SCHEME = "cap-desktop";
type DeepLinkAction = string | Record<string, unknown>;
/**
* Build a Cap deeplink URL.
*
* Actions are sent as: cap-desktop://action?value=<json>
*
* Unit variants (e.g. StopRecording) serialize as a plain string: "stop_recording"
* Struct variants serialize as: {"start_recording": {...}}
*/
export function buildDeepLink(action: DeepLinkAction): string {
const json = JSON.stringify(action);
return `${SCHEME}://action?value=${encodeURIComponent(json)}`;
}
/**
* Open a Cap deeplink and show a HUD message.
* Shows an error HUD if Cap is not running or the deeplink fails.
*/
export async function triggerDeepLink(
action: DeepLinkAction,
hudMessage: string,
): Promise<void> {
const url = buildDeepLink(action);
try {
await open(url);
await showHUD(hudMessage);
} catch {
await showHUD("❌ Failed — is Cap running?");
}
}