Skip to content

Commit cfc41b2

Browse files
authored
change-hook-args (#1733)
1 parent f6c6ea2 commit cfc41b2

File tree

11 files changed

+416
-181
lines changed

11 files changed

+416
-181
lines changed

apps/desktop/src/store/zustand/listener/general.ts

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { getName } from "@tauri-apps/api/app";
2+
import { appDataDir } from "@tauri-apps/api/path";
13
import { Effect, Exit } from "effect";
24
import { create as mutate } from "mutative";
35
import type { StoreApi } from "zustand";
@@ -202,9 +204,18 @@ export const createGeneralSlice = <
202204
}),
203205
);
204206

205-
hooksCommands
206-
.runEventHooks({
207-
beforeListeningStarted: { args: { session_id: targetSessionId } },
207+
Promise.all([appDataDir(), getName().catch(() => "com.hyprnote.app")])
208+
.then(([dataDirPath, appName]) => {
209+
const sessionPath = `${dataDirPath}/hyprnote/sessions/${targetSessionId}`;
210+
return hooksCommands.runEventHooks({
211+
beforeListeningStarted: {
212+
args: {
213+
resource_dir: sessionPath,
214+
app_hyprnote: appName,
215+
app_meeting: null,
216+
},
217+
},
218+
});
208219
})
209220
.catch((error) => {
210221
console.error("[hooks] BeforeListeningStarted failed:", error);
@@ -264,9 +275,21 @@ export const createGeneralSlice = <
264275
},
265276
onSuccess: () => {
266277
if (sessionId) {
267-
hooksCommands
268-
.runEventHooks({
269-
afterListeningStopped: { args: { session_id: sessionId } },
278+
Promise.all([
279+
appDataDir(),
280+
getName().catch(() => "com.hyprnote.app"),
281+
])
282+
.then(([dataDirPath, appName]) => {
283+
const sessionPath = `${dataDirPath}/hyprnote/sessions/${sessionId}`;
284+
return hooksCommands.runEventHooks({
285+
afterListeningStopped: {
286+
args: {
287+
resource_dir: sessionPath,
288+
app_hyprnote: appName,
289+
app_meeting: null,
290+
},
291+
},
292+
});
270293
})
271294
.catch((error) => {
272295
console.error("[hooks] AfterListeningStopped failed:", error);

apps/web/content-collections.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ const hooks = defineCollection({
267267
name: z.string(),
268268
type_name: z.string(),
269269
description: z.string(),
270+
optional: z.boolean().default(false),
270271
}),
271272
)
272273
.optional(),
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
---
22
name: afterListeningStopped
3-
description: '123'
3+
description: Arguments passed to hooks triggered after listening stops.
44
args:
5-
- name: session_id
6-
description: '345'
5+
- name: --resource-dir
6+
description: Path to the resource directory.
77
type_name: string
8+
- name: --app-hyprnote
9+
description: Application-specific Hyprnote data.
10+
type_name: string
11+
- name: --app-meeting
12+
description: Optional meeting-specific data.
13+
type_name: string
14+
optional: true
815
---
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
---
22
name: beforeListeningStarted
3-
description: '123'
3+
description: Arguments passed to hooks triggered before listening starts.
44
args:
5-
- name: session_id
6-
description: '345'
5+
- name: --resource-dir
6+
description: Path to the resource directory.
77
type_name: string
8+
- name: --app-hyprnote
9+
description: Application-specific Hyprnote data.
10+
type_name: string
11+
- name: --app-meeting
12+
description: Optional meeting-specific data.
13+
type_name: string
14+
optional: true
815
---

apps/web/src/components/hooks-list.tsx

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,63 @@ export function HooksList() {
99
}
1010

1111
return (
12-
<div className="space-y-8 mt-8">
12+
<div className="space-y-10 mt-6">
1313
{hooks.map((hook) => (
14-
<section key={hook.slug} className="border-t pt-6">
15-
<h2 id={hook.name} className="scroll-mt-20">
16-
{hook.name}
17-
</h2>
18-
{hook.description && (
19-
<p className="mt-2 text-neutral-600">{hook.description}</p>
20-
)}
14+
<section
15+
key={hook.slug}
16+
className="border-t pt-2 first:border-t-0 first:pt-0"
17+
>
18+
<div className="space-y-1">
19+
<h2
20+
id={hook.name}
21+
className="scroll-mt-24 text-xl font-bold tracking-tight text-neutral-900"
22+
>
23+
{hook.name}
24+
</h2>
25+
{hook.description && (
26+
<p className="text-neutral-600 leading-relaxed">
27+
{hook.description}
28+
</p>
29+
)}
30+
</div>
31+
2132
{hook.args && hook.args.length > 0 && (
22-
<div className="mt-4">
23-
<h3 className="text-lg font-medium mb-2">Arguments</h3>
24-
<div className="space-y-2">
33+
<div className="mt-4 rounded-lg border border-neutral-200 bg-neutral-50/50 px-3 pb-3 pt-2 sm:px-4 sm:pb-4 sm:pt-3">
34+
<h3 className="mb-2 font-mono text-[10px] font-bold uppercase leading-none tracking-wider text-neutral-500/80">
35+
Arguments
36+
</h3>
37+
<div className="space-y-3">
2538
{hook.args.map((arg) => (
2639
<div
2740
key={arg.name}
28-
className="border-l-2 border-neutral-200 pl-4"
41+
className="group grid grid-cols-1 gap-1.5 sm:grid-cols-[180px_1fr] sm:gap-4"
2942
>
30-
<div className="font-mono text-sm">
31-
<span className="font-semibold">{arg.name}</span>
32-
<span className="text-neutral-500">
33-
{" "}
34-
: {arg.type_name}
35-
</span>
43+
<div className="flex flex-col items-start gap-1">
44+
<code className="rounded bg-white px-1.5 py-0.5 text-xs font-semibold text-neutral-900 shadow-sm ring-1 ring-neutral-200 font-mono">
45+
{arg.name}
46+
</code>
47+
<div className="flex items-center gap-1.5 px-0.5 font-mono text-[10px] text-neutral-500">
48+
<span>{arg.type_name}</span>
49+
{arg.optional && (
50+
<>
51+
<span className="h-0.5 w-0.5 rounded-full bg-neutral-300" />
52+
<span className="italic text-neutral-400">
53+
optional
54+
</span>
55+
</>
56+
)}
57+
</div>
58+
</div>
59+
<div className="text-sm leading-relaxed text-neutral-600">
60+
{arg.description}
3661
</div>
37-
{arg.description && (
38-
<p className="text-sm text-neutral-600 mt-1">
39-
{arg.description}
40-
</p>
41-
)}
4262
</div>
4363
))}
4464
</div>
4565
</div>
4666
)}
47-
<div className="mt-4">
67+
68+
<div className="mt-4 prose prose-sm prose-neutral max-w-none prose-headings:scroll-mt-24 prose-headings:font-semibold prose-p:leading-relaxed">
4869
<MDXContent code={hook.mdx} />
4970
</div>
5071
</section>

plugins/hooks/js/bindings.gen.ts

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,56 @@ async runEventHooks(event: HookEvent) : Promise<Result<null, string>> {
2828
/** user-defined types **/
2929

3030
/**
31-
* 123
31+
* Arguments passed to hooks triggered after listening stops.
3232
*/
3333
export type AfterListeningStoppedArgs = {
3434
/**
35-
* 345
35+
* Path to the resource directory.
3636
*/
37-
session_id: string }
37+
resource_dir: string;
3838
/**
39-
* 123
39+
* Application-specific Hyprnote data.
40+
*/
41+
app_hyprnote: string;
42+
/**
43+
* Optional meeting-specific data.
44+
*/
45+
app_meeting?: string | null }
46+
/**
47+
* Arguments passed to hooks triggered before listening starts.
4048
*/
4149
export type BeforeListeningStartedArgs = {
4250
/**
43-
* 345
51+
* Path to the resource directory.
52+
*/
53+
resource_dir: string;
54+
/**
55+
* Application-specific Hyprnote data.
56+
*/
57+
app_hyprnote: string;
58+
/**
59+
* Optional meeting-specific data.
60+
*/
61+
app_meeting?: string | null }
62+
/**
63+
* Defines a single hook to be executed on an event.
64+
*/
65+
export type HookDefinition = {
66+
/**
67+
* Shell command to execute when the hook is triggered.
4468
*/
45-
session_id: string }
46-
export type HookDefinition = { command: string }
69+
command: string }
4770
export type HookEvent = { afterListeningStopped: { args: AfterListeningStoppedArgs } } | { beforeListeningStarted: { args: BeforeListeningStartedArgs } }
4871
/**
49-
* 123
72+
* Configuration for hook execution.
5073
*/
5174
export type HooksConfig = {
5275
/**
53-
* 345
76+
* Configuration schema version.
5477
*/
5578
version: number;
5679
/**
57-
* 678
80+
* Map of event names to their associated hook definitions.
5881
*/
5982
hooks?: Partial<{ [key in string]: HookDefinition[] }> }
6083

plugins/hooks/src/config.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@ use serde::{Deserialize, Serialize};
22
use std::collections::HashMap;
33
use std::path::PathBuf;
44

5-
/// 123
5+
/// Configuration for hook execution.
66
#[derive(Debug, Clone, Serialize, Deserialize, specta::Type)]
77
pub struct HooksConfig {
8-
/// 345
8+
/// Configuration schema version.
99
pub version: u8,
10-
/// 678
10+
/// Map of event names to their associated hook definitions.
1111
#[serde(default)]
1212
pub hooks: HashMap<String, Vec<HookDefinition>>,
1313
}
1414

15+
/// Defines a single hook to be executed on an event.
1516
#[derive(Debug, Clone, Serialize, Deserialize, specta::Type)]
1617
pub struct HookDefinition {
18+
/// Shell command to execute when the hook is triggered.
1719
pub command: String,
1820
}
1921

0 commit comments

Comments
 (0)