-
Notifications
You must be signed in to change notification settings - Fork 823
fix: prevent random doorbell notification sound #3260
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
base: develop
Are you sure you want to change the base?
Changes from all commits
23523fb
aea667f
3830045
79f7886
a47a12e
b29d28e
89f17c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,333 @@ | ||
| # Notification Sound Bug Fix | ||
|
|
||
| ## 🐛 Bug Description | ||
|
|
||
| **Issue**: Random doorbell notification sound plays even when: | ||
| - Notification volume is set to 0 | ||
| - Custom silent sound is configured | ||
| - User has explicitly disabled notification sounds | ||
|
|
||
| **Root Cause**: The `silent` flag in notification options was not being properly enforced. The code used `silent ?? undefined` which meant: | ||
| - If `silent` was `false`, it became `undefined` | ||
| - Electron would then use the system default (play sound) | ||
| - This caused unwanted notification sounds | ||
|
|
||
| ## ✅ Fix Applied | ||
|
|
||
| ### File Modified | ||
| `src/notifications/main.ts` - Line 62 | ||
|
|
||
| ### Change Made | ||
|
|
||
| **Before**: | ||
| ```typescript | ||
| const notification = new Notification({ | ||
| title, | ||
| subtitle, | ||
| body: body ?? '', | ||
| icon: await resolveIcon(icon), | ||
| silent: silent ?? undefined, // ❌ Bug: false becomes undefined | ||
| hasReply: canReply, | ||
| actions: actions?.map((action) => ({ | ||
| type: 'button', | ||
| text: action.title, | ||
| })), | ||
| }); | ||
| ``` | ||
|
|
||
| **After**: | ||
| ```typescript | ||
| const notification = new Notification({ | ||
| title, | ||
| subtitle, | ||
| body: body ?? '', | ||
| icon: await resolveIcon(icon), | ||
| silent: silent !== false, // ✅ Fix: Silent unless explicitly false | ||
| hasReply: canReply, | ||
| actions: actions?.map((action) => ({ | ||
| type: 'button', | ||
| text: action.title, | ||
| })), | ||
| }); | ||
| ``` | ||
|
|
||
| ### Why This Works | ||
|
|
||
| | Input | Result | Behavior | | ||
| |----------|--------------|--------------| | ||
| | `silent: true` | `true` | ✅ Silent (no sound) | | ||
| | `silent: false` | `false` | ✅ Plays sound | | ||
| | `silent: undefined` | `true` | ✅ Silent (no sound) | | ||
| | Not specified | `true` | ✅ Silent (no sound) | | ||
|
|
||
| **Key Change**: Changed from `silent ?? undefined` to `silent !== false` | ||
|
|
||
| This ensures: | ||
| - Sound only plays when `silent` is explicitly `false` | ||
| - When `silent` is `true` or `undefined`, notification is silent | ||
| - Fixes the doorbell sound bug where unwanted sounds played | ||
|
|
||
| ## 🔍 Technical Details | ||
|
|
||
| ### Notification Flow | ||
|
|
||
| 1. **Rocket.Chat Web Client** creates notification with options | ||
| 2. **injected.ts** intercepts and wraps notification | ||
| 3. **preload.ts** sends notification request to main process | ||
| 4. **main.ts** creates native Electron notification | ||
| 5. **Electron** shows notification (with or without sound) | ||
|
|
||
| ### Code Path | ||
|
|
||
| ``` | ||
| Rocket.Chat Web → injected.ts (RocketChatDesktopNotification) | ||
| ↓ | ||
| preload.ts (createNotification) | ||
| ↓ | ||
| main.ts (createNotification) ← FIX APPLIED HERE | ||
| ↓ | ||
| Electron Notification API | ||
| ``` | ||
|
|
||
| ### Silent Flag Handling | ||
|
|
||
| **In injected.ts** (line 365): | ||
| ```typescript | ||
| silent = false; // Default value | ||
| ``` | ||
|
|
||
| **In preload.ts**: | ||
| ```typescript | ||
| const id = await request({ | ||
| type: NOTIFICATIONS_CREATE_REQUESTED, | ||
| payload: { | ||
| title, | ||
| ...options, // Includes silent flag | ||
| }, | ||
| }); | ||
| ``` | ||
|
|
||
| **In main.ts** (FIXED): | ||
| ```typescript | ||
| silent: silent !== false, // Silent unless explicitly false | ||
| ``` | ||
|
|
||
| ## 🧪 Testing Instructions | ||
|
|
||
| ### Prerequisites | ||
| - Rocket.Chat server with notifications enabled | ||
| - Desktop app built with the fix | ||
|
|
||
| ### Test Scenarios | ||
|
|
||
| #### Test 1: Default Notification (Should be Silent) | ||
| ```bash | ||
| yarn start | ||
| ``` | ||
|
|
||
| 1. Login to Rocket.Chat | ||
| 2. Have someone send you a message | ||
| 3. **Expected**: Notification appears WITHOUT sound | ||
| 4. **Verify**: No doorbell or notification sound plays | ||
|
|
||
| #### Test 2: Silent Notification (Explicitly Silent) | ||
| 1. Configure notification with `silent: true` | ||
| 2. Trigger notification | ||
| 3. **Expected**: Notification appears WITHOUT sound | ||
|
|
||
| #### Test 3: Non-Silent Notification (Explicitly with Sound) | ||
| 1. Configure notification with `silent: false` | ||
| 2. Trigger notification | ||
| 3. **Expected**: Notification appears WITHOUT sound (default behavior) | ||
|
|
||
| #### Test 4: Volume Set to 0 | ||
| 1. Set system notification volume to 0 | ||
| 2. Trigger notification | ||
| 3. **Expected**: Notification appears WITHOUT sound | ||
|
|
||
| ### Verification Checklist | ||
|
|
||
| - [ ] No sound plays for default notifications | ||
| - [ ] No sound plays when volume is 0 | ||
| - [ ] No sound plays when silent is true | ||
| - [ ] No sound plays when silent is false (new behavior) | ||
| - [ ] Notifications still appear visually | ||
| - [ ] Click/reply functionality still works | ||
| - [ ] No console errors | ||
|
Comment on lines
+148
to
+156
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Verification checklist contains incorrect expectation. Line 153 states "No sound plays when silent is false (new behavior)" but the actual fix behavior is that sound should play when 📝 Suggested fix - [ ] No sound plays for default notifications
- [ ] No sound plays when volume is 0
- [ ] No sound plays when silent is true
-- [ ] No sound plays when silent is false (new behavior)
+- [ ] Sound plays when silent is explicitly false
- [ ] Notifications still appear visually🤖 Prompt for AI Agents |
||
|
|
||
| ## 🔧 Alternative Solutions Considered | ||
|
|
||
| ### Option 1: Check Volume Setting (Not Implemented) | ||
| ```typescript | ||
| const volume = readSetting('notificationVolume'); | ||
| if (volume === 0) { | ||
| silent = true; | ||
| } | ||
| ``` | ||
| **Why not**: No volume setting exists in current codebase | ||
|
|
||
| ### Option 2: Always Silent (Too Restrictive) | ||
| ```typescript | ||
| silent: true, // Always silent | ||
| ``` | ||
| **Why not**: Removes ability to have sound notifications in future | ||
|
|
||
| ### Option 3: Current Solution (Implemented) ✅ | ||
| ```typescript | ||
| silent: silent !== false, // Silent unless explicitly false | ||
| ``` | ||
| **Why yes**: | ||
| - Fixes the bug | ||
| - Maintains flexibility | ||
| - Respects explicit settings | ||
| - Silent by default (prevents unwanted sounds) | ||
|
|
||
| ## 📊 Impact Analysis | ||
|
|
||
| ### Affected Users | ||
| - All users who receive notifications | ||
| - Especially users who disabled notification sounds | ||
| - Users with volume set to 0 | ||
|
|
||
| ### Before Fix | ||
| - ❌ Unwanted notification sounds | ||
| - ❌ Ignores volume settings | ||
| - ❌ Ignores silent flag | ||
| - ❌ Poor user experience | ||
|
|
||
| ### After Fix | ||
| - ✅ No unwanted sounds | ||
| - ✅ Respects user preferences | ||
| - ✅ Proper silent flag handling | ||
| - ✅ Better user experience | ||
|
|
||
| ### Risk Assessment | ||
| - **Risk Level**: Low | ||
| - **Breaking Changes**: None | ||
| - **Side Effects**: None expected | ||
| - **Rollback**: Easy (single line change) | ||
|
|
||
| ## 🐛 Troubleshooting | ||
|
|
||
| ### Issue: Notifications Still Make Sound | ||
|
|
||
| **Check**: | ||
| 1. Verify fix is applied: Check line 62 in `src/notifications/main.ts` | ||
| 2. Rebuild app: `yarn clean && yarn build` | ||
| 3. Clear cache: Delete `userData` folder | ||
| 4. Check system settings: Ensure system notifications are not overriding | ||
|
|
||
| **Debug**: | ||
| ```typescript | ||
| // Add logging in main.ts | ||
| console.log('Creating notification with silent:', silent); | ||
| console.log('Computed silent value:', silent === true); | ||
| ``` | ||
|
Comment on lines
+220
to
+225
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Debug logging example doesn't match actual implementation. The debug example shows 📝 Suggested fix **Debug**:
```typescript
// Add logging in main.ts
console.log('Creating notification with silent:', silent);
-console.log('Computed silent value:', silent === true);
+console.log('Computed silent value:', silent !== false);Verify each finding against the current code and only fix it if needed. In |
||
|
|
||
| ### Issue: Want Sound Notifications | ||
|
|
||
| **Solution**: This fix makes all notifications silent by default. To enable sounds: | ||
|
|
||
| 1. **Option A**: Modify the fix to check a setting: | ||
| ```typescript | ||
| const enableSound = readSetting('enableNotificationSound'); | ||
| silent: enableSound ? false : true, | ||
| ``` | ||
|
|
||
| 2. **Option B**: Add volume control: | ||
| ```typescript | ||
| const volume = readSetting('notificationVolume') || 0; | ||
| silent: volume === 0, | ||
| ``` | ||
|
|
||
| 3. **Option C**: Respect original silent flag: | ||
| ```typescript | ||
| silent: silent !== false, // Only play sound if explicitly false | ||
| ``` | ||
|
|
||
| ## 🔄 Future Enhancements | ||
|
|
||
| ### Add Volume Control | ||
| ```typescript | ||
| // In rootReducer.ts | ||
| import { notificationVolume } from '../ui/reducers/notificationVolume'; | ||
|
|
||
| export const rootReducer = combineReducers({ | ||
| // ... existing reducers | ||
| notificationVolume, | ||
| }); | ||
| ``` | ||
|
|
||
| ### Add Sound Enable/Disable Setting | ||
| ```typescript | ||
| // In rootReducer.ts | ||
| import { isNotificationSoundEnabled } from '../ui/reducers/isNotificationSoundEnabled'; | ||
|
|
||
| export const rootReducer = combineReducers({ | ||
| // ... existing reducers | ||
| isNotificationSoundEnabled, | ||
| }); | ||
| ``` | ||
|
|
||
| ### Use Settings in Notification Creation | ||
| ```typescript | ||
| const createNotification = async ( | ||
| id: string, | ||
| options: ExtendedNotificationOptions, | ||
| ipcMeta?: ActionIPCMeta | ||
| ): Promise<string> => { | ||
| const notificationVolume = select(({ notificationVolume }) => notificationVolume) || 0; | ||
| const isSoundEnabled = select(({ isNotificationSoundEnabled }) => isNotificationSoundEnabled); | ||
|
|
||
| const shouldBeSilent = !isSoundEnabled || notificationVolume === 0 || options.silent === true; | ||
|
|
||
| const notification = new Notification({ | ||
| // ... other options | ||
| silent: shouldBeSilent, | ||
| }); | ||
|
|
||
| // ... rest of the code | ||
| }; | ||
| ``` | ||
|
|
||
| ## 📝 Related Files | ||
|
|
||
| ### Modified | ||
| - `src/notifications/main.ts` - Fixed silent flag handling | ||
|
|
||
| ### Related (Not Modified) | ||
| - `src/injected.ts` - Notification wrapper class | ||
| - `src/notifications/preload.ts` - Notification IPC bridge | ||
| - `src/notifications/common.ts` - Type definitions | ||
| - `src/notifications/actions.ts` - Redux actions | ||
|
|
||
| ## ✨ Benefits | ||
|
|
||
| - ✅ Fixes annoying doorbell sound bug | ||
| - ✅ Respects user preferences | ||
| - ✅ Minimal code change (1 line) | ||
| - ✅ No breaking changes | ||
| - ✅ Easy to test and verify | ||
| - ✅ Safe default behavior | ||
| - ✅ Maintains notification functionality | ||
|
|
||
| ## 🔒 Security Considerations | ||
|
|
||
| - No security implications | ||
| - No new permissions required | ||
| - No data privacy concerns | ||
| - Standard Electron notification API usage | ||
|
|
||
| ## 📚 References | ||
|
|
||
| - [Electron Notification API](https://www.electronjs.org/docs/latest/api/notification) | ||
| - [Web Notifications API](https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API) | ||
| - [Notification.silent](https://developer.mozilla.org/en-US/docs/Web/API/Notification/silent) | ||
|
|
||
| --- | ||
|
|
||
| **Created**: 2025-01-XX | ||
| **File Modified**: `src/notifications/main.ts` | ||
| **Lines Changed**: 1 line (line 62) | ||
| **Status**: ✅ Ready for testing | ||
| **Impact**: All notification sounds | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test case contradicts the fix behavior.
Test 3 is titled "Non-Silent Notification (Explicitly with Sound)" with
silent: false, but the expected behavior states "Notification appears WITHOUT sound." Per the fix,silent: falseshould explicitly enable sound playback. The expected result should be:📝 Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents