Surface shortcut-triggered start failures as a toast

The global shortcuts exist so a presenter never has to touch the app while on
camera — but Follow and Voice-Activated need a microphone, and one going
missing (unplugged, swapped, driver hiccup) between selecting a mode and
pressing the shortcut is entirely plausible. When that happens with the
editor closed to the tray, the failure was reported the only way this app
knows how: an inline status line in a window nobody is looking at. Pressing
the shortcut would look like it silently did nothing at all — exactly the
class of failure this session has spent most of its time hunting down in the
audio pipeline, just relocated to the UI layer.

A native toast now carries the same message when the failure came from a
shortcut, in addition to the inline text. Scoped to that path specifically,
not every warning: clicking Start with an empty script while looking straight
at the editor does not need a toast on top of the text already on screen.

Permission is requested once at startup rather than lazily on the first
warning — a Windows permission prompt appearing mid-presentation, raised by
the very problem it exists to report, would be a worse interruption than the
silence it replaces.

Fixes a bug caught while wiring this in: `onclick={toggleRun}` handed the
function straight to a native button, which calls it with the click's
MouseEvent as its first argument. Once toggleRun gained a real first
parameter, every ordinary click would have been read as shortcut-triggered.
Wrapped as `onclick={() => toggleRun()}` so only an intentional call passes
the flag.
This commit is contained in:
CRTkafa 2026-08-27 01:42:24 +07:00
parent 0137a7a725
commit 94a78501aa
10 changed files with 211 additions and 12 deletions

117
Cargo.lock generated
View file

