Skip to content

Commit d3d26d1

Browse files
committed
Fix SwiftLint errors by splitting up NotificationManager
1 parent b91877e commit d3d26d1

File tree

4 files changed

+61
-57
lines changed

4 files changed

+61
-57
lines changed

CodeEdit.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,8 @@
558558
B65B10FE2B08B07D002852CF /* SourceControlNavigatorChangesList.swift in Sources */ = {isa = PBXBuildFile; fileRef = B65B10FD2B08B07D002852CF /* SourceControlNavigatorChangesList.swift */; };
559559
B65B11012B09D5D4002852CF /* GitClient+Pull.swift in Sources */ = {isa = PBXBuildFile; fileRef = B65B11002B09D5D4002852CF /* GitClient+Pull.swift */; };
560560
B65B11042B09DB1C002852CF /* GitClient+Fetch.swift in Sources */ = {isa = PBXBuildFile; fileRef = B65B11032B09DB1C002852CF /* GitClient+Fetch.swift */; };
561+
B66460592D600E9500EC1411 /* NotificationManager+Delegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B66460572D600E9500EC1411 /* NotificationManager+Delegate.swift */; };
562+
B664605A2D600E9500EC1411 /* NotificationManager+System.swift in Sources */ = {isa = PBXBuildFile; fileRef = B66460582D600E9500EC1411 /* NotificationManager+System.swift */; };
561563
B664C3B02B965F6C00816B4E /* NavigationSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = B664C3AF2B965F6C00816B4E /* NavigationSettings.swift */; };
562564
B664C3B32B96634F00816B4E /* NavigationSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B664C3B22B96634F00816B4E /* NavigationSettingsView.swift */; };
563565
B66A4E4529C8E86D004573B4 /* CommandsFixes.swift in Sources */ = {isa = PBXBuildFile; fileRef = B66A4E4429C8E86D004573B4 /* CommandsFixes.swift */; };
@@ -1253,6 +1255,8 @@
12531255
B65B10FD2B08B07D002852CF /* SourceControlNavigatorChangesList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SourceControlNavigatorChangesList.swift; sourceTree = "<group>"; };
12541256
B65B11002B09D5D4002852CF /* GitClient+Pull.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "GitClient+Pull.swift"; sourceTree = "<group>"; };
12551257
B65B11032B09DB1C002852CF /* GitClient+Fetch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "GitClient+Fetch.swift"; sourceTree = "<group>"; };
1258+
B66460572D600E9500EC1411 /* NotificationManager+Delegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NotificationManager+Delegate.swift"; sourceTree = "<group>"; };
1259+
B66460582D600E9500EC1411 /* NotificationManager+System.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NotificationManager+System.swift"; sourceTree = "<group>"; };
12561260
B664C3AF2B965F6C00816B4E /* NavigationSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationSettings.swift; sourceTree = "<group>"; };
12571261
B664C3B22B96634F00816B4E /* NavigationSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationSettingsView.swift; sourceTree = "<group>"; };
12581262
B66A4E4429C8E86D004573B4 /* CommandsFixes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CommandsFixes.swift; sourceTree = "<group>"; };
@@ -3583,6 +3587,8 @@
35833587
B68DE5D82D5A61E5009A43EF /* Models */,
35843588
B68DE5DC2D5A61E5009A43EF /* Views */,
35853589
B68DE5DD2D5A61E5009A43EF /* NotificationManager.swift */,
3590+
B66460572D600E9500EC1411 /* NotificationManager+Delegate.swift */,
3591+
B66460582D600E9500EC1411 /* NotificationManager+System.swift */,
35863592
);
35873593
path = Notifications;
35883594
sourceTree = "<group>";
@@ -4525,6 +4531,8 @@
45254531
B6A43C5D29FC4AF00027E0E0 /* CreateSSHKeyView.swift in Sources */,
45264532
B6EA200229DB7F81001BF195 /* View+ConstrainHeightToWindow.swift in Sources */,
45274533
66F370342BEE537B00D3B823 /* NonTextFileView.swift in Sources */,
4534+
B66460592D600E9500EC1411 /* NotificationManager+Delegate.swift in Sources */,
4535+
B664605A2D600E9500EC1411 /* NotificationManager+System.swift in Sources */,
45284536
613899B72B6E702F00A5CAF6 /* String+LengthOfMatchingPrefix.swift in Sources */,
45294537
6C48D8F42972DB1A00D6D205 /* Env+Window.swift in Sources */,
45304538
6C5FDF7A29E6160000BC08C0 /* AppSettings.swift in Sources */,
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import UserNotifications
2+
3+
extension NotificationManager: UNUserNotificationCenterDelegate {
4+
func userNotificationCenter(
5+
_ center: UNUserNotificationCenter,
6+
didReceive response: UNNotificationResponse,
7+
withCompletionHandler completionHandler: @escaping () -> Void
8+
) {
9+
if let id = response.notification.request.content.userInfo["id"] as? String {
10+
DispatchQueue.main.async {
11+
self.handleSystemNotificationResponse(id: id)
12+
}
13+
}
14+
completionHandler()
15+
}
16+
17+
func userNotificationCenter(
18+
_ center: UNUserNotificationCenter,
19+
willPresent notification: UNNotification,
20+
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
21+
) {
22+
// Don't show system notifications when app is active
23+
completionHandler([])
24+
}
25+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import SwiftUI
2+
3+
extension NotificationManager {
4+
/// Shows a notification in macOS Notification Center when app is in background
5+
func showSystemNotification(_ notification: CENotification) {
6+
let content = UNMutableNotificationContent()
7+
content.title = notification.title
8+
content.body = notification.description
9+
content.userInfo = ["id": notification.id.uuidString]
10+
11+
let request = UNNotificationRequest(
12+
identifier: notification.id.uuidString,
13+
content: content,
14+
trigger: nil
15+
)
16+
17+
UNUserNotificationCenter.current().add(request)
18+
}
19+
20+
/// Handles response from system notification
21+
func handleSystemNotificationResponse(id: String) {
22+
if let uuid = UUID(uuidString: id),
23+
let notification = notifications.first(where: { $0.id == uuid }) {
24+
notification.action()
25+
dismissNotification(notification)
26+
}
27+
}
28+
}

CodeEdit/Features/Notifications/NotificationManager.swift

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,6 @@ final class NotificationManager: NSObject, ObservableObject {
107107
notifications.filter { !$0.isRead }.count
108108
}
109109

110-
/// Whether there are currently notifications being displayed in the overlay
111-
var hasActiveNotification: Bool {
112-
!activeNotifications.isEmpty
113-
}
114-
115110
/// Posts a new notification
116111
/// - Parameters:
117112
/// - iconSymbol: SF Symbol or CodeEditSymbol name for the notification icon
@@ -230,22 +225,6 @@ final class NotificationManager: NSObject, ObservableObject {
230225
}
231226
}
232227

