Skip to content

Commit c9f50d0

Browse files
authored
Migrate from channel to event for listener (#765)
1 parent f04337a commit c9f50d0

File tree

20 files changed

+107
-505
lines changed

20 files changed

+107
-505
lines changed

Cargo.lock

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

apps/desktop/src-tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "desktop"
3-
version = "0.0.31"
3+
version = "0.0.32"
44
authors = ["you"]
55
edition = "2021"
66
description = "Hyprnote Desktop App"

apps/desktop/src-tauri/tauri.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://schema.tauri.app/config/2",
3-
"version": "0.0.31",
3+
"version": "0.0.32",
44
"productName": "Hyprnote Dev",
55
"mainBinaryName": "Hyprnote Dev",
66
"identifier": "com.hyprnote.dev",

apps/desktop/src/routes/video.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ function Component() {
2929
useEffect(() => {
3030
let unlisten: () => void;
3131

32-
listenerEvents.statusEvent.listen(({ payload }) => {
33-
if (payload === "running_paused") {
32+
listenerEvents.sessionEvent.listen(({ payload }) => {
33+
if (payload.type === "running_paused") {
3434
player.current?.pause();
3535
}
3636

37-
if (payload === "running_active") {
37+
if (payload.type === "running_active") {
3838
player.current?.play();
3939
}
4040

41-
if (payload === "inactive") {
41+
if (payload.type === "inactive") {
4242
handleEnded();
4343
}
4444
}).then((u) => {

extensions/summary/src/widgets/bullet/2x2.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { useQuery } from "@tanstack/react-query";
2-
import { Channel } from "@tauri-apps/api/core";
32
import { generateObject } from "ai";
43
import { motion } from "motion/react";
54
import { useEffect, useState } from "react";
65

76
import { commands as dbCommands } from "@hypr/plugin-db";
8-
import { commands as listenerCommands, type SessionEvent } from "@hypr/plugin-listener";
7+
import { events as listenerEvents } from "@hypr/plugin-listener";
98
import { commands as templateCommands } from "@hypr/plugin-template";
109
import { Button } from "@hypr/ui/components/ui/button";
1110
import { WidgetHeader, type WidgetTwoByTwo, WidgetTwoByTwoWrapper } from "@hypr/ui/components/ui/widgets";
@@ -25,20 +24,23 @@ const Widget: WidgetTwoByTwo = ({ queryClient }) => {
2524
const [progress, setProgress] = useState(0);
2625

2726
useEffect(() => {
28-
const channel = new Channel<SessionEvent>();
29-
listenerCommands.subscribe(channel);
27+
let unlisten: (() => void) | null = null;
3028

31-
channel.onmessage = (e) => {
32-
if (e.type === "started") {
33-
setIsLive(true);
34-
}
35-
if (e.type === "stopped") {
29+
listenerEvents.sessionEvent.listen(({ payload }) => {
30+
if (payload.type === "inactive" || payload.type === "running_paused") {
3631
setIsLive(false);
3732
}
38-
};
33+
if (payload.type === "running_active") {
34+
setIsLive(true);
35+
}
36+
}).then((fn) => {
37+
unlisten = fn;
38+
});
3939

4040
return () => {
41-
listenerCommands.unsubscribe(channel);
41+
if (unlisten) {
42+
unlisten();
43+
}
4244
};
4345
}, []);
4446

extensions/transcript/src/hooks/useTranscript.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { Channel } from "@tauri-apps/api/core";
21
import { useEffect, useMemo, useState } from "react";
32

43
import { commands as dbCommands } from "@hypr/plugin-db";
5-
import { commands as listenerCommands, type SessionEvent, type TimelineView } from "@hypr/plugin-listener";
4+
import { events as listenerEvents, type TimelineView } from "@hypr/plugin-listener";
65
import { useOngoingSession, useSession } from "@hypr/utils/contexts";
76

87
export function useTranscript(sessionId: string | null) {
@@ -53,17 +52,20 @@ export function useTranscript(sessionId: string | null) {
5352
return;
5453
}
5554

56-
const channel = new Channel<SessionEvent>();
57-
listenerCommands.subscribe(channel);
55+
let unlisten: (() => void) | null = null;
5856

59-
channel.onmessage = (e) => {
60-
if (e.type === "timelineView") {
61-
setTimeline(e.timeline);
57+
listenerEvents.sessionEvent.listen(({ payload }) => {
58+
if (payload.type === "timelineView") {
59+
setTimeline(payload.view);
6260
}
63-
};
61+
}).then((fn) => {
62+
unlisten = fn;
63+
});
6464

6565
return () => {
66-
listenerCommands.unsubscribe(channel);
66+
if (unlisten) {
67+
unlisten();
68+
}
6769
};
6870
}, [ongoingSessionState.status, ongoingSessionState.sessionId, sessionId]);
6971

Lines changed: 3 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
2-
import { Channel, isTauri } from "@tauri-apps/api/core";
2+
import { isTauri } from "@tauri-apps/api/core";
33
import { clearMocks, mockIPC } from "@tauri-apps/api/mocks";
44
import { useEffect } from "react";
55

66
import { Session } from "@hypr/plugin-db";
7-
import { type SessionEvent, TimelineView } from "@hypr/plugin-listener";
7+
import { type TimelineView } from "@hypr/plugin-listener";
88
import { OngoingSessionProvider } from "@hypr/utils/contexts";
99
import { SessionsProvider } from "@hypr/utils/contexts";
1010
import { createOngoingSessionStore, createSessionsStore, createSessionStore } from "@hypr/utils/stores";
11-
import { sleep } from "../../utils";
1211

1312
const queryClient = new QueryClient();
1413

@@ -63,15 +62,11 @@ export default function MockProvider({
6362
}
6463

6564
const mockTranscriptIPC = (): (() => void) | undefined => {
66-
mockIPC((cmd, args) => {
65+
mockIPC((cmd, _args) => {
6766
if (cmd == "plugin:listener|get_timeline_view") {
6867
return handleGetTimeline();
6968
}
7069

71-
if (cmd == "plugin:listener|subscribe") {
72-
return handleListenerSubscribe((args as any).channel as Channel<SessionEvent>);
73-
}
74-
7570
console.warn(`'${cmd}' is not mocked`);
7671
});
7772

@@ -83,143 +78,3 @@ const handleGetTimeline = () => {
8378
items: [],
8479
} satisfies TimelineView;
8580
};
86-
87-
const handleListenerSubscribe = (channel: Channel<SessionEvent>) => {
88-
(async () => {
89-
let currentTime = 0;
90-
91-
// John starts the meeting
92-
await sleep(500);
93-
currentTime += 0.5;
94-
channel.onmessage({
95-
type: "timelineView",
96-
timeline: {
97-
items: [
98-
{
99-
start: currentTime,
100-
end: currentTime + 3,
101-
speaker: 1,
102-
text: "Hey team, thanks for joining. Today we'll discuss the new transcription feature requirements.",
103-
confidence: 0.9,
104-
},
105-
],
106-
},
107-
});
108-
109-
// Sarah responds
110-
await sleep(3500);
111-
currentTime += 3.5;
112-
channel.onmessage({
113-
type: "timelineView",
114-
timeline: {
115-
items: [
116-
{
117-
start: currentTime,
118-
end: currentTime + 5,
119-
speaker: 2,
120-
text:
121-
"I've been working on some mockups based on user feedback. The main request is for real-time updates and clear speaker identification.",
122-
confidence: 0.9,
123-
},
124-
],
125-
},
126-
});
127-
128-
// Mike adds technical context
129-
await sleep(5500);
130-
currentTime += 5.5;
131-
channel.onmessage({
132-
type: "timelineView",
133-
timeline: {
134-
items: [
135-
{
136-
start: currentTime,
137-
end: currentTime + 4,
138-
speaker: 3,
139-
text:
140-
"That aligns with our backend capabilities. We can stream the transcription with about 500ms latency.",
141-
confidence: 0.9,
142-
},
143-
],
144-
},
145-
});
146-
147-
// John asks about timeline
148-
await sleep(4500);
149-
currentTime += 4.5;
150-
channel.onmessage({
151-
type: "timelineView",
152-
timeline: {
153-
items: [
154-
{
155-
start: currentTime,
156-
end: currentTime + 2,
157-
speaker: 1,
158-
text: "What's our timeline for implementing this?",
159-
confidence: 0.9,
160-
},
161-
],
162-
},
163-
});
164-
165-
// Sarah provides estimate
166-
await sleep(3000);
167-
currentTime += 3;
168-
channel.onmessage({
169-
type: "timelineView",
170-
timeline: {
171-
items: [
172-
{
173-
start: currentTime,
174-
end: currentTime + 4,
175-
speaker: 2,
176-
text: "The UI work should take about two weeks. We already have most of the components ready.",
177-
confidence: 0.9,
178-
},
179-
],
180-
},
181-
});
182-
183-
// Mike confirms backend timeline
184-
await sleep(4500);
185-
currentTime += 4.5;
186-
channel.onmessage({
187-
type: "timelineView",
188-
timeline: {
189-
items: [
190-
{
191-
start: currentTime,
192-
end: currentTime + 3,
193-
speaker: 3,
194-
text: "Backend integration can be done in parallel. We should be ready for testing in two weeks.",
195-
confidence: 0.9,
196-
},
197-
],
198-
},
199-
});
200-
201-
// Meeting wrap-up
202-
await sleep(3500);
203-
currentTime += 3.5;
204-
channel.onmessage({
205-
type: "timelineView",
206-
timeline: {
207-
items: [
208-
{
209-
start: currentTime,
210-
end: currentTime + 2,
211-
speaker: 1,
212-
text: "Perfect, let's reconvene next week for a progress check. Thanks everyone!",
213-
confidence: 0.9,
214-
},
215-
],
216-
},
217-
});
218-
219-
// Send stopped event after a brief pause
220-
await sleep(2500);
221-
channel.onmessage({
222-
type: "stopped",
223-
});
224-
})();
225-
};

0 commit comments

Comments
 (0)