Skip to content

Commit c856414

Browse files
feat(hooks): await beforeListeningStarted hook before starting session (#2206)
Previously, the beforeListeningStarted hook was fire-and-forget, meaning the session would start immediately without waiting for the hook to complete. This change ensures the hook completes before startSessionEffect is called, allowing hooks to set up the default input device before listening starts. Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: yujonglee <[email protected]>
1 parent 4188842 commit c856414

File tree

1 file changed

+31
-26
lines changed

1 file changed

+31
-26
lines changed

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

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -202,34 +202,39 @@ export const createGeneralSlice = <
202202
}),
203203
);
204204

205-
Promise.all([
206-
appDataDir(),
207-
detectCommands
208-
.listMicUsingApplications()
209-
.then((r) =>
210-
r.status === "ok" ? r.data.map((app) => app.id) : null,
211-
),
212-
getIdentifier().catch(() => "com.hyprnote.stable"),
213-
])
214-
.then(([dataDirPath, micUsingApps, bundleId]) => {
215-
const sessionPath = `${dataDirPath}/hyprnote/sessions/${targetSessionId}`;
216-
const app_meeting = micUsingApps?.[0] ?? null;
217-
218-
hooksCommands
219-
.runEventHooks({
220-
beforeListeningStarted: {
221-
args: {
222-
resource_dir: sessionPath,
223-
app_hyprnote: bundleId,
224-
app_meeting,
225-
},
205+
const [dataDirPath, micUsingApps, bundleId] = yield* Effect.tryPromise({
206+
try: () =>
207+
Promise.all([
208+
appDataDir(),
209+
detectCommands
210+
.listMicUsingApplications()
211+
.then((r) =>
212+
r.status === "ok" ? r.data.map((app) => app.id) : null,
213+
),
214+
getIdentifier().catch(() => "com.hyprnote.stable"),
215+
]),
216+
catch: (error) => error,
217+
});
218+
219+
const sessionPath = `${dataDirPath}/hyprnote/sessions/${targetSessionId}`;
220+
const app_meeting = micUsingApps?.[0] ?? null;
221+
222+
yield* Effect.tryPromise({
223+
try: () =>
224+
hooksCommands.runEventHooks({
225+
beforeListeningStarted: {
226+
args: {
227+
resource_dir: sessionPath,
228+
app_hyprnote: bundleId,
229+
app_meeting,
226230
},
227-
})
228-
.catch(console.error);
229-
})
230-
.catch((error) => {
231+
},
232+
}),
233+
catch: (error) => {
231234
console.error("[hooks] BeforeListeningStarted failed:", error);
232-
});
235+
return error;
236+
},
237+
});
233238

234239
yield* startSessionEffect(params);
235240
set((state) =>

0 commit comments

Comments
 (0)