Skip to content

Commit 6988330

Browse files
committed
Fixed SwiftLint errors
1 parent 779e3a6 commit 6988330

File tree

7 files changed

+123
-25
lines changed

7 files changed

+123
-25
lines changed

CodeEdit/AppDelegate.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ final class AppDelegate: NSObject, NSApplicationDelegate, ObservableObject {
2929
// Add test notification
3030
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
3131
NotificationManager.shared.post(
32-
iconSymbol: "bell.badge",
32+
iconText: "👋",
33+
iconTextColor: .white,
34+
iconColor: .indigo,
3335
title: "Welcome to CodeEdit",
3436
description: "This is a test notification to demonstrate the notification system.",
35-
actionButtonTitle: "Learn More",
37+
actionButtonTitle: "Learn More...",
3638
action: {
3739
print("Action button clicked!")
3840
}
@@ -85,7 +87,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, ObservableObject {
8587
handleOpen()
8688
return false
8789
}
88-
90+
8991
/// Check if all windows are either miniaturized or not visible.
9092
/// If so, attempt to find the first miniaturized window and deminiaturize it.
9193
guard sender.windows.allSatisfy({ $0.isMiniaturized || !$0.isVisible }) else { return false }
@@ -164,9 +166,9 @@ final class AppDelegate: NSObject, NSApplicationDelegate, ObservableObject {
164166
func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply {
165167
let projects: [String] = CodeEditDocumentController.shared.documents
166168
.compactMap { ($0 as? WorkspaceDocument)?.fileURL?.path }
167-
169+
168170
UserDefaults.standard.set(projects, forKey: AppDelegate.recoverWorkspacesKey)
169-
171+
170172
let areAllDocumentsClean = CodeEditDocumentController.shared.documents.allSatisfy { !$0.isDocumentEdited }
171173
guard areAllDocumentsClean else {
172174
CodeEditDocumentController.shared.closeAllDocuments(

CodeEdit/Features/CodeEditUI/Views/FeatureIcon.swift

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ struct FeatureIcon: View {
2323
self.size = size ?? 20
2424
}
2525

26+
init(
27+
text: String,
28+
textColor: Color? = nil,
29+
color: Color? = nil,
30+
size: CGFloat? = nil
31+
) {
32+
self.content = .text(text, textColor: textColor)
33+
self.color = color ?? .accentColor
34+
self.size = size ?? 20
35+
}
36+
2637
init(
2738
image: Image,
2839
size: CGFloat? = nil
@@ -45,13 +56,17 @@ struct FeatureIcon: View {
4556
.fill(background)
4657
.overlay {
4758
switch content {
48-
case .symbol(let name):
59+
case let .symbol(name):
4960
getSafeImage(named: name)
5061
.resizable()
5162
.aspectRatio(contentMode: .fit)
5263
.foregroundColor(.white)
5364
.padding(size / 8)
54-
case .image(let image):
65+
case let .text(text, textColor):
66+
Text(text)
67+
.font(.system(size: size * 0.65))
68+
.foregroundColor(textColor ?? .primary)
69+
case let .image(image):
5570
image
5671
.resizable()
5772
.aspectRatio(contentMode: .fill)
@@ -68,7 +83,7 @@ struct FeatureIcon: View {
6883

6984
private var background: AnyShapeStyle {
7085
switch content {
71-
case .symbol:
86+
case .symbol, .text:
7287
return AnyShapeStyle((color ?? .accentColor).gradient)
7388
case .image:
7489
return AnyShapeStyle(.regularMaterial)
@@ -78,5 +93,6 @@ struct FeatureIcon: View {
7893

7994
private enum IconContent {
8095
case symbol(String)
96+
case text(String, textColor: Color?)
8197
case image(Image)
8298
}

CodeEdit/Features/InspectorArea/FileInspector/FileInspectorView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ struct FileInspectorView: View {
9191

9292
func addTestNotification () {
9393
NotificationManager.shared.post(
94-
iconSymbol: "bell",
94+
iconSymbol: "bell.badge.fill",
9595
iconColor: .red,
9696
title: "New Notification Created",
9797
description: "Successfully created new notification",

CodeEdit/Features/Notifications/Models/CENotification.swift

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ struct CENotification: Identifiable, Equatable {
1818
let isSticky: Bool
1919
var isRead: Bool
2020
let timestamp: Date
21-
21+
2222
enum IconType {
2323
case symbol(name: String, color: Color?)
2424
case image(Image)
25+
case text(String, backgroundColor: Color?, textColor: Color?)
2526
}
26-
27+
2728
init(
2829
id: UUID = UUID(),
2930
iconSymbol: String,
@@ -45,7 +46,30 @@ struct CENotification: Identifiable, Equatable {
4546
self.isRead = isRead
4647
self.timestamp = Date()
4748
}
48-
49+
50+
init(
51+
id: UUID = UUID(),
52+
iconText: String,
53+
iconTextColor: Color? = nil,
54+
iconColor: Color? = nil,
55+
title: String,
56+
description: String,
57+
actionButtonTitle: String,
58+
action: @escaping () -> Void,
59+
isSticky: Bool = false,
60+
isRead: Bool = false
61+
) {
62+
self.id = id
63+
self.icon = .text(iconText, backgroundColor: iconColor, textColor: iconTextColor)
64+
self.title = title
65+
self.description = description
66+
self.actionButtonTitle = actionButtonTitle
67+
self.action = action
68+
self.isSticky = isSticky
69+
self.isRead = isRead
70+
self.timestamp = Date()
71+
}
72+
4973
init(
5074
id: UUID = UUID(),
5175
iconImage: Image,
@@ -66,8 +90,8 @@ struct CENotification: Identifiable, Equatable {
6690
self.isRead = isRead
6791
self.timestamp = Date()
6892
}
69-
93+
7094
static func == (lhs: CENotification, rhs: CENotification) -> Bool {
7195
lhs.id == rhs.id
7296
}
73-
}
97+
}

CodeEdit/Features/Notifications/NotificationManager.swift

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ final class NotificationManager: NSObject, ObservableObject {
3030
private var isPaused: Bool = false
3131
private var isAppActive: Bool = true
3232

33-
private override init() {
33+
override private init() {
3434
super.init()
3535

3636
// Request notification permissions
@@ -149,6 +149,48 @@ final class NotificationManager: NSObject, ObservableObject {
149149
}
150150
}
151151

152+
/// Posts a new notification
153+
/// - Parameters:
154+
/// - iconText: Text or emoji for the notification icon
155+
/// - iconTextColor: Color of the text/emoji (defaults to primary label color)
156+
/// - iconColor: Background color for the icon
157+
/// - title: Main notification title
158+
/// - description: Detailed notification message
159+
/// - actionButtonTitle: Title for the action button
160+
/// - action: Closure to execute when action button is clicked
161+
/// - isSticky: Whether the notification should persist until manually dismissed
162+
func post(
163+
iconText: String,
164+
iconTextColor: Color? = nil,
165+
iconColor: Color? = Color(.systemBlue),
166+
title: String,
167+
description: String,
168+
actionButtonTitle: String,
169+
action: @escaping () -> Void,
170+
isSticky: Bool = false
171+
) {
172+
let notification = CENotification(
173+
iconText: iconText,
174+
iconTextColor: iconTextColor,
175+
iconColor: iconColor,
176+
title: title,
177+
description: description,
178+
actionButtonTitle: actionButtonTitle,
179+
action: action,
180+
isSticky: isSticky
181+
)
182+
183+
DispatchQueue.main.async { [weak self] in
184+
self?.notifications.append(notification)
185+
186+
if self?.isAppActive == true {
187+
self?.showTemporaryNotification(notification)
188+
} else {
189+
self?.showSystemNotification(notification)
190+
}
191+
}
192+
}
193+
152194
/// Shows a notification in macOS Notification Center when app is in background
153195
private func showSystemNotification(_ notification: CENotification) {
154196
let content = UNMutableNotificationContent()

CodeEdit/Features/Notifications/Views/NotificationBannerView.swift

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,21 @@
88
import SwiftUI
99

1010
struct NotificationBannerView: View {
11+
@Environment(\.isOverlay)
12+
private var isOverlay
13+
14+
@Environment(\.isSingleListItem)
15+
private var isSingleListItem
16+
1117
let notification: CENotification
1218
let namespace: Namespace.ID
1319
let onDismiss: () -> Void
1420
let onAction: () -> Void
1521

16-
@Environment(\.isOverlay) private var isOverlay
17-
@Environment(\.isSingleListItem) private var isSingleListItem
1822
@State private var offset: CGFloat = 0
1923
@State private var opacity: CGFloat = 1
2024
@State private var isHovering = false
21-
25+
2226
private let dismissThreshold: CGFloat = 100
2327

2428
private var cornerRadius: CGFloat {
@@ -33,23 +37,30 @@ struct NotificationBannerView: View {
3337
VStack(spacing: 10) {
3438
HStack(alignment: .top, spacing: 10) {
3539
switch notification.icon {
36-
case .symbol(let name, let color):
40+
case let .symbol(name, color):
3741
FeatureIcon(
3842
symbol: name,
3943
color: color ?? Color(.systemBlue),
4044
size: 26
4145
)
42-
case .image(let image):
46+
case let .text(text, backgroundColor, textColor):
47+
FeatureIcon(
48+
text: text,
49+
textColor: textColor ?? .primary,
50+
color: backgroundColor ?? Color(.systemBlue),
51+
size: 26
52+
)
53+
case let .image(image):
4354
FeatureIcon(
4455
image: image,
4556
size: 26
4657
)
4758
}
4859
VStack(alignment: .leading, spacing: 1) {
4960
Text(notification.title)
50-
.font(.headline)
51-
.fontWeight(.medium)
52-
.padding(.top, -2)
61+
.font(.system(size: 12))
62+
.fontWeight(.semibold)
63+
.padding(.top, -3)
5364
Text(notification.description)
5465
.font(.callout)
5566
.foregroundColor(.secondary)
@@ -97,7 +108,7 @@ struct NotificationBannerView: View {
97108
}
98109
.onEnded { value in
99110
let velocity = value.predictedEndLocation.x - value.location.x
100-
111+
101112
if offset > dismissThreshold || velocity > 100 {
102113
withAnimation(.easeOut(duration: 0.2)) {
103114
offset = NSScreen.main?.frame.width ?? 1000

CodeEdit/Features/Notifications/Views/NotificationOverlayView.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88
import SwiftUI
99

1010
struct NotificationOverlayView: View {
11+
@Environment(\.controlActiveState)
12+
private var controlActiveState
13+
1114
@ObservedObject private var notificationManager = NotificationManager.shared
15+
1216
@Namespace private var animation
13-
@Environment(\.controlActiveState) private var controlActiveState
1417

1518
var body: some View {
1619
VStack(spacing: 10) {

0 commit comments

Comments
 (0)