Skip to content

feat (desktop): toggle for notifications#1045

Merged
AviPeltz merged 2 commits intomainfrom
AviPeltz/toggle-notifications
Jan 29, 2026
Merged

feat (desktop): toggle for notifications#1045
AviPeltz merged 2 commits intomainfrom
AviPeltz/toggle-notifications

Conversation

@AviPeltz
Copy link
Copy Markdown
Collaborator

@AviPeltz AviPeltz commented Jan 29, 2026

Description

Related Issues

Type of Change

  • Bug fix
  • New feature
  • Documentation
  • Refactor
  • Other (please describe):

Testing

Screenshots (if applicable)

Additional Notes

Summary by CodeRabbit

  • New Features
    • Added a notification sounds toggle in Settings to mute/unmute notification audio.
  • UI Changes
    • Ringtone selection and tips are hidden when notification sounds are muted.
    • Removed the explicit "Silent" ringtone option; muting is managed by the new toggle.
  • Behavior
    • Playback now respects the muted setting and will not play sounds when muted.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 29, 2026

📝 Walkthrough

Walkthrough

Adds notification-sounds muting: DB migration and schema column, TRPC procedures to get/set muted state, settings UI toggle with optimistic updates, removal of the "none" ringtone entry, and playback gating so notifications skip sound when muted.

Changes

Cohort / File(s) Summary
Database schema & metadata
packages/local-db/drizzle/0015_add_notification_sounds_muted.sql, packages/local-db/drizzle/meta/0015_snapshot.json, packages/local-db/drizzle/meta/_journal.json, packages/local-db/src/schema/schema.ts
Add notification_sounds_muted column to settings (stored as integer with boolean mode); include migration, snapshot, and journal entry.
TRPC settings router
apps/desktop/src/lib/trpc/routers/settings/index.ts
Add getNotificationSoundsMuted query and setNotificationSoundsMuted mutation to read and upsert the muted flag.
Notification playback logic
apps/desktop/src/main/lib/notification-sound.ts
Introduce private areNotificationSoundsMuted() helper and short-circuit playNotificationSound() when muted.
Ringtones UI
apps/desktop/src/renderer/routes/_authenticated/settings/ringtones/components/RingtonesSettings/RingtonesSettings.tsx
Add Label/Switch UI for notification sounds mute, wire TRPC query/mutation with optimistic update and rollback, conditionally hide ringtone grid/tips when muted, and remove silent-specific rendering.
Shared ringtone data
apps/desktop/src/shared/ringtones.ts
Remove the id: "none" (Silent) entry from exported RINGTONES and update JSDoc for lookup behavior.
Package manifest
package.json
Manifest file modified (lines changed reported in summary).

Sequence Diagram

sequenceDiagram
    participant User
    participant UI as Settings UI
    participant TRPC as TRPC Server
    participant DB as LocalDB
    participant Notifier as Notification System

    User->>UI: toggle mute switch
    UI->>UI: optimistic UI update
    UI->>TRPC: setNotificationSoundsMuted({ muted })
    TRPC->>DB: upsert settings.notification_sounds_muted
    DB-->>TRPC: confirmation
    TRPC-->>UI: { success: true }
    Note over UI: ringtone grid/tips hidden when muted

    Notifier->>DB: areNotificationSoundsMuted()
    DB-->>Notifier: boolean
    alt muted
        Notifier->>Notifier: skip playback
    else not muted
        Notifier->>Notifier: play sound file
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰🔔 I flipped the switch, the world went hush,
A tiny toggle, a gentle hush!
DB remembers, UI nods yes,
No more beeps to break my rest.
Hop, click, quiet—what bliss!

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is incomplete; it contains only template placeholders with no actual content, implementation details, testing steps, or links to related issues. Fill in all required sections: provide a clear description of the notification toggle feature, link any related issues, add testing steps, and include relevant context about the changes.
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title describes adding a toggle for notifications, which aligns with the core changes: introducing notification sounds muting functionality across settings router, UI, and database.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@AviPeltz AviPeltz marked this pull request as ready for review January 29, 2026 01:22
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
apps/desktop/src/renderer/routes/_authenticated/settings/ringtones/components/RingtonesSettings/RingtonesSettings.tsx (2)

