Skip to content

Notify user after failing to start recording #715

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { commands as analyticsCommands } from "@hypr/plugin-analytics";
import { commands as dbCommands } from "@hypr/plugin-db";
import { commands as listenerCommands } from "@hypr/plugin-listener";
import { commands as localSttCommands } from "@hypr/plugin-local-stt";
import { commands as notificationCommands } from "@hypr/plugin-notification";
import { commands as windowsCommands } from "@hypr/plugin-windows";
import { Button } from "@hypr/ui/components/ui/button";
import { Popover, PopoverContent, PopoverTrigger } from "@hypr/ui/components/ui/popover";
import { Spinner } from "@hypr/ui/components/ui/spinner";
Expand Down Expand Up @@ -65,15 +67,41 @@ export default function ListenButton({ sessionId }: { sessionId: string }) {
}
}, [ongoingSessionStatus]);

const handleStartSession = () => {
const handleStartSession = async () => {
if (ongoingSessionStatus === "inactive") {
ongoingSessionStore.start(sessionId);

analyticsCommands.event({
event: "onboarding_video_started",
distinct_id: userId,
session_id: sessionId,
});
try {
await ongoingSessionStore.start(sessionId);

analyticsCommands.event({
event: "onboarding_video_started",
distinct_id: userId,
session_id: sessionId,
});
} catch (error) {
console.error("Failed to start recording session:", error);

const isWindowVisible = await windowsCommands.windowIsVisible({ type: "main" });

if (isWindowVisible) {
toast({
id: "recording-failed",
title: "Recording Failed",
content: "Unable to start recording. Try it again.",
dismissible: true,
duration: 3000,
});
} else {
const permission = await notificationCommands.checkNotificationPermission();
if (permission === "Granted") {
await notificationCommands.sendNotification({
title: "Recording Failed",
message: "Unable to start recording. Try it again.",
url: null,
timeout: { secs: 3, nanos: 0 },
});
}
}
}
}
};

Expand Down
26 changes: 17 additions & 9 deletions apps/desktop/src/locales/en/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ msgstr "(Beta) Upcoming meeting notifications"
#. placeholder {0}: disabled ? "Wait..." : isHovered ? "Resume" : "Ended"
#. placeholder {0}: disabled ? "Wait..." : "Play again"
#: src/components/settings/components/calendar/cloud-calendar-integration-details.tsx:36
#: src/components/editor-area/note-header/listen-button.tsx:275
#: src/components/editor-area/note-header/listen-button.tsx:314
#: src/components/editor-area/note-header/listen-button.tsx:303
#: src/components/editor-area/note-header/listen-button.tsx:342
msgid "{0}"
msgstr "{0}"

Expand Down Expand Up @@ -439,14 +439,22 @@ msgstr "Create Note"
msgid "Current Plan"
msgstr "Current Plan"

#: src/components/editor-area/note-header/listen-button.tsx:221
#: src/components/settings/views/ai.tsx:432
#~ msgid "Custom Endpoint"
#~ msgstr "Custom Endpoint"

#: src/components/editor-area/note-header/listen-button.tsx:249
msgid "Custom instruction"
msgstr "Custom instruction"

#: src/components/settings/views/ai.tsx:264
msgid "Custom LLM Endpoint"
msgstr "Custom LLM Endpoint"

#: src/components/settings/views/ai.tsx:407
#~ msgid "Default (llama-3.2-3b-q4)"
#~ msgstr "Default (llama-3.2-3b-q4)"

#: src/components/settings/views/template.tsx:86
#: src/components/settings/views/team.tsx:165
#: src/components/left-sidebar/notes-list.tsx:323
Expand Down Expand Up @@ -776,15 +784,15 @@ msgstr "Optional for participant suggestions"
msgid "Owner"
msgstr "Owner"

#: src/components/editor-area/note-header/listen-button.tsx:398
#: src/components/editor-area/note-header/listen-button.tsx:426
msgid "Pause"
msgstr "Pause"

#: src/components/share-and-permission/participants-selector.tsx:35
msgid "people"
msgstr "people"

#: src/components/editor-area/note-header/listen-button.tsx:294
#: src/components/editor-area/note-header/listen-button.tsx:322
msgid "Play video"
msgstr "Play video"

Expand All @@ -796,7 +804,7 @@ msgstr "Pro"
msgid "Profile"
msgstr "Profile"

#: src/components/editor-area/note-header/listen-button.tsx:230
#: src/components/editor-area/note-header/listen-button.tsx:258
msgid "Provide descriptions about the meeting. Company specific terms, acronyms, jargons... any thing!"
msgstr "Provide descriptions about the meeting. Company specific terms, acronyms, jargons... any thing!"

Expand Down Expand Up @@ -825,7 +833,7 @@ msgstr "Required to transcribe other people's voice during meetings"
msgid "Required to transcribe your voice during meetings"
msgstr "Required to transcribe your voice during meetings"

#: src/components/editor-area/note-header/listen-button.tsx:103
#: src/components/editor-area/note-header/listen-button.tsx:131
msgid "Resume"
msgstr "Resume"

Expand Down Expand Up @@ -899,7 +907,7 @@ msgstr "Speech-to-Text Model"
msgid "Start Annual Plan"
msgstr "Start Annual Plan"

#: src/components/editor-area/note-header/listen-button.tsx:249
#: src/components/editor-area/note-header/listen-button.tsx:277
msgid "Start Meeting"
msgstr "Start Meeting"

Expand All @@ -911,7 +919,7 @@ msgstr "Start Monthly Plan"
#~ msgid "Start recording"
#~ msgstr "Start recording"

#: src/components/editor-area/note-header/listen-button.tsx:406
#: src/components/editor-area/note-header/listen-button.tsx:434
msgid "Stop"
msgstr "Stop"

Expand Down
26 changes: 17 additions & 9 deletions apps/desktop/src/locales/ko/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ msgstr ""
#. placeholder {0}: disabled ? "Wait..." : isHovered ? "Resume" : "Ended"
#. placeholder {0}: disabled ? "Wait..." : "Play again"
#: src/components/settings/components/calendar/cloud-calendar-integration-details.tsx:36
#: src/components/editor-area/note-header/listen-button.tsx:275
#: src/components/editor-area/note-header/listen-button.tsx:314
#: src/components/editor-area/note-header/listen-button.tsx:303
#: src/components/editor-area/note-header/listen-button.tsx:342
msgid "{0}"
msgstr ""

Expand Down Expand Up @@ -439,14 +439,22 @@ msgstr ""
msgid "Current Plan"
msgstr ""

#: src/components/editor-area/note-header/listen-button.tsx:221
#: src/components/settings/views/ai.tsx:432
#~ msgid "Custom Endpoint"
#~ msgstr ""

#: src/components/editor-area/note-header/listen-button.tsx:249
msgid "Custom instruction"
msgstr ""

#: src/components/settings/views/ai.tsx:264
msgid "Custom LLM Endpoint"
msgstr ""

#: src/components/settings/views/ai.tsx:407
#~ msgid "Default (llama-3.2-3b-q4)"
#~ msgstr ""

#: src/components/settings/views/template.tsx:86
#: src/components/settings/views/team.tsx:165
#: src/components/left-sidebar/notes-list.tsx:323
Expand Down Expand Up @@ -776,15 +784,15 @@ msgstr ""
msgid "Owner"
msgstr ""

#: src/components/editor-area/note-header/listen-button.tsx:398
#: src/components/editor-area/note-header/listen-button.tsx:426
msgid "Pause"
msgstr ""

#: src/components/share-and-permission/participants-selector.tsx:35
msgid "people"
msgstr ""

#: src/components/editor-area/note-header/listen-button.tsx:294
#: src/components/editor-area/note-header/listen-button.tsx:322
msgid "Play video"
msgstr ""

Expand All @@ -796,7 +804,7 @@ msgstr ""
msgid "Profile"
msgstr ""

#: src/components/editor-area/note-header/listen-button.tsx:230
#: src/components/editor-area/note-header/listen-button.tsx:258
msgid "Provide descriptions about the meeting. Company specific terms, acronyms, jargons... any thing!"
msgstr ""

Expand Down Expand Up @@ -825,7 +833,7 @@ msgstr ""
msgid "Required to transcribe your voice during meetings"
msgstr ""

#: src/components/editor-area/note-header/listen-button.tsx:103
#: src/components/editor-area/note-header/listen-button.tsx:131
msgid "Resume"
msgstr ""

Expand Down Expand Up @@ -899,7 +907,7 @@ msgstr ""
msgid "Start Annual Plan"
msgstr ""

#: src/components/editor-area/note-header/listen-button.tsx:249
#: src/components/editor-area/note-header/listen-button.tsx:277
msgid "Start Meeting"
msgstr ""

Expand All @@ -911,7 +919,7 @@ msgstr ""
#~ msgid "Start recording"
#~ msgstr ""

#: src/components/editor-area/note-header/listen-button.tsx:406
#: src/components/editor-area/note-header/listen-button.tsx:434
msgid "Stop"
msgstr ""

Expand Down
6 changes: 3 additions & 3 deletions apps/docs/data/i18n.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[
{
"language": "ko",
"total": 243,
"missing": 243
"total": 245,
"missing": 245
},
{
"language": "en (source)",
"total": 243,
"total": 245,
"missing": 0
}
]
21 changes: 19 additions & 2 deletions crates/notification2/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
pub use wezterm::ToastNotification as Notification;
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, specta::Type)]
pub struct Notification {
pub title: String,
pub message: String,
pub url: Option<String>,
pub timeout: Option<std::time::Duration>,
}

