Skip to content

Commit 58dcbad

Browse files
committed
Fixed animation glitch when taking action on a notification while notification panel is presented. Removed notification tests and made the notification test in the dev inspector more configurable.
1 parent 4eca1c4 commit 58dcbad

4 files changed

Lines changed: 11 additions & 138 deletions

File tree

CodeEdit/AppDelegate.swift

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate, ObservableObject {
2626

2727
NSApp.closeWindow(.welcome, .about)
2828

29-
// Add test notification
30-
DispatchQueue.main.asyncAfter(deadline: .now() + 5.0) {
31-
NotificationManager.shared.post(
32-
iconText: "👋",
33-
iconTextColor: .white,
34-
iconColor: .indigo,
35-
title: "Welcome to CodeEdit",
36-
description: "This is a test notification to demonstrate the notification system.",
37-
actionButtonTitle: "Learn More...",
38-
action: {
39-
print("Action button clicked!")
40-
}
41-
)
42-
}
43-
4429
DispatchQueue.main.async {
4530
var needToHandleOpen = true
4631

CodeEdit/Features/InspectorArea/FileInspector/FileInspectorView.swift

Lines changed: 0 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -59,71 +59,6 @@ struct FileInspectorView: View {
5959
widthOptions
6060
wrapLinesToggle
6161
}
62-
Section("Test Notifications") {
63-
Button("Add Notification") {
64-
let (iconSymbol, iconColor) = randomSymbolAndColor()
65-
NotificationManager.shared.post(
66-
iconSymbol: iconSymbol,
67-
iconColor: iconColor,
68-
title: "Test Notification",
69-
description: "This is a test notification.",
70-
actionButtonTitle: "Action",
71-
action: {
72-
print("Test notification action triggered")
73-
}
74-
)
75-
}
76-
Button("Add Sticky Notification") {
77-
NotificationManager.shared.post(
78-
iconSymbol: "pin.fill",
79-
iconColor: .orange,
80-
title: "Sticky Notification",
81-
description: "This notification will stay until dismissed.",
82-
actionButtonTitle: "Acknowledge",
83-
action: {
84-
print("Sticky notification acknowledged")
85-
},
86-
isSticky: true
87-
)
88-
}
89-
Button("Add Image Notification") {
90-
NotificationManager.shared.post(
91-
iconImage: randomImage(),
92-
title: "Test Notification with Image",
93-
description: "This is a test notification with a custom image.",
94-
actionButtonTitle: "Action",
95-
action: {
96-
print("Test notification action triggered")
97-
}
98-
)
99-
}
100-
Button("Add Text Notification") {
101-
NotificationManager.shared.post(
102-
iconText: randomLetter(),
103-
iconTextColor: .white,
104-
iconColor: randomColor(),
105-
title: "Text Notification",
106-
description: "This is a test notification with text.",
107-
actionButtonTitle: "Acknowledge",
108-
action: {
109-
print("Test notification action triggered")
110-
}
111-
)
112-
}
113-
Button("Add Emoji Notification") {
114-
NotificationManager.shared.post(
115-
iconText: randomEmoji(),
116-
iconTextColor: .white,
117-
iconColor: randomColor(),
118-
title: "Emoji Notification",
119-
description: "This is a test notification with an emoji.",
120-
actionButtonTitle: "Acknowledge",
121-
action: {
122-
print("Test notification action triggered")
123-
}
124-
)
125-
}
126-
}
12762
}
12863
} else {
12964
NoSelectionInspectorView()
@@ -146,62 +81,6 @@ struct FileInspectorView: View {
14681
}
14782
}
14883

149-
func randomColor() -> Color {
150-
let colors: [Color] = [
151-
.red, .orange, .yellow, .green, .mint, .cyan,
152-
.teal, .blue, .indigo, .purple, .pink, .gray
153-
]
154-
return colors.randomElement() ?? .black
155-
}
156-
157-
func randomSymbolAndColor() -> (String, Color) {
158-
let symbols: [(String, Color)] = [
159-
("bell.fill", .red),
160-
("bell.badge.fill", .red),
161-
("exclamationmark.triangle.fill", .orange),
162-
("info.circle.fill", .blue),
163-
("checkmark.seal.fill", .green),
164-
("xmark.octagon.fill", .red),
165-
("bubble.left.fill", .teal),
166-
("envelope.fill", .blue),
167-
("phone.fill", .green),
168-
("megaphone.fill", .pink),
169-
("clock.fill", .gray),
170-
("calendar", .red),
171-
("flag.fill", .green),
172-
("bookmark.fill", .orange),
173-
("bolt.fill", .indigo),
174-
("shield.lefthalf.fill", .red),
175-
("gift.fill", .purple),
176-
("heart.fill", .pink),
177-
("star.fill", .orange),
178-
("curlybraces", .cyan),
179-
]
180-
return symbols.randomElement() ?? ("bell.fill", .red)
181-
}
182-
183-
func randomEmoji() -> String {
184-
let emoji: [String] = [
185-
"🔔", "🚨", "⚠️", "👋", "😍", "😎", "😘", "😜", "😝", "😀", "😁",
186-
"😂", "🤣", "😃", "😄", "😅", "😆", "😇", "😉", "😊", "😋", "😌"
187-
]
188-
return emoji.randomElement() ?? "🔔"
189-
}
190-
191-
func randomImage() -> Image {
192-
let images: [Image] = [
193-
Image("GitHubIcon"),
194-
Image("BitBucketIcon"),
195-
Image("GitLabIcon")
196-
]
197-
return images.randomElement() ?? Image("GitHubIcon")
198-
}
199-
200-
func randomLetter() -> String {
201-
let letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".map { String($0) }
202-
return letters.randomElement() ?? "A"
203-
}
204-
20584
@ViewBuilder private var fileNameField: some View {
20685
@State var isValid: Bool = true
20786

CodeEdit/Features/Notifications/ViewModels/NotificationOverlayViewModel.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,21 @@ final class NotificationOverlayViewModel: ObservableObject {
181181
}
182182

183183
/// Dismisses a specific notification
184-
func dismissNotification(_ notification: CENotification) {
184+
func dismissNotification(_ notification: CENotification, disableAnimation: Bool = false) {
185185
// Clean up timers
186186
timers[notification.id]?.invalidate()
187187
timers[notification.id] = nil
188188
hiddenNotificationIds.remove(notification.id)
189189

190190
// Mark as being dismissed for animation
191191
if let index = activeNotifications.firstIndex(where: { $0.id == notification.id }) {
192+
if disableAnimation {
193+
self.activeNotifications.removeAll(where: { $0.id == notification.id })
194+
NotificationManager.shared.markAsRead(notification)
195+
NotificationManager.shared.dismissNotification(notification)
196+
return
197+
}
198+
192199
var dismissingNotification = activeNotifications[index]
193200
dismissingNotification.isBeingDismissed = true
194201
activeNotifications[index] = dismissingNotification

CodeEdit/Features/Notifications/Views/NotificationOverlayView.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ struct NotificationOverlayView: View {
4646
},
4747
onAction: {
4848
notification.action()
49-
workspace.notificationOverlay.dismissNotification(notification)
5049
if workspace.notificationOverlay.isManuallyShown {
5150
workspace.notificationOverlay.toggleNotificationsVisibility()
51+
workspace.notificationOverlay.dismissNotification(notification, disableAnimation: true)
52+
} else {
53+
workspace.notificationOverlay.dismissNotification(notification)
5254
}
5355
}
5456
)

0 commit comments

Comments
 (0)