233-
/// Shows a notification in macOS Notification Center when app is in background
234-
private func showSystemNotification(_ notification: CENotification) {
235-
let content = UNMutableNotificationContent()
236-
content.title = notification.title
237-
content.body = notification.description
238-
content.userInfo = ["id": notification.id.uuidString]
239-
240-
let request = UNNotificationRequest(
241-
identifier: notification.id.uuidString,
242-
content: content,
243-
trigger: nil
244-
)
245-
246-
UNUserNotificationCenter.current().add(request)
247-
}
248-
249228
/// Shows a notification in the app's overlay UI
250229
private func showTemporaryNotification(_ notification: CENotification) {
251230
withAnimation(.easeInOut(duration: 0.3)) {
@@ -350,16 +329,6 @@ final class NotificationManager: NSObject, ObservableObject {
350329
}
351330
}
352331

353-
/// Handles response from system notification
354-
/// - Parameter id: ID of the notification that was interacted with
355-
func handleSystemNotificationResponse(id: String) {
356-
if let uuid = UUID(uuidString: id),
357-
let notification = notifications.first(where: { $0.id == uuid }) {
358-
notification.action()
359-
dismissNotification(notification)
360-
}
361-
}
362-
363332
/// Toggles visibility of notifications in the overlay
364333
func toggleNotificationsVisibility() {
365334
withAnimation(.easeInOut(duration: 0.3)) {
@@ -378,29 +347,3 @@ final class NotificationManager: NSObject, ObservableObject {
378347
}
379348
}
380349
}
381-
382-
// MARK: - UNUserNotificationCenterDelegate
383-
384-
extension NotificationManager: UNUserNotificationCenterDelegate {
385-
func userNotificationCenter(
386-
_ center: UNUserNotificationCenter,
387-
didReceive response: UNNotificationResponse,
388-
withCompletionHandler completionHandler: @escaping () -> Void
389-
) {
390-
if let id = response.notification.request.content.userInfo["id"] as? String {
391-
DispatchQueue.main.async {
392-
self.handleSystemNotificationResponse(id: id)
393-
}
394-
}
395-
completionHandler()
396-
}
397-
398-
func userNotificationCenter(
399-
_ center: UNUserNotificationCenter,
400-
willPresent notification: UNNotification,
401-
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
402-
) {
403-
// Don't show system notifications when app is active
404-
completionHandler([])
405-
}
406-
}

0 commit comments

Comments
 (0)