impl From<Notification> for wezterm::ToastNotification {
fn from(notif: Notification) -> Self {
wezterm::ToastNotification {
title: notif.title,
message: notif.message,
url: notif.url,
timeout: notif.timeout,
}
}
}

#[cfg(target_os = "macos")]
mod macos;
Expand All @@ -8,7 +25,7 @@ pub fn show(notif: Notification) {
return;
}

wezterm::show(notif);
wezterm::show(notif.into());
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, specta::Type)]
Expand Down
6 changes: 4 additions & 2 deletions packages/utils/src/stores/ongoing-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Actions = {
cancelEnhance: () => void;
setEnhanceController: (controller: AbortController | null) => void;
setStatus: (status: ListenerState) => void;
start: (sessionId: string) => void;
start: (sessionId: string) => Promise<void>;
stop: () => void;
pause: () => void;
resume: () => void;
Expand Down Expand Up @@ -90,12 +90,14 @@ export const createOngoingSessionStore = (sessionsStore: ReturnType<typeof creat
);
};

listenerCommands.startSession(sessionId).then(() => {
// Note: Return the promise so errors can be caught by callers
return listenerCommands.startSession(sessionId).then(() => {
set({ channel, status: "running_active", loading: false });
listenerCommands.subscribe(channel);
}).catch((error) => {
console.error(error);
set(initialState);
throw new Error(error?.message ?? "Failed to start recording session");
});
},
stop: () => {
Expand Down
5 changes: 5 additions & 0 deletions plugins/notification/js/bindings.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@


export const commands = {
async sendNotification(notif: Notification) : Promise<null> {
return await TAURI_INVOKE("plugin:notification|send_notification", { notif });
},
async getEventNotification() : Promise<boolean> {
return await TAURI_INVOKE("plugin:notification|get_event_notification");
},
Expand Down Expand Up @@ -52,6 +55,8 @@ async stopEventNotification() : Promise<null> {

/** user-defined types **/

export type Duration = { secs: number; nanos: number }
export type Notification = { title: string; message: string; url: string | null; timeout: Duration | null }
export type NotificationPermission = "Granted" | "NotGrantedAndShouldRequest" | "NotGrantedAndShouldAskManual"

/** tauri-specta globals **/
Expand Down
9 changes: 9 additions & 0 deletions plugins/notification/src/commands.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
use crate::NotificationPluginExt;

#[tauri::command]
#[specta::specta]
pub(crate) async fn send_notification<R: tauri::Runtime>(
app: tauri::AppHandle<R>,
notif: hypr_notification2::Notification,
) -> Result<(), String> {
app.send_notification(notif).map_err(|e| e.to_string())
}

#[tauri::command]
#[specta::specta]
pub(crate) async fn get_event_notification<R: tauri::Runtime>(
Expand Down
7 changes: 7 additions & 0 deletions plugins/notification/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use tauri_plugin_store2::StorePluginExt;
pub trait NotificationPluginExt<R: tauri::Runtime> {
fn notification_store(&self) -> tauri_plugin_store2::ScopedStore<R, crate::StoreKey>;

fn send_notification(&self, notif: hypr_notification2::Notification) -> Result<(), Error>;

fn get_event_notification(&self) -> Result<bool, Error>;
fn set_event_notification(&self, enabled: bool) -> Result<(), Error>;

Expand All @@ -31,6 +33,11 @@ impl<R: tauri::Runtime, T: tauri::Manager<R>> NotificationPluginExt<R> for T {
self.scoped_store(crate::PLUGIN_NAME).unwrap()
}

fn send_notification(&self, notif: hypr_notification2::Notification) -> Result<(), Error> {
hypr_notification2::show(notif);
Ok(())
}

#[tracing::instrument(skip(self))]
fn get_event_notification(&self) -> Result<bool, Error> {
let store = self.notification_store();
Expand Down
2 changes: 2 additions & 0 deletions plugins/notification/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ fn make_specta_builder<R: tauri::Runtime>() -> tauri_specta::Builder<R> {
tauri_specta::Builder::<R>::new()
.plugin_name(PLUGIN_NAME)
.commands(tauri_specta::collect_commands![
commands::send_notification::<tauri::Wry>,
commands::get_event_notification::<tauri::Wry>,
commands::set_event_notification::<tauri::Wry>,
commands::get_detect_notification::<tauri::Wry>,
Expand Down Expand Up @@ -87,6 +88,7 @@ mod test {

fn create_app<R: tauri::Runtime>(builder: tauri::Builder<R>) -> tauri::App<R> {
builder
.plugin(tauri_plugin_store::Builder::default().build())
.plugin(init())
.plugin(tauri_plugin_store::Builder::default().build())
.build(tauri::test::mock_context(tauri::test::noop_assets()))
Expand Down
Loading