-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Refactored Activities for clarity and a consistent API #1993
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
Draft
austincondiff
wants to merge
36
commits into
CodeEditApp:main
from
austincondiff:activities-refactor
Draft
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
2f63de4
Added global notifications system
austincondiff 898a87c
Refactored FeatureIcon and notifications to support custom images
austincondiff 418e540
Fixed SwiftLint errors
austincondiff 14fc34f
Fixed SwiftLint errors
austincondiff 2e73c75
Deleted unused file
austincondiff a0e7357
Added sticky notifications. Allowed multiple notifications to overlay...
austincondiff 5ba7a66
Streamlined UI getting rid of the notifications popover in favor of t...
austincondiff e7216ca
Added a close button click state, allows clicking under scroll view.
austincondiff 4bc9151
Remove test notification
austincondiff d636277
Improve notification handling and workspace panel behavior
austincondiff 9df84a1
Fixed SwiftLint and PR issues
austincondiff 951e899
Fixed animation glitch when taking action on a notification while not...
austincondiff 4518e4c
Changed variable name isManuallyShown to isPresented, and notificatio...
austincondiff 46adb4c
Refactored CENotification to use delegated inits.
austincondiff 8abb2b5
Moved CloseButtonStyle into CodeEditUI and renamed it OverlayButtonStyle
austincondiff 6bdde36
Using cancelables so workspace cleanup is more concise
austincondiff 42f802e
Refactored Activities (previously TaskNotifications) to have a clear ...
austincondiff 596847c
Renamed a few files for consistency
austincondiff 87ebaa7
Added Activities section to the Internal Developer Inspector for test...
austincondiff 4b262f8
Fixed SwiftLint errors and made a few adjustments
austincondiff 97d7f07
Added update and delete functions to notification manager.
austincondiff 694d868
Fixed some tests
austincondiff e602eab
Put back window observer
austincondiff 09e52d7
Clip the inspector so when scrolled, contents can't be seen under too...
austincondiff 43ca864
Performance improvements
austincondiff ca6a3fc
Made fixes suggested in PR.
austincondiff c4f7479
Rebased from latest main
austincondiff 6f2e611
Removed files inadvertedly added durring rebase
austincondiff 17b940f
Rebased from main
austincondiff 46c94d1
SwiftLint fix
austincondiff 299ad40
Cleanup
austincondiff ce4f72c
Cleanup
austincondiff c858f66
Merge branch 'main' into activities-refactor
austincondiff 403f480
Update CodeEdit/Features/Documents/WorkspaceDocument/WorkspaceDocumen...
austincondiff 6b02dfb
fix: Finish the continuation and await the consumtion of the stream
tom-ludwig 61278fe
lint: fix linter warning
tom-ludwig File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
CodeEdit/Features/Activities/ActivityManager.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
// | ||
// ActivityManager.swift | ||
// CodeEdit | ||
// | ||
// Created by Tommy Ludwig on 21.06.24. | ||
// | ||
|
||
import Foundation | ||
import Combine | ||
import SwiftUI | ||
|
||
/// Manages activities for a workspace | ||
@MainActor | ||
final class ActivityManager: ObservableObject { | ||
/// Currently displayed activities | ||
@Published private(set) var activities: [CEActivity] = [] | ||
|
||
/// Debounce work item for batching updates | ||
private var updateWorkItems: [String: DispatchWorkItem] = [:] | ||
|
||
/// Posts a new activity | ||
/// - Parameters: | ||
/// - priority: Whether to insert at start of list | ||
/// - title: Activity title | ||
/// - message: Optional detail message | ||
/// - percentage: Optional progress percentage (0-1) | ||
/// - isLoading: Whether activity shows loading indicator | ||
/// - Returns: The created activity | ||
@discardableResult | ||
func post( | ||
priority: Bool = false, | ||
title: String, | ||
message: String? = nil, | ||
percentage: Double? = nil, | ||
isLoading: Bool = false | ||
) -> CEActivity { | ||
let activity = CEActivity( | ||
id: UUID().uuidString, | ||
title: title, | ||
message: message, | ||
percentage: percentage, | ||
isLoading: isLoading | ||
) | ||
|
||
withAnimation(.easeInOut(duration: 0.3)) { | ||
if priority { | ||
activities.insert(activity, at: 0) | ||
} else { | ||
activities.append(activity) | ||
} | ||
} | ||
|
||
return activity | ||
} | ||
|
||
/// Updates an existing activity with debouncing | ||
/// - Parameters: | ||
/// - id: ID of activity to update | ||
/// - title: New title (optional) | ||
/// - message: New message (optional) | ||
/// - percentage: New progress percentage (optional) | ||
/// - isLoading: New loading state (optional) | ||
func update( | ||
id: String, | ||
title: String? = nil, | ||
message: String? = nil, | ||
percentage: Double? = nil, | ||
isLoading: Bool? = nil | ||
) { | ||
// Cancel any pending update for this specific activity | ||
updateWorkItems[id]?.cancel() | ||
|
||
// Create new work item | ||
let workItem = DispatchWorkItem { [weak self] in | ||
guard let self else { return } | ||
|
||
if let index = self.activities.firstIndex(where: { 0ドル.id == id }) { | ||
var activity = self.activities[index] | ||
|
||
if let title = title { | ||
activity.title = title | ||
} | ||
if let message = message { | ||
activity.message = message | ||
} | ||
if let percentage = percentage { | ||
activity.percentage = percentage | ||
} | ||
if let isLoading = isLoading { | ||
activity.isLoading = isLoading | ||
} | ||
|
||
withAnimation(.easeInOut(duration: 0.15)) { | ||
self.activities[index] = activity | ||
} | ||
} | ||
|
||
self.updateWorkItems.removeValue(forKey: id) | ||
} | ||
|
||
// Store work item and schedule after delay | ||
updateWorkItems[id] = workItem | ||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.05, execute: workItem) | ||
} | ||
|
||
/// Deletes an activity | ||
/// - Parameter id: ID of activity to delete | ||
func delete(id: String) { | ||
// Clear any pending updates for this activity | ||
updateWorkItems[id]?.cancel() | ||
updateWorkItems.removeValue(forKey: id) | ||
|
||
withAnimation(.easeInOut(duration: 0.3)) { | ||
activities.removeAll { 0ドル.id == id } | ||
} | ||
} | ||
|
||
/// Deletes an activity after a delay | ||
/// - Parameters: | ||
/// - id: ID of activity to delete | ||
/// - delay: Time to wait before deleting | ||
func delete(id: String, delay: TimeInterval) { | ||
Task { @MainActor in | ||
try? await Task.sleep(for: .seconds(delay)) | ||
delete(id: id) | ||
} | ||
} | ||
} | ||
|
||
extension Notification.Name { | ||
static let activity = Notification.Name("activity") | ||
} |
6 changes: 3 additions & 3 deletions
...Viewer/Models/TaskNotificationModel.swift → ...atures/Activities/Models/CEActivity.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.