Skip to content

Commit f87b417

Browse files
committed
Refactored FeatureIcon and notifications to support custom images
1 parent c9b32d7 commit f87b417

6 files changed

Lines changed: 59 additions & 16 deletions

File tree

CodeEdit/AppDelegate.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ final class AppDelegate: NSObject, NSApplicationDelegate, ObservableObject {
2525
checkForFilesToOpen()
2626

2727
NSApp.closeWindow(.welcome, .about)
28-
28+
2929
// Add test notification
3030
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
3131
NotificationManager.shared.post(
32-
icon: "bell.badge",
32+
iconSymbol: "bell.badge",
3333
title: "Welcome to CodeEdit",
3434
description: "This is a test notification to demonstrate the notification system.",
3535
actionButtonTitle: "Learn More",
@@ -38,10 +38,10 @@ final class AppDelegate: NSObject, NSApplicationDelegate, ObservableObject {
3838
}
3939
)
4040
}
41-
41+
4242
DispatchQueue.main.async {
4343
var needToHandleOpen = true
44-
44+
4545
// If no windows were reopened by NSQuitAlwaysKeepsWindows, do default behavior.
4646
// Non-WindowGroup SwiftUI Windows are still in NSApp.windows when they are closed,
4747
// So we need to think about those.
@@ -73,13 +73,13 @@ final class AppDelegate: NSObject, NSApplicationDelegate, ObservableObject {
7373
}
7474

7575
func applicationWillTerminate(_ aNotification: Notification) {
76-
76+
7777
}
78-
78+
7979
func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
8080
true
8181
}
82-
82+
8383
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
8484
guard flag else {
8585
handleOpen()
@@ -92,11 +92,11 @@ final class AppDelegate: NSObject, NSApplicationDelegate, ObservableObject {
9292
sender.windows.first(where: { $0.isMiniaturized })?.deminiaturize(sender)
9393
return false
9494
}
95-
95+
9696
func applicationShouldOpenUntitledFile(_ sender: NSApplication) -> Bool {
9797
false
9898
}
99-
99+
100100
func handleOpen() {
101101
let behavior = Settings.shared.preferences.general.reopenBehavior
102102
switch behavior {
@@ -110,15 +110,15 @@ final class AppDelegate: NSObject, NSApplicationDelegate, ObservableObject {
110110
CodeEditDocumentController.shared.newDocument(self)
111111
}
112112
}
113-
113+
114114
/// Handle urls with the form `codeedit://file/{filepath}:{line}:{column}`
115115
func application(_ application: NSApplication, open urls: [URL]) {
116116
for url in urls {
117117
let file = URL(fileURLWithPath: url.path).path.split(separator: ":")
118118
let filePath = URL(fileURLWithPath: String(file[0]))
119119
let line = file.count > 1 ? Int(file[1]) ?? 0 : 0
120120
let column = file.count > 2 ? Int(file[2]) ?? 1 : 1
121-
121+
122122
CodeEditDocumentController.shared
123123
.openDocument(withContentsOf: filePath, display: true) { document, _, error in
124124
if let error {
@@ -133,7 +133,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, ObservableObject {
133133
// Add notification when workspace is opened via URL
134134
if let workspaceDoc = document as? WorkspaceDocument {
135135
NotificationManager.shared.post(
136-
icon: "folder.badge.plus",
136+
iconSymbol: "folder.badge.plus",
137137
title: "Workspace Opened",
138138
description: "Successfully opened workspace: \(workspaceDoc.fileURL?.lastPathComponent ?? "")",
139139
actionButtonTitle: "View Files",
@@ -146,7 +146,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, ObservableObject {
146146
}
147147
}
148148
}
149-
149+
150150
/// Defers the application terminate message until we've finished cleanup.
151151
///
152152
/// All paths _must_ call `NSApplication.shared.reply(toApplicationShouldTerminate: true)` as soon as possible.

CodeEdit/Features/InspectorArea/FileInspector/FileInspectorView.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ struct FileInspectorView: View {
9191

9292
func addTestNotification () {
9393
NotificationManager.shared.post(
94-
icon: "bell",
94+
iconSymbol: "bell",
95+
iconColor: .red,
9596
title: "New Notification Created",
9697
description: "Successfully created new notification",
9798
actionButtonTitle: "Action",
@@ -100,7 +101,7 @@ struct FileInspectorView: View {
100101
}
101102
)
102103
}
103-
104+
104105
func addTestNotificationAfterDelay () {
105106
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
106107
addTestNotification()

CodeEdit/Features/Notifications/Models/CENotification.swift

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,28 @@ struct CENotification: Identifiable, Equatable {
106106
isRead: Bool
107107
) {
108108
self.id = id
109-
self.icon = icon
109+
self.icon = .symbol(name: iconSymbol, color: iconColor)
110+
self.title = title
111+
self.description = description
112+
self.actionButtonTitle = actionButtonTitle
113+
self.action = action
114+
self.isSticky = isSticky
115+
self.isRead = isRead
116+
self.timestamp = Date()
117+
}
118+
119+
init(
120+
id: UUID = UUID(),
121+
iconImage: Image,
122+
title: String,
123+
description: String,
124+
actionButtonTitle: String,
125+
action: @escaping () -> Void,
126+
isSticky: Bool = false,
127+
isRead: Bool = false
128+
) {
129+
self.id = id
130+
self.icon = .image(iconImage)
110131
self.title = title
111132
self.description = description
112133
self.actionButtonTitle = actionButtonTitle

CodeEdit/Features/Notifications/Views/NotificationBannerEnvironment.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
//
2+
// NotificationBannerEnvironment.swift
3+
// CodeEdit
4+
//
5+
// Created by Austin Condiff on 2/10/24.
6+
//
7+
18
import SwiftUI
29

310
struct IsOverlayKey: EnvironmentKey {

CodeEdit/Features/Notifications/Views/NotificationListView.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
//
2+
// NotificationListView.swift
3+
// CodeEdit
4+
//
5+
// Created by Austin Condiff on 2/10/24.
6+
//
7+
18
import SwiftUI
29

310
struct NotificationListView: View {

CodeEdit/Features/Notifications/Views/NotificationOverlayView.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
//
2+
// NotificationOverlayView.swift
3+
// CodeEdit
4+
//
5+
// Created by Austin Condiff on 2/10/24.
6+
//
7+
18
import SwiftUI
29

310
struct NotificationOverlayView: View {

0 commit comments

Comments
 (0)