Skip to content
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

Implemented Global Notification System #1984

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

austincondiff
Copy link
Collaborator

@austincondiff austincondiff commented Feb 12, 2025

Description

This PR introduces a global notification system in CodeEdit that allows users to receive and manage notifications across all open workspaces. Notifications provide important alerts and updates while ensuring consistency across multiple instances of the application.

Note

To test, go to Settings, press F12. Go to the Developer page and toggle on "Show Internal Development Inspector". In a workspace, in the inspector, open the new internal development inspector by clicking the hammer icon.

Key Features

  • Temporary Notifications:

    • Displayed at the top-right corner of the active workspace.
    • Automatically hide after 5 seconds, unless hovered over.
  • Sticky Notifications:

    • Persist in the UI until manually dismissed.
    • Useful for critical alerts or alerts where user action or attention is required.
  • Notification Button & Popover:

    • Added to the toolbar in each workspace.
    • Displays a notification count for unread notifications.
    • Clicking the button opens a popove* containing all notifications.
    • When opening popover, all notifications are hidden. Sticky notifications that are not dismissed are restored over the UI after popover is closed.

Behavior:

  • Notifications do not persist after the application is quit.
  • All open workspaces stay in sync with the latest notifications.
  • Interacting with a notification (e.g., dismissing it) updates all workspaces.
  • Hovering over a temporary notification pauses and resets its hide timer.
  • When CodeEdit is not in focus, notifications are redirected to the system Notification Center.
  • Clicking the system notification action button focuses CodeEdit, executes the action, and dismisses the corresponding CodeEdit notification.
  • Dismissing a CodeEdit notification also dismisses its corresponding system notification (if one exists), and vice versa.
  • The notification panel closes when clicking outside of it, behaving like other menus.

Screenshots

Screen.Recording.2025-02-14.at.4.09.29.PM.mp4
Screen.Recording.2025-02-14.at.5.36.32.PM.mov

The following screen recording showcases the first iteration. In the design channel on Discord, @thecoolwinter suggested moving in this direction. While it required a bit more effort, I agree that it ultimately results in a much cleaner and more polished look.

Screen.Recording.2025-02-12.at.12.42.55.PM.mov

Usage

With a symbol (works with both SF Symbols and CodeEditSymbols)

NotificationManager.shared.post(
    iconSymbol: "bell",
    title: "New Notification Created",
    description: "Successfully created new notification",
    actionButtonTitle: "Action",
    action: {
        print("Action taken")
    }
)

The icon defaults to the users accent color if one isn't specified however you can specify a color here...

NotificationManager.shared.post(
    iconSymbol: "bell",
    iconColor: .red,
    title: "New Notification Created",
    description: "Successfully created new notification",
    actionButtonTitle: "Action",
    action: {
        print("Action taken")
    }
)

With a custom image...

NotificationManager.shared.post(
    iconImage: Image("GitHubIcon"),
    title: "New Notification Created",
    description: "Successfully created new notification",
    actionButtonTitle: "Action",
    action: {
        print("Action taken")
    }
)

With an emoji...

NotificationManager.shared.post(
    iconText: "👋",
    title: "New Notification Created",
    description: "Successfully created new notification",
    actionButtonTitle: "Action",
    action: {
        print("Action taken")
    }
)

With text...

NotificationManager.shared.post(
    iconText: "A",
    iconTextColor: .white,
    iconColor: .red,
    title: "New Notification Created",
    description: "Successfully created new notification",
    actionButtonTitle: "Action",
    action: {
        print("Action taken")
    }
)

Future Considerations

Currently, NotificationManager is shared between workspaces. This is intentional because notifications should generally speaking be global and not workspace specific. We may at some point allow for workspace specific notifications in addition to global notifications.

Related Issues

Checklist

  • I read and understood the contributing guide as well as the code of conduct
  • The issues this PR addresses are related to each other
  • My changes generate no new warnings
  • My code builds and runs on my machine
  • My changes are all related to the related issue above
  • I documented my code

@austincondiff austincondiff changed the title Added global notification system Implemented Global Notification System Feb 12, 2025
@austincondiff austincondiff marked this pull request as ready for review February 15, 2025 00:05
Copy link
Collaborator

@thecoolwinter thecoolwinter left a comment

Choose a reason for hiding this comment

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

A few nitpicks and a suggestion for some duplicated initializers. Adding the FeatureIcon was a good idea! Documentation is also top notch.

CodeEdit/Features/Notifications/NotificationManager.swift Outdated Show resolved Hide resolved

import SwiftUI

struct CloseButtonStyle: ButtonStyle {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should probably be in it's own file

- Add system notification action button that, when clicked, focuses CodeEdit, runs the action, and dismisses the corresponding CodeEdit notification.
- Dismissing a CodeEdit notification now also dismisses its corresponding system notification, and vice versa.
- The notification panel in a workspace now closes when clicking outside of it, behaving like other menus.
- Refactored notification state management: Moved display-related state from `NotificationService` to a dedicated view model to ensure notification panels remain independent across workspaces.
…ector can be enabled with a setting found in the hidden developer settings page.
…ification panel is presented. Removed notification tests and made the notification test in the dev inspector more configurable.
…nOverlay to notificationPanel. Fixed SwiftLint errors.
Copy link
Collaborator

@thecoolwinter thecoolwinter left a comment

Choose a reason for hiding this comment

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

One last question, and reopened a comment that I think was mistakenly resolved

@austincondiff
Copy link
Collaborator Author

Oh whoops. I closed it not by mistake. I created the OverlayButtonStyle but didn't realize I left CloseButtobStyle there. I'll remove it.

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.

✨ Global Notification System
2 participants