@ -2334,6 +2334,20 @@ version = "0.4.34"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6" checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6"
[[package]]
name = "mac-notification-sys"
version = "0.6.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd604973958ddcc11b561193c0fb96ba146506ef2f231ef2e7c35fd2cbc9beca"
dependencies = [
"cc",
"log",
"objc2",
"objc2-foundation",
"time",
"uuid",
]
[[package]] [[package]]
name = "mach2" name = "mach2"
version = "0.6.0" version = "0.6.0"
@ -2476,6 +2490,20 @@ dependencies = [
"minimal-lexical", "minimal-lexical",
] ]
[[package]]
name = "notify-rust"
version = "4.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c5b4c1b4f2aa9f25f63a7a49d3dd0ed567b3670da15330a66b29434be899b891"
dependencies = [
"futures-lite",
"log",
"mac-notification-sys",
"serde",
"tauri-winrt-notification",
"zbus",
]
[[package]] [[package]]
name = "num-conv" name = "num-conv"
version = "0.2.2" version = "0.2.2"
@ -3024,6 +3052,15 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
[[package]]
name = "ppv-lite86"
version = "0.2.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
dependencies = [
"zerocopy",
]
[[package]] [[package]]
name = "precomputed-hash" name = "precomputed-hash"
version = "0.1.1" version = "0.1.1"
@ -3145,6 +3182,35 @@ version = "6.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
[[package]]
name = "rand"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9ef1d0d795eb7d84685bca4f72f3649f064e6641543d3a8c415898726a57b41"
dependencies = [
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c"
dependencies = [
"getrandom 0.3.4",
]
[[package]] [[package]]
name = "raw-window-handle" name = "raw-window-handle"
version = "0.6.2" version = "0.6.2"
@ -4192,6 +4258,25 @@ dependencies = [
"thiserror 2.0.20", "thiserror 2.0.20",
] ]
[[package]]
name = "tauri-plugin-notification"
version = "2.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "01fc2c5ff41105bd1f7242d8201fdf3efd70749b82fa013a17f2126357d194cc"
dependencies = [
"log",
"notify-rust",
"rand",
"serde",
"serde_json",
"serde_repr",
"tauri",
"tauri-plugin",
"thiserror 2.0.20",
"time",
"url",
]
[[package]] [[package]]
name = "tauri-plugin-opener" name = "tauri-plugin-opener"
version = "2.5.4" version = "2.5.4"
@ -4330,6 +4415,17 @@ dependencies = [
"toml 1.1.4+spec-1.1.0", "toml 1.1.4+spec-1.1.0",
] ]
[[package]]
name = "tauri-winrt-notification"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ed071c670382e85fc2f48ae706492d8c338f4f89bf72520d32f8abfe880aade"
dependencies = [
"thiserror 2.0.20",
"windows 0.61.3",
"windows-version",
]
[[package]] [[package]]
name = "tempfile" name = "tempfile"
version = "3.27.0" version = "3.27.0"
@ -4365,6 +4461,7 @@ dependencies = [
"tauri-build", "tauri-build",
"tauri-plugin-dialog", "tauri-plugin-dialog",
"tauri-plugin-global-shortcut", "tauri-plugin-global-shortcut",
"tauri-plugin-notification",
"tauri-plugin-opener", "tauri-plugin-opener",
"tauri-plugin-single-instance", "tauri-plugin-single-instance",
"ureq", "ureq",
@ -5930,6 +6027,26 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "zerocopy"
version = "0.8.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "556764e583adb45a9f8d413c2a147fa7e8d821e48e12b14fd560b607998b75eb"
dependencies = [
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.8.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2ab42fc20575779bd240faa45f94a74256f755c0fa9e89f0ede20d91d0cdfc1"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.119",
]
[[package]] [[package]]
name = "zerofrom" name = "zerofrom"
version = "0.1.8" version = "0.1.8"

View file

@ -92,6 +92,7 @@ src-tauri/ Windows shell
├── backdrop.rs Mica or blur behind the frameless window ├── backdrop.rs Mica or blur behind the frameless window
├── settings.rs Persisted preferences ├── settings.rs Persisted preferences
├── shortcuts.rs Global shortcuts for hands-free control ├── shortcuts.rs Global shortcuts for hands-free control
├── diagnostics.rs Crash and background-error logging
├── session.rs Live session state and the webview-facing DTOs ├── session.rs Live session state and the webview-facing DTOs
└── lib.rs Commands, events, tray icon └── lib.rs Commands, events, tray icon
@ -100,7 +101,7 @@ src/ Svelte UI
├── Chrome.svelte Title bar and resize grips for the frameless window ├── Chrome.svelte Title bar and resize grips for the frameless window
├── LiquidStart.svelte The voice-reactive transport control ├── LiquidStart.svelte The voice-reactive transport control
├── Overlay.svelte The prompter pill ├── Overlay.svelte The prompter pill
└── lib/ Typed command wrappers, spring integrator, file dialogs └── lib/ Typed command wrappers, spring integrator, file dialogs, toasts
``` ```
The engine deliberately knows nothing about Windows. That keeps it testable The engine deliberately knows nothing about Windows. That keeps it testable
@ -240,6 +241,9 @@ cargo test --workspace
- [x] `.textream` files — the same format the macOS app writes - [x] `.textream` files — the same format the macOS app writes
- [x] Global shortcuts — start, hold and mute without leaving the camera - [x] Global shortcuts — start, hold and mute without leaving the camera
- [x] First-run welcome, and error messages that say what to do - [x] First-run welcome, and error messages that say what to do
- [x] Closes to the tray instead of quitting; a second launch refocuses it
- [x] A toast when a shortcut-triggered start fails with the window hidden
- [x] A crash log, since a release build has no console to catch one
- [ ] Update check - [ ] Update check
### Deliberately out of scope ### Deliberately out of scope

12
package-lock.json generated
View file

@ -9,7 +9,8 @@
"version": "0.1.0", "version": "0.1.0",
"dependencies": { "dependencies": {
"@tauri-apps/api": "^2.11.1", "@tauri-apps/api": "^2.11.1",
"@tauri-apps/plugin-dialog": "^2.7.2" "@tauri-apps/plugin-dialog": "^2.7.2",
"@tauri-apps/plugin-notification": "^2.3.3"
}, },
"devDependencies": { "devDependencies": {
"@sveltejs/vite-plugin-svelte": "^7.3.0", "@sveltejs/vite-plugin-svelte": "^7.3.0",
@ -652,6 +653,15 @@
"@tauri-apps/api": "^2.11.0" "@tauri-apps/api": "^2.11.0"
} }
}, },
"node_modules/@tauri-apps/plugin-notification": {
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-notification/-/plugin-notification-2.3.3.tgz",
"integrity": "sha512-Zw+ZH18RJb41G4NrfHgIuofJiymusqN+q8fGUIIV7vyCH+5sSn5coqRv/MWB9qETsUs97vmU045q7OyseCV3Qg==",
"license": "MIT OR Apache-2.0",
"dependencies": {
"@tauri-apps/api": "^2.8.0"
}
},
"node_modules/@types/estree": { "node_modules/@types/estree": {
"version": "1.0.9", "version": "1.0.9",
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.9.tgz", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.9.tgz",

View file

@ -14,7 +14,8 @@
}, },
"dependencies": { "dependencies": {
"@tauri-apps/api": "^2.11.1", "@tauri-apps/api": "^2.11.1",
"@tauri-apps/plugin-dialog": "^2.7.2" "@tauri-apps/plugin-dialog": "^2.7.2",
"@tauri-apps/plugin-notification": "^2.3.3"
}, },
"devDependencies": { "devDependencies": {
"@sveltejs/vite-plugin-svelte": "^7.3.0", "@sveltejs/vite-plugin-svelte": "^7.3.0",

View file

@ -23,6 +23,7 @@ tauri-plugin-opener = "2"
tauri-plugin-global-shortcut = "2" tauri-plugin-global-shortcut = "2"
tauri-plugin-dialog = "2" tauri-plugin-dialog = "2"
tauri-plugin-single-instance = "2" tauri-plugin-single-instance = "2"
tauri-plugin-notification = "2"
serde = { version = "1", features = ["derive"] } serde = { version = "1", features = ["derive"] }
serde_json = "1" serde_json = "1"

View file

@ -24,6 +24,7 @@
"core:webview:default", "core:webview:default",
"opener:default", "opener:default",
"dialog:default", "dialog:default",
"dialog:allow-confirm" "dialog:allow-confirm",
"notification:default"
] ]
} }

