Skip to content

fix: guard Notification.isSupported for standalone/Docker (#42)#67

Merged
matt1398 merged 1 commit intomatt1398:mainfrom
Psypeal:fix/notification-crash
Feb 23, 2026
Merged

fix: guard Notification.isSupported for standalone/Docker (#42)#67
matt1398 merged 1 commit intomatt1398:mainfrom
Psypeal:fix/notification-crash

Conversation

@Psypeal
Copy link
Contributor

@Psypeal Psypeal commented Feb 22, 2026

Summary

  • Add typeof checks before calling Notification.isSupported() to prevent crashes in environments where the Notification API is unavailable

Fixes #42

Changes

  • src/main/services/infrastructure/NotificationManager.ts - Add typeof guards for Notification and Notification.isSupported

Test plan

  • App starts without crash in Docker/standalone mode
  • Native notifications still work in normal Electron mode

Summary by CodeRabbit

  • Bug Fixes
    • Improved notification system reliability by adding defensive checks for environments where the Notification API is unavailable (e.g., Docker, standalone deployments). The system now gracefully handles these scenarios with appropriate logging while preserving existing functionality.

Add typeof checks before calling Notification.isSupported() to prevent crashes in environments where the Notification API is unavailable.
@gemini-code-assist
Copy link

Summary of Changes

Hello @Psypeal, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the application's robustness by implementing defensive programming around the Notification API. It specifically addresses potential crashes in environments like Docker or standalone deployments where Electron's native notification capabilities might not be present, ensuring the application remains stable while preserving notification functionality where supported.

Highlights

  • Crash Prevention: Added typeof checks before calling Notification.isSupported() to prevent application crashes in environments where the Notification API is unavailable, such as standalone or Docker modes.
Changelog
  • src/main/services/infrastructure/NotificationManager.ts
    • Implemented typeof guards for Notification and Notification.isSupported to prevent errors in unsupported environments.
Activity
  • No human activity has occurred on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai coderabbitai bot added the bug Something isn't working label Feb 22, 2026
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request correctly addresses potential crashes in environments where the Electron Notification API is unavailable, such as Docker or standalone mode. The added guards are effective and ensure the application remains stable in headless environments. The implementation can be made more concise by leveraging modern JavaScript features like optional chaining, which is already supported in the project.

Comment on lines +377 to +381
if (
typeof Notification === 'undefined' ||
typeof Notification.isSupported !== 'function' ||
!Notification.isSupported()
) {

Choose a reason for hiding this comment

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

medium

This guard can be simplified using optional chaining for better readability and conciseness. This approach safely handles cases where Notification is undefined or isSupported is not a function, which is the primary goal of this fix. Since the project already uses modern syntax (like the nullish coalescing assignment operator), this is consistent with the existing codebase.

    if (!Notification?.isSupported?.()) {

@coderabbitai
Copy link

coderabbitai bot commented Feb 22, 2026

📝 Walkthrough

Walkthrough

Adds defensive null/type checks to the NotificationManager's Electron Notification API usage to handle environments where the Notification API is unavailable, preventing runtime errors when attempting to call potentially undefined methods.

Changes

Cohort / File(s) Summary
Notification Manager Defensive Checks
src/main/services/infrastructure/NotificationManager.ts
Added guarded conditions to check if Notification is defined, if isSupported is a function, and if isSupported() returns true before proceeding. Logs a warning and exits early if any condition fails, preventing crashes in standalone/Docker environments where Notification API is unavailable.

Suggested labels

bug

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The pull request successfully addresses issue #42 by adding typeof guards to prevent crashes when Notification API is unavailable in Docker/standalone environments.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the Notification API issue in Docker/standalone environments with no unrelated modifications.

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

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


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

Copy link

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/main/services/infrastructure/NotificationManager.ts`:
- Around line 375-384: The inline runtime guard in showNativeNotification that
checks Notification support should be extracted into a clearly named type-guard
function (e.g., isNotificationSupported) to follow the isXxx convention; create
a new function isNotificationSupported(): boolean that performs the existing
typeof Notification and Notification.isSupported checks, replace the inline
condition in showNativeNotification with a call to isNotificationSupported(),
and update any imports/exports or tests that reference this check to use the new
function.

Comment on lines 375 to 384
private showNativeNotification(error: DetectedError): void {
// Check if Notification is supported
if (!Notification.isSupported()) {
// Guard against standalone/Docker mode where Electron's Notification API is unavailable
if (
typeof Notification === 'undefined' ||
typeof Notification.isSupported !== 'function' ||
!Notification.isSupported()
) {
logger.warn('Native notifications not supported');
return;
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# First, locate and verify the NotificationManager.ts file
fd -t f "NotificationManager.ts" --exec wc -l {} \;

Repository: matt1398/claude-devtools

Length of output: 129


🏁 Script executed:

# Check the actual code at lines 375-384
fd -t f "NotificationManager.ts" --exec sed -n '370,390p' {} +

Repository: matt1398/claude-devtools

Length of output: 835


🏁 Script executed:

# Search for existing type guards following isXxx pattern
rg -n --type=ts "^\s*(?:private|public|static)?\s+\w*is[A-Z][a-zA-Z0-9]*\s*\(" --max-count=20

Repository: matt1398/claude-devtools

Length of output: 2741


🏁 Script executed:

# Check if there's a types/notifications.ts file as mentioned in learnings
fd -t f "types/notifications.ts" --exec cat {} +

Repository: matt1398/claude-devtools

Length of output: 50


🏁 Script executed:

# Search for existing Notification support checks in codebase
rg -n --type=ts "Notification\.isSupported|typeof Notification" -C 2

Repository: matt1398/claude-devtools

Length of output: 789


Extract an isXxx type guard for Notification support checks.

Runtime guards should follow the isXxx naming convention per coding guidelines. The inline typeof checks should be extracted into a type guard method.

Suggested refactor
+  private static isNotificationSupported(): boolean {
+    return (
+      typeof Notification !== 'undefined' &&
+      typeof Notification.isSupported === 'function' &&
+      Notification.isSupported()
+    );
+  }
+
   private showNativeNotification(error: DetectedError): void {
     // Guard against standalone/Docker mode where Electron's Notification API is unavailable
-    if (
-      typeof Notification === 'undefined' ||
-      typeof Notification.isSupported !== 'function' ||
-      !Notification.isSupported()
-    ) {
+    if (!NotificationManager.isNotificationSupported()) {
       logger.warn('Native notifications not supported');
       return;
     }
📝 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
private showNativeNotification(error: DetectedError): void {
// Check if Notification is supported
if (!Notification.isSupported()) {
// Guard against standalone/Docker mode where Electron's Notification API is unavailable
if (
typeof Notification === 'undefined' ||
typeof Notification.isSupported !== 'function' ||
!Notification.isSupported()
) {
logger.warn('Native notifications not supported');
return;
}
private static isNotificationSupported(): boolean {
return (
typeof Notification !== 'undefined' &&
typeof Notification.isSupported === 'function' &&
Notification.isSupported()
);
}
private showNativeNotification(error: DetectedError): void {
// Guard against standalone/Docker mode where Electron's Notification API is unavailable
if (!NotificationManager.isNotificationSupported()) {
logger.warn('Native notifications not supported');
return;
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/services/infrastructure/NotificationManager.ts` around lines 375 -
384, The inline runtime guard in showNativeNotification that checks Notification
support should be extracted into a clearly named type-guard function (e.g.,
isNotificationSupported) to follow the isXxx convention; create a new function
isNotificationSupported(): boolean that performs the existing typeof
Notification and Notification.isSupported checks, replace the inline condition
in showNativeNotification with a call to isNotificationSupported(), and update
any imports/exports or tests that reference this check to use the new function.

@matt1398 matt1398 merged commit a95f107 into matt1398:main Feb 23, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

devtools not working with vscode

2 participants