Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions apps/desktop/src/store/zustand/listener/general.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getName } from "@tauri-apps/api/app";
import { appDataDir } from "@tauri-apps/api/path";
import { Effect, Exit } from "effect";
import { create as mutate } from "mutative";
import type { StoreApi } from "zustand";
Expand Down Expand Up @@ -202,9 +204,18 @@ export const createGeneralSlice = <
}),
);

hooksCommands
.runEventHooks({
beforeListeningStarted: { args: { session_id: targetSessionId } },
Promise.all([appDataDir(), getName().catch(() => "com.hyprnote.app")])
.then(([dataDirPath, appName]) => {
const sessionPath = `${dataDirPath}/hyprnote/sessions/${targetSessionId}`;
return hooksCommands.runEventHooks({
beforeListeningStarted: {
args: {
resource_dir: sessionPath,
app_hyprnote: appName,
app_meeting: null,
},
},
});
})
.catch((error) => {
console.error("[hooks] BeforeListeningStarted failed:", error);
Expand Down Expand Up @@ -264,9 +275,21 @@ export const createGeneralSlice = <
},
onSuccess: () => {
if (sessionId) {
hooksCommands
.runEventHooks({
afterListeningStopped: { args: { session_id: sessionId } },
Promise.all([
appDataDir(),
getName().catch(() => "com.hyprnote.app"),
])
.then(([dataDirPath, appName]) => {
const sessionPath = `${dataDirPath}/hyprnote/sessions/${sessionId}`;
return hooksCommands.runEventHooks({
afterListeningStopped: {
args: {
resource_dir: sessionPath,
app_hyprnote: appName,
app_meeting: null,
},
},
});
})
.catch((error) => {
console.error("[hooks] AfterListeningStopped failed:", error);
Expand Down
1 change: 1 addition & 0 deletions apps/web/content-collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ const hooks = defineCollection({
name: z.string(),
type_name: z.string(),
description: z.string(),
optional: z.boolean().default(false),
}),
)
.optional(),
Expand Down
13 changes: 10 additions & 3 deletions apps/web/content/docs/hooks/afterListeningStopped.mdx
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
---
name: afterListeningStopped
description: '123'
description: Arguments passed to hooks triggered after listening stops.
args:
- name: session_id
description: '345'
- name: --resource-dir
description: Path to the resource directory.
type_name: string
- name: --app-hyprnote
description: Application-specific Hyprnote data.
type_name: string
- name: --app-meeting
description: Optional meeting-specific data.
type_name: string
optional: true
---
13 changes: 10 additions & 3 deletions apps/web/content/docs/hooks/beforeListeningStarted.mdx
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
---
name: beforeListeningStarted
description: '123'
description: Arguments passed to hooks triggered before listening starts.
args:
- name: session_id
description: '345'
- name: --resource-dir
description: Path to the resource directory.
type_name: string
- name: --app-hyprnote
description: Application-specific Hyprnote data.
type_name: string
- name: --app-meeting
description: Optional meeting-specific data.
type_name: string
optional: true
---
69 changes: 45 additions & 24 deletions apps/web/src/components/hooks-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,63 @@ export function HooksList() {
}

return (
<div className="space-y-8 mt-8">
<div className="space-y-10 mt-6">
{hooks.map((hook) => (
<section key={hook.slug} className="border-t pt-6">
<h2 id={hook.name} className="scroll-mt-20">
{hook.name}
</h2>
{hook.description && (
<p className="mt-2 text-neutral-600">{hook.description}</p>
)}
<section
key={hook.slug}
className="border-t pt-2 first:border-t-0 first:pt-0"
>
<div className="space-y-1">
<h2
id={hook.name}
className="scroll-mt-24 text-xl font-bold tracking-tight text-neutral-900"
>
{hook.name}
</h2>
{hook.description && (
<p className="text-neutral-600 leading-relaxed">
{hook.description}
</p>
)}
</div>

{hook.args && hook.args.length > 0 && (
<div className="mt-4">
<h3 className="text-lg font-medium mb-2">Arguments</h3>
<div className="space-y-2">
<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">
<h3 className="mb-2 font-mono text-[10px] font-bold uppercase leading-none tracking-wider text-neutral-500/80">
Arguments
</h3>
<div className="space-y-3">
{hook.args.map((arg) => (
<div
key={arg.name}
className="border-l-2 border-neutral-200 pl-4"
className="group grid grid-cols-1 gap-1.5 sm:grid-cols-[180px_1fr] sm:gap-4"
>
<div className="font-mono text-sm">
<span className="font-semibold">{arg.name}</span>
<span className="text-neutral-500">
{" "}
: {arg.type_name}
</span>
<div className="flex flex-col items-start gap-1">
<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">
{arg.name}
</code>
<div className="flex items-center gap-1.5 px-0.5 font-mono text-[10px] text-neutral-500">
<span>{arg.type_name}</span>
{arg.optional && (
<>
<span className="h-0.5 w-0.5 rounded-full bg-neutral-300" />
<span className="italic text-neutral-400">
optional
</span>
</>
)}
</div>
</div>
<div className="text-sm leading-relaxed text-neutral-600">
{arg.description}
</div>
{arg.description && (
<p className="text-sm text-neutral-600 mt-1">
{arg.description}
</p>
)}
</div>
))}
</div>
</div>
)}
<div className="mt-4">

<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">
<MDXContent code={hook.mdx} />
</div>
</section>
Expand Down
43 changes: 33 additions & 10 deletions plugins/hooks/js/bindings.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,56 @@ async runEventHooks(event: HookEvent) : Promise<Result<null, string>> {
/** user-defined types **/

/**
* 123
* Arguments passed to hooks triggered after listening stops.
*/
export type AfterListeningStoppedArgs = {
/**
* 345
* Path to the resource directory.
*/
session_id: string }
resource_dir: string;
/**
* 123
* Application-specific Hyprnote data.
*/
app_hyprnote: string;
/**
* Optional meeting-specific data.
*/
app_meeting?: string | null }
/**
* Arguments passed to hooks triggered before listening starts.
*/
export type BeforeListeningStartedArgs = {
/**
* 345
* Path to the resource directory.
*/
resource_dir: string;
/**
* Application-specific Hyprnote data.
*/
app_hyprnote: string;
/**
* Optional meeting-specific data.
*/
app_meeting?: string | null }
/**
* Defines a single hook to be executed on an event.
*/
export type HookDefinition = {
/**
* Shell command to execute when the hook is triggered.
*/
session_id: string }
export type HookDefinition = { command: string }
command: string }
export type HookEvent = { afterListeningStopped: { args: AfterListeningStoppedArgs } } | { beforeListeningStarted: { args: BeforeListeningStartedArgs } }
/**
* 123
* Configuration for hook execution.
*/
export type HooksConfig = {
/**
* 345
* Configuration schema version.
*/
version: number;
/**
* 678
* Map of event names to their associated hook definitions.
*/
hooks?: Partial<{ [key in string]: HookDefinition[] }> }

Expand Down
8 changes: 5 additions & 3 deletions plugins/hooks/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::path::PathBuf;

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

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

Expand Down
Loading
Loading