View file

@ -451,6 +451,7 @@ pub fn run() {
.plugin(tauri_plugin_opener::init()) .plugin(tauri_plugin_opener::init())
.plugin(tauri_plugin_dialog::init()) .plugin(tauri_plugin_dialog::init())
.plugin(shortcuts::plugin()) .plugin(shortcuts::plugin())
.plugin(tauri_plugin_notification::init())
.manage(SessionState::new()) .manage(SessionState::new())
.manage(AudioState::default()) .manage(AudioState::default())
.manage(BackdropState(Mutex::new(Backdrop::None))) .manage(BackdropState(Mutex::new(Backdrop::None)))

View file

@ -361,7 +361,10 @@ mod tests {
}) })
.expect("a real download of the default model should succeed"); .expect("a real download of the default model should succeed");
assert!(progress_seen, "the progress callback should fire at least once"); assert!(
progress_seen,
"the progress callback should fire at least once"
);
assert!( assert!(
final_progress.received > 0, final_progress.received > 0,
"should report having received bytes" "should report having received bytes"

View file

@ -3,6 +3,7 @@
import { listen } from "@tauri-apps/api/event"; import { listen } from "@tauri-apps/api/event";
import * as api from "./lib/api"; import * as api from "./lib/api";
import * as files from "./lib/files"; import * as files from "./lib/files";
import * as notify from "./lib/notify";
import type { import type {
ColorPreset, ColorPreset,
DownloadProgress, DownloadProgress,
@ -156,6 +157,7 @@ Today we are shipping something I have wanted for a long time.
onMount(() => { onMount(() => {
void restore(); void restore();
void notify.init();
const unlisten = Promise.all([ const unlisten = Promise.all([
listen<DownloadProgress>(api.EVENT_DOWNLOAD, (event) => { listen<DownloadProgress>(api.EVENT_DOWNLOAD, (event) => {
const { received, total } = event.payload; const { received, total } = event.payload;
@ -173,7 +175,7 @@ Today we are shipping something I have wanted for a long time.
}); });
async function onShortcut(action: api.ShortcutAction) { async function onShortcut(action: api.ShortcutAction) {
if (action === "toggle") return toggleRun(); if (action === "toggle") return toggleRun(true);
// Hold and mute mean nothing when nothing is running. // Hold and mute mean nothing when nothing is running.
if (!running) return; if (!running) return;
if (action === "hold") return togglePause(); if (action === "hold") return togglePause();
@ -269,7 +271,7 @@ Today we are shipping something I have wanted for a long time.
} }
} }
async function toggleRun() { async function toggleRun(viaShortcut = false) {
// start() and stop() both open or release a microphone and a model, which // start() and stop() both open or release a microphone and a model, which
// take real time to settle. Without this guard, a second click before the // take real time to settle. Without this guard, a second click before the
// first finishes would race two attempts against the same device — the // first finishes would race two attempts against the same device — the
@ -279,15 +281,26 @@ Today we are shipping something I have wanted for a long time.
transitioning = true; transitioning = true;
try { try {
if (running) await stop(); if (running) await stop();
else await start(); else await start(viaShortcut);
} finally { } finally {
transitioning = false; transitioning = false;
} }
} }
async function start() { /**
* @param viaShortcut Also raises a toast on failure. Set when this run
* started from the global shortcut rather than a click, since that is the
* one path where the editor window — and the inline status message in it —
* can be sitting hidden in the tray while this fails.
*/
async function start(viaShortcut = false) {
const fail = (message: string) => {
say(message, "warn");
if (viaShortcut) notify.notifyWarning(message);
};
if (settings.script.trim() === "") { if (settings.script.trim() === "") {
say("Nothing to read — paste a script first.", "warn"); fail("Nothing to read — paste a script first.");
return; return;
} }
@ -304,7 +317,7 @@ Today we are shipping something I have wanted for a long time.
settings.mode === "wordTracking" ? settings.modelId : null, settings.mode === "wordTracking" ? settings.modelId : null,
); );
} catch (error) { } catch (error) {
say(String(error), "warn"); fail(String(error));
return; return;
} }
@ -709,7 +722,7 @@ Today we are shipping something I have wanted for a long time.
{level} {level}
listening={needsMicrophone && !muted} listening={needsMicrophone && !muted}
disabled={transitioning} disabled={transitioning}
onclick={toggleRun} onclick={() => toggleRun()}
/> />
<div class="middle"> <div class="middle">

48
src/lib/notify.ts Normal file
View file

@ -0,0 +1,48 @@
/**
* Native toast notifications, for the one blind spot the inline status
* message cannot cover.
*
* A global shortcut can start or stop a take while the editor window sits
* hidden in the tray — the entire point of the shortcuts is to do exactly
* that without touching the app. If starting fails in that moment (no
* microphone, a script cleared earlier), the inline status text in `App.svelte`
* updates in a window nobody is looking at, which is not a message at all.
* A toast reaches the presenter without stealing focus from whatever they are
* actually doing.
*/
import {
isPermissionGranted,
requestPermission,
sendNotification,
} from "@tauri-apps/plugin-notification";
let granted = false;
/**
* Resolves notification permission once, at startup.
*
* Not requested lazily on the first warning: a Windows permission prompt
* appearing mid-presentation, triggered by the very problem it exists to
* report, would be a worse interruption than the silence it replaces.
*/
export async function init(): Promise<void> {
try {
granted = await isPermissionGranted();
if (!granted) {
granted = (await requestPermission()) === "granted";
}
} catch {
granted = false;
}
}
/** Shows `message` as a toast, if permission was granted at startup. */
export function notifyWarning(message: string): void {
if (!granted) return;
try {
sendNotification({ title: "Textream", body: message });
} catch {
// A failed notification must never be the reason anything else breaks.
}
}