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

Refactored Activities for clarity and a consistent API #1993

Draft
wants to merge 28 commits into
base: main
Choose a base branch
from

Conversation

austincondiff
Copy link
Collaborator

@austincondiff austincondiff commented Feb 20, 2025

Description

This PR refactors the Activity Manager to provide a more Swift-like, type-safe API similar to our NotificationManager. It removes the dependency on NotificationCenter and provides a cleaner interface for managing activities within workspaces. This refactor aligns with CodeEdit’s architecture by ensuring activities are workspace-specific while keeping notifications global.

Note

To test this, go to Settings, press F12, toggle on "Show Internal Development Inspector". In a workspace, go to the Internal Development Inspector in the Inspector Area, and then test Activities using the Activities form.

Changes

Filesystem changes

CodeEdit/
└── CodeEdit/
│   └── Features/
│       └── Activities/                               (previously ActivityViewer)
│           ├── ActivityManager.swift                 (previously TaskNotificationHandler)
│           ├── Models/
│           │   └── CEActivity.swift                  (previously TaskNotificationModel)
│           └── Views/
│                ├── ActivityView.swift               (previously TaskNotificationView) 
│                └── ActivitiesDetailView.swift       (previously TaskNotificationsDetailView)
└── CodeEditTests/
    └── Features/
        └── Activities/                               (previously ActivityViewer)
            └── ActivityManagerTests.swift            (previously TaskNotificationHandlerTests)

New API

Activities can now be created, updated and deleted using a simple, fluent API:

@ObservedObject var activityManager: ActivityManager

// Create
let activity = activityManager.post(
    title: "Indexing Files",
    message: "Processing workspace files",
    isLoading: true
)

// Create with priority (shows at top of list)
let activity = activityManager.post(
    priority: true,
    title: "Building Project",
    message: "Compiling sources",
    percentage: 0.0,
    isLoading: true
)

// Update
activityManager.update(
    id: activity.id,
    percentage: 0.5,
    message: "50% complete"
)

// Delete
activityManager.delete(id: activity.id)

// Delete with delay
activityManager.delete(id: activity.id, delay: 4.0)

Architecture Changes

  • Activities are now scoped to workspaces instead of being global
  • ActivityManager is now a proper ObservableObject
  • Removed NotificationCenter-based activity management
  • Added proper type safety for activity parameters
  • Activities are now properly tracked and referenced by their own IDs

Migration

Updated existing activity creators to use new API:

  • Task execution activities in CEActiveTask
  • File indexing activities in WorkspaceDocument+Index
  • Updated tests to verify new API behavior

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

… UI. Improved aesthetics of notification banner
…he notification overlay UI previously just used for temporary notifications.
- 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.
…distinction in name and have a consistent API when compared with Notifications.
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