168-170: Don't silently swallow cleanup errors.

The catch(() => {}) pattern violates the coding guideline to never silently swallow errors. Even in cleanup scenarios, errors should be logged at minimum for debugging purposes.

Proposed fix
 		electronTrpcClient.ringtone.stop.mutate().catch(() => {
-			// Ignore errors during cleanup
+			(err) => {
+				console.error("[ringtone/cleanup] Failed to stop preview on unmount:", err);
+			}
 		});

Actually, the fix should be:

-		electronTrpcClient.ringtone.stop.mutate().catch(() => {
-			// Ignore errors during cleanup
-		});
+		electronTrpcClient.ringtone.stop.mutate().catch((err) => {
+			console.error("[ringtone/cleanup] Failed to stop preview on unmount:", err);
+		});

266-283: Stop ringtone preview when muting is toggled.

When a user starts previewing a ringtone and then toggles the mute switch, the sound continues playing but the UI disappears. Add a useEffect to stop the preview and clear playingId when isMuted changes:

useEffect(() => {
  if (isMuted && playingId) {
    electronTrpcClient.ringtone.stop.mutate().catch(() => {
      console.error("Failed to stop ringtone on mute");
    });
    setPlayingId(null);
  }
}, [isMuted, playingId]);
🤖 Fix all issues with AI agents
In
`@apps/desktop/src/renderer/routes/_authenticated/settings/ringtones/components/RingtonesSettings/RingtonesSettings.tsx`:
- Around line 146-152: The onError handler for the mutation currently swallows
errors; update the onError in RingtonesSettings (the function using onError:
(_err, _vars, context) => { ... }) to log the error and context before or after
restoring state with
utils.settings.getNotificationSoundsMuted.setData(undefined, context.previous);
include the _err and context (or context.previous) in the log call (e.g.,
console.error or the app logger) so the failure is recorded with relevant
context.
🧹 Nitpick comments (2)
apps/desktop/src/main/lib/notification-sound.ts (1)

14-21: Add logging for errors instead of silently swallowing.

The catch block silently returns false without logging the error. This makes debugging harder when database access fails unexpectedly. As per coding guidelines, errors should at minimum be logged with context.

♻️ Suggested fix
 function areNotificationSoundsMuted(): boolean {
 	try {
 		const settingsRow = localDb.select().from(settings).get();
 		return settingsRow?.notificationSoundsMuted ?? false;
-	} catch {
+	} catch (error) {
+		console.warn("[notification-sound/areNotificationSoundsMuted] Failed to read muted state:", error);
 		return false;
 	}
 }
apps/desktop/src/renderer/routes/_authenticated/settings/ringtones/components/RingtonesSettings/RingtonesSettings.tsx (1)

188-221: Console logging missing domain prefix and magic numbers.

Per coding guidelines:

  1. Console logging should use [domain/operation] message pattern
  2. Magic numbers should be extracted to named constants
Proposed fix
+const PLAYBACK_END_BUFFER_SECONDS = 0.5;
+const MS_PER_SECOND = 1000;
+
 // ... in handleTogglePlay:
 
 			} catch (error) {
-				console.error("Failed to stop ringtone:", error);
+				console.error("[ringtone/preview] Failed to stop ringtone:", error);
 			}
 
 // ... and:
 
 			} catch (error) {
-				console.error("Failed to play ringtone:", error);
+				console.error("[ringtone/preview] Failed to play ringtone:", error);
 				setPlayingId(null);
 			}
 
 			// Auto-reset after the ringtone's actual duration (with buffer)
