generated from nhcarrigan/template
fix: assorted bug fixes for lists, sounds, interrupts, and permissions (#173)
## Summary - **Markdown lists**: Explicitly set `list-style-type: disc` / `decimal` in the Markdown renderer — Tauri's WebView strips browser defaults, leaving bullets and numbers invisible. - **Notification sounds**: Moved all per-task sounds (success, error, permission, task-start) from a global `characterState` subscription into the per-conversation `claude:state` event handler, so background tabs receive their sounds correctly and tab-switching never replays a sound that already fired. Closes #172 - **Draft text**: Persists `inputValue` per conversation tab so a half-typed prompt survives switching to another tab and back. - **Interrupt messages**: Replaced vague "Process interrupted" / "Disconnected" strings with source-specific descriptions (keyboard shortcut, stop button, unexpected crash) so it's clear what actually happened. - **Silent prompt loss**: When Claude Code exits whilst a prompt is in-flight, emits a visible error line telling the user their last prompt was not processed and to reconnect and retry. - **Double disconnect**: Added an `intentional_stop` flag to `WslBridge` so that `stop()` / `interrupt()` — which kill the process themselves — suppress the duplicate "Disconnected unexpectedly" message that `handle_stdout`'s EOF path was also emitting. - **Permission modal**: Fixed two cooperating reactivity bugs — `pendingPermissions` was mutated in-place (`.push()`), causing Svelte's derived-store chain to receive the same array reference and skip re-rendering; `PermissionModal.svelte` also used `$state()` (runes mode) where plain `let` is required for correct store-subscription reactivity. ## Test plan - [ ] Unordered and ordered lists render with visible bullets and numbers in the chat terminal - [ ] Completion sound plays once when a background tab finishes; switching back to that tab does not replay it - [ ] Sounds for error, permission request, and task-start also play for background tabs and do not replay on tab switch - [ ] Typing a prompt, switching tabs, and switching back restores the draft text - [ ] Pressing Ctrl+C shows "keyboard shortcut (Ctrl+C)"; clicking the stop button shows "via stop button" - [ ] If Claude exits mid-request, an error message appears prompting the user to resend - [ ] Clicking stop or pressing Ctrl+C produces exactly one disconnect message (not two) - [ ] When a tool requires permission, the permission modal appears and the user can approve or dismiss it ✨ This PR was created with help from Hikari~ 🌸 Reviewed-on: #173 Co-authored-by: Hikari <hikari@nhcarrigan.com> Co-committed-by: Hikari <hikari@nhcarrigan.com>
This commit was merged in pull request #173.
This commit is contained in:
@@ -1,52 +1,8 @@
|
||||
import { characterState } from "$lib/stores/character";
|
||||
import { notificationManager } from "./notificationManager";
|
||||
import type { CharacterState } from "$lib/types/states";
|
||||
import type { ConnectionStatus } from "$lib/types/messages";
|
||||
|
||||
// Track previous states to detect transitions
|
||||
let previousCharacterState: CharacterState | null = null;
|
||||
// Track previous connection status to detect transitions
|
||||
let previousConnectionStatus: ConnectionStatus | null = null;
|
||||
let taskStartTime: number | null = null;
|
||||
let hasNotifiedTaskStart = false;
|
||||
|
||||
export function handleCharacterStateChange(newState: CharacterState): void {
|
||||
// Detect state transitions
|
||||
if (previousCharacterState === newState) return;
|
||||
|
||||
// Task completion: any state -> success
|
||||
if (newState === "success" && previousCharacterState !== null) {
|
||||
const taskDuration = taskStartTime ? Date.now() - taskStartTime : 0;
|
||||
// Only notify for tasks that took more than 2 seconds
|
||||
if (taskDuration > 2000) {
|
||||
notificationManager.notifySuccess();
|
||||
}
|
||||
taskStartTime = null;
|
||||
}
|
||||
|
||||
// Error occurred
|
||||
if (newState === "error" && previousCharacterState !== "error") {
|
||||
notificationManager.notifyError();
|
||||
}
|
||||
|
||||
// Permission needed
|
||||
if (newState === "permission") {
|
||||
notificationManager.notifyPermission();
|
||||
}
|
||||
|
||||
// Starting long tasks - only notify once per response
|
||||
if (
|
||||
(newState === "coding" || newState === "searching") &&
|
||||
previousCharacterState !== "coding" &&
|
||||
previousCharacterState !== "searching" &&
|
||||
!hasNotifiedTaskStart
|
||||
) {
|
||||
taskStartTime = Date.now();
|
||||
hasNotifiedTaskStart = true;
|
||||
notificationManager.notifyTaskStart();
|
||||
}
|
||||
|
||||
previousCharacterState = newState;
|
||||
}
|
||||
|
||||
export function handleConnectionStatusChange(newStatus: ConnectionStatus): void {
|
||||
// Only notify on successful connection after being disconnected
|
||||
@@ -67,37 +23,13 @@ export function handleToolExecution(_toolName: string): void {
|
||||
// But we could add specific rules here if needed
|
||||
}
|
||||
|
||||
// Reset notification state for a new response
|
||||
export function handleNewUserMessage(): void {
|
||||
hasNotifiedTaskStart = false;
|
||||
}
|
||||
// No-op: sound tracking is now per-conversation in tauri.ts
|
||||
export function handleNewUserMessage(): void {}
|
||||
|
||||
// Store unsubscribe functions
|
||||
let unsubscribeCharacterState: (() => void) | null = null;
|
||||
// No-op: all per-conversation sounds are driven by tauri.ts event listeners
|
||||
export function initializeNotificationRules(): void {}
|
||||
|
||||
// Initialize listeners
|
||||
export function initializeNotificationRules(): void {
|
||||
// Clean up any existing subscriptions first
|
||||
cleanupNotificationRules();
|
||||
|
||||
// Subscribe to character state changes
|
||||
unsubscribeCharacterState = characterState.subscribe((state) => {
|
||||
handleCharacterStateChange(state);
|
||||
});
|
||||
|
||||
// We'll connect to connection status in the next step
|
||||
}
|
||||
|
||||
// Cleanup function to prevent duplicate listeners
|
||||
// Cleanup — reset connection tracking on teardown
|
||||
export function cleanupNotificationRules(): void {
|
||||
if (unsubscribeCharacterState) {
|
||||
unsubscribeCharacterState();
|
||||
unsubscribeCharacterState = null;
|
||||
}
|
||||
|
||||
// Reset state tracking
|
||||
previousCharacterState = null;
|
||||
previousConnectionStatus = null;
|
||||
taskStartTime = null;
|
||||
hasNotifiedTaskStart = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user