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 11 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.

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.

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

Note

Add the following to FileInspectorView.swift to test

Section("Test Notifications") {
    Button("Add Test Notification") {
        NotificationManager.shared.post(
            iconSymbol: "bell.badge.fill",
            iconColor: .red,
            title: "Test Notification",
            description: "This is a test notification",
            actionButtonTitle: "Action",
            action: {
                print("Test notification action triggered")
            }
        )
    }
    Button("Add Sticky Notification") {
        NotificationManager.shared.post(
            iconSymbol: "pin.fill",
            iconColor: .orange,
            title: "Sticky Notification",
            description: "This notification will stay until dismissed",
            actionButtonTitle: "Acknowledge",
            action: {
                print("Sticky notification acknowledged")
            },
            isSticky: true
        )
    }
}

@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
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
1 participant