-			const durationMs = ((ringtone.duration ?? 5) + 0.5) * 1000;
+			const durationMs = ((ringtone.duration ?? 5) + PLAYBACK_END_BUFFER_SECONDS) * MS_PER_SECOND;

Comment on lines +146 to +152
onError: (_err, _vars, context) => {
if (context?.previous !== undefined) {
utils.settings.getNotificationSoundsMuted.setData(
undefined,
context.previous,
);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Log the error in onError handler.

The error is being silently handled without logging. Per coding guidelines, errors should at minimum be logged with context.

Proposed fix
-		onError: (_err, _vars, context) => {
+		onError: (err, _vars, context) => {
+			console.error("[settings/notification-sounds] Failed to toggle muted state:", err);
 			if (context?.previous !== undefined) {
 				utils.settings.getNotificationSoundsMuted.setData(
 					undefined,
 					context.previous,
 				);
 			}
 		},
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
onError: (_err, _vars, context) => {
if (context?.previous !== undefined) {
utils.settings.getNotificationSoundsMuted.setData(
undefined,
context.previous,
);
}
onError: (err, _vars, context) => {
console.error("[settings/notification-sounds] Failed to toggle muted state:", err);
if (context?.previous !== undefined) {
utils.settings.getNotificationSoundsMuted.setData(
undefined,
context.previous,
);
}
🤖 Prompt for AI Agents
In
`@apps/desktop/src/renderer/routes/_authenticated/settings/ringtones/components/RingtonesSettings/RingtonesSettings.tsx`
around lines 146 - 152, The onError handler for the mutation currently swallows
errors; update the onError in RingtonesSettings (the function using onError:
(_err, _vars, context) => { ... }) to log the error and context before or after
restoring state with
utils.settings.getNotificationSoundsMuted.setData(undefined, context.previous);
include the _err and context (or context.previous) in the log call (e.g.,
console.error or the app logger) so the failure is recorded with relevant
context.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 29, 2026

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

  • ✅ Neon database branch
  • ✅ Electric Fly.io app

Thank you for your contribution! 🎉

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@apps/desktop/src/main/lib/notification-sound.ts`:
- Around line 14-21: The catch block in areNotificationSoundsMuted currently
swallows errors; update it to log the caught error (include the error object and
context indicating the function and that a default false will be returned)
before returning false—use the project's logger if available (e.g.,
appLogger.error or similar), otherwise console.error; reference localDb and
settings in the log message so the failure source is clear.

Comment on lines +14 to +21
function areNotificationSoundsMuted(): boolean {
try {
const settingsRow = localDb.select().from(settings).get();
return settingsRow?.notificationSoundsMuted ?? false;
} catch {
return false;
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Log the error before returning the default value.

The catch block silently swallows errors. Per coding guidelines, errors should at minimum be logged with context, even when providing a safe fallback.

Proposed fix
 function areNotificationSoundsMuted(): boolean {
 	try {
 		const settingsRow = localDb.select().from(settings).get();
 		return settingsRow?.notificationSoundsMuted ?? false;
-	} catch {
+	} catch (error) {
+		console.error("[notification-sound/areNotificationSoundsMuted] Failed to read muted state:", error);
 		return false;
 	}
 }
🤖 Prompt for AI Agents
In `@apps/desktop/src/main/lib/notification-sound.ts` around lines 14 - 21, The
catch block in areNotificationSoundsMuted currently swallows errors; update it
to log the caught error (include the error object and context indicating the
function and that a default false will be returned) before returning false—use
the project's logger if available (e.g., appLogger.error or similar), otherwise
console.error; reference localDb and settings in the log message so the failure
source is clear.

@AviPeltz AviPeltz merged commit f6cd372 into main Jan 29, 2026
13 checks passed
@Kitenite Kitenite deleted the AviPeltz/toggle-notifications branch January 29, 2026 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant