Skip to content

Commit abced05

Browse files
Global Notification System (#1984)
1 parent aac7aa1 commit abced05

37 files changed

+1676
-252
lines changed

CodeEdit.xcodeproj/project.pbxproj

Lines changed: 100 additions & 8 deletions
Large diffs are not rendered by default.

CodeEdit/Features/About/Views/BlurButtonStyle.swift

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,18 @@ import SwiftUI
99

1010
extension ButtonStyle where Self == BlurButtonStyle {
1111
static var blur: BlurButtonStyle { BlurButtonStyle() }
12+
static var secondaryBlur: BlurButtonStyle { BlurButtonStyle(isSecondary: true) }
1213
}
1314

1415
struct BlurButtonStyle: ButtonStyle {
16+
var isSecondary: Bool = false
17+
1518
@Environment(\.controlSize)
1619
var controlSize
1720

21+
@Environment(\.colorScheme)
22+
var colorScheme
23+
1824
var height: CGFloat {
1925
switch controlSize {
2026
case .large:
@@ -24,32 +30,40 @@ struct BlurButtonStyle: ButtonStyle {
2430
}
2531
}
2632

27-
@Environment(\.colorScheme)
28-
var colorScheme
29-
3033
func makeBody(configuration: Configuration) -> some View {
3134
configuration.label
35+
.padding(.horizontal, 8)
3236
.frame(height: height)
33-
.buttonStyle(.bordered)
3437
.background {
3538
switch colorScheme {
3639
case .dark:
37-
Color
38-
.gray
39-
.opacity(0.001)
40-
.overlay(.regularMaterial.blendMode(.plusLighter))
41-
.overlay(Color.gray.opacity(0.30))
42-
.overlay(Color.white.opacity(configuration.isPressed ? 0.20 : 0.00))
40+
ZStack {
41+
Color.gray.opacity(0.001)
42+
if isSecondary {
43+
Rectangle()
44+
.fill(.regularMaterial)
45+
} else {
46+
Rectangle()
47+
.fill(.regularMaterial)
48+
.blendMode(.plusLighter)
49+
}
50+
Color.gray.opacity(isSecondary ? 0.10 : 0.30)
51+
Color.white.opacity(configuration.isPressed ? 0.10 : 0.00)
52+
}
4353
case .light:
44-
Color
45-
.gray
46-
.opacity(0.001)
47-
.overlay(.regularMaterial.blendMode(.darken))
48-
.overlay(Color.gray.opacity(0.15).blendMode(.plusDarker))
54+
ZStack {
55+
Color.gray.opacity(0.001)
56+
Rectangle()
57+
.fill(.regularMaterial)
58+
.blendMode(.darken)
59+
Color.gray.opacity(isSecondary ? 0.05 : 0.15)
60+
.blendMode(.plusDarker)
61+
Color.gray.opacity(configuration.isPressed ? 0.10 : 0.00)
62+
}
4963
@unknown default:
5064
Color.black
5165
}
5266
}
53-
.clipShape(RoundedRectangle(cornerRadius: 6))
67+
.clipShape(RoundedRectangle(cornerRadius: controlSize == .large ? 6 : 5))
5468
}
5569
}

CodeEdit/Features/ActivityViewer/Notifications/TaskNotificationHandler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ import Combine
7676
/// "id": "uniqueTaskID",
7777
/// "action": "update",
7878
/// "title": "Updated Task Title",
79-
/// "message": "Updated Task Message"
79+
/// "message": "Updated Task Message",
8080
/// "percentage": 0.5,
8181
/// "isLoading": true
8282
/// ]
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import SwiftUI
2+
3+
/// A button style for overlay buttons (like close, action buttons in notifications)
4+
struct OverlayButtonStyle: ButtonStyle {
5+
@Environment(\.colorScheme)
6+
private var colorScheme
7+
8+
func makeBody(configuration: Configuration) -> some View {
9+
configuration.label
10+
.font(.system(size: 10))
11+
.foregroundColor(.secondary)
12+
.frame(width: 20, height: 20, alignment: .center)
13+
.background(Color.primary.opacity(configuration.isPressed ? colorScheme == .dark ? 0.10 : 0.05 : 0.00))
14+
.background(.regularMaterial)
15+
.overlay(
16+
RoundedRectangle(cornerRadius: 10)
17+
.stroke(Color(nsColor: .separatorColor), lineWidth: 2)
18+
)
19+
.cornerRadius(10)
20+
.shadow(
21+
color: Color(.black.withAlphaComponent(colorScheme == .dark ? 0.2 : 0.1)),
22+
radius: 5,
23+
x: 0,
24+
y: 2
25+
)
26+
}
27+
}
28+
29+
extension ButtonStyle where Self == OverlayButtonStyle {
30+
/// A button style for overlay buttons
31+
static var overlay: OverlayButtonStyle {
32+
OverlayButtonStyle()
33+
}
34+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
//
2+
// FeatureIcon.swift
3+
// CodeEdit
4+
//
5+
// Created by Austin Condiff on 12/2/24.
6+
//
7+
8+
import SwiftUI
9+
import CodeEditSymbols
10+
11+
struct FeatureIcon: View {
12+
private let content: IconContent
13+
private let color: Color?
14+
private let size: CGFloat
15+
16+
init(
17+
symbol: String,
18+
color: Color? = nil,
19+
size: CGFloat? = nil
20+
) {
21+
self.content = .symbol(symbol)
22+
self.color = color ?? .accentColor
23+
self.size = size ?? 20
24+
}
25+
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+
37+
init(
38+
image: Image,
39+
size: CGFloat? = nil
40+
) {
41+
self.content = .image(image)
42+
self.color = nil
43+
self.size = size ?? 20
44+
}
45+
46+
private func getSafeImage(named: String) -> Image {
47+
if NSImage(systemSymbolName: named, accessibilityDescription: nil) != nil {
48+
return Image(systemName: named)
49+
} else {
50+
return Image(symbol: named)
51+
}
52+
}
53+
54+
var body: some View {
55+
RoundedRectangle(cornerRadius: size / 4, style: .continuous)
56+
.fill(background)
57+
.overlay {
58+
switch content {
59+
case let .symbol(name):
60+
getSafeImage(named: name)
61+
.resizable()
62+
.aspectRatio(contentMode: .fit)
63+
.foregroundColor(.white)
64+
.padding(size / 8)
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):
70+
image
71+
.resizable()
72+
.aspectRatio(contentMode: .fill)
73+
}
74+
}
75+
.clipShape(RoundedRectangle(cornerRadius: size / 4, style: .continuous))
76+
.shadow(
77+
color: Color(NSColor.black).opacity(0.25),
78+
radius: size / 40,
79+
y: size / 40
80+
)
81+
.frame(width: size, height: size)
82+
}
83+
84+
private var background: AnyShapeStyle {
85+
switch content {
86+
case .symbol, .text:
87+
return AnyShapeStyle((color ?? .accentColor).gradient)
88+
case .image:
89+
return AnyShapeStyle(.regularMaterial)
90+
}
91+
}
92+
}
93+
94+
private enum IconContent {
95+
case symbol(String)
96+
case text(String, textColor: Color?)
97+
case image(Image)
98+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import SwiftUI
2+
3+
/// Tracks scroll offset in scrollable views
4+
struct ScrollOffsetPreferenceKey: PreferenceKey {
5+
typealias Value = CGFloat
6+
static var defaultValue = CGFloat.zero
7+
static func reduce(value: inout Value, nextValue: () -> Value) {
8+
value += nextValue()
9+
}
10+
}

CodeEdit/Features/CodeEditUI/Views/SegmentedControlImproved.swift

Lines changed: 0 additions & 145 deletions
This file was deleted.

0 commit comments

Comments
 (0)