Skip to content

Commit 9887762

Browse files
committed
"feat: Implement color scheme changes in GitMacApp and related views"
1 parent 99b5d74 commit 9887762

4 files changed

Lines changed: 116 additions & 43 deletions

File tree

GitMac/App/GitMacApp.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ struct GitMacApp: App {
8686
Settings {
8787
SettingsView()
8888
.environmentObject(appState)
89+
.environmentObject(themeManager)
8990
}
9091
}
9192
}

GitMac/App/Welcome/WelcomeView.swift

Lines changed: 107 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,38 @@ struct WelcomeView: View {
125125
@EnvironmentObject var recentReposManager: RecentRepositoriesManager
126126
@EnvironmentObject var appState: AppState
127127
@EnvironmentObject var themeManager: ThemeManager
128+
@Environment(\.colorScheme) private var colorScheme
128129
@State private var refreshTrigger = UUID()
129130

131+
// Computed colors that respond to theme changes
132+
private var backgroundColor: Color {
133+
colorScheme == .dark ? Color(hex: "#1E1E1E") : Color(hex: "#FFFFFF")
134+
}
135+
136+
private var backgroundSecondaryColor: Color {
137+
colorScheme == .dark ? Color(hex: "#252526") : Color(hex: "#F5F5F7")
138+
}
139+
140+
private var textPrimaryColor: Color {
141+
colorScheme == .dark ? Color.white : Color(hex: "#1D1D1F")
142+
}
143+
144+
private var textSecondaryColor: Color {
145+
colorScheme == .dark ? Color(hex: "#CCCCCC") : Color(hex: "#48484A")
146+
}
147+
148+
private var textMutedColor: Color {
149+
colorScheme == .dark ? Color(hex: "#999999") : Color(hex: "#6E6E73")
150+
}
151+
152+
private var accentColor: Color {
153+
Color.accentColor
154+
}
155+
156+
private var successColor: Color {
157+
Color(nsColor: .systemGreen)
158+
}
159+
130160
var body: some View {
131161
HStack(spacing: 0) {
132162
// Left side - Actions
@@ -138,65 +168,86 @@ struct WelcomeView: View {
138168

139169
Text("GitMac")
140170
.font(.system(size: 36, weight: .bold))
141-
.foregroundColor(AppTheme.textPrimary)
171+
.foregroundColor(textPrimaryColor)
142172

143173
Text("A Git client for Mac")
144174
.font(.system(size: 16))
145-
.foregroundColor(AppTheme.textSecondary)
175+
.foregroundColor(textSecondaryColor)
146176

147177
HStack(spacing: 16) {
148-
WelcomeButton(icon: "folder", title: "Open", color: AppTheme.accent, action: onOpen)
149-
WelcomeButton(icon: "arrow.down.circle", title: "Clone", color: AppTheme.success, action: onClone)
150-
WelcomeButton(icon: "plus.circle", title: "Init", color: AppTheme.accent) {
178+
WelcomeButton(icon: "folder", title: "Open", color: accentColor, action: onOpen)
179+
WelcomeButton(icon: "arrow.down.circle", title: "Clone", color: successColor, action: onClone)
180+
WelcomeButton(icon: "plus.circle", title: "Init", color: accentColor) {
151181
NotificationCenter.default.post(name: .initRepository, object: nil)
152182
}
153183
}
154184

155185
Spacer()
156186
}
157187
.frame(maxWidth: .infinity)
158-
.background(AppTheme.background)
188+
.background(backgroundColor)
159189

160190
// Right side - Recent repos
161-
VStack(alignment: .leading, spacing: 0) {
162-
Text("RECENT REPOSITORIES")
163-
.font(.system(size: 11, weight: .semibold))
164-
.foregroundColor(AppTheme.textMuted)
165-
.padding(.horizontal, 20)
166-
.padding(.top, 20)
167-
.padding(.bottom, 12)
168-
169-
ScrollView {
170-
VStack(spacing: 0) {
171-
if recentReposManager.recentRepos.isEmpty {
172-
VStack(spacing: 12) {
173-
Image(systemName: "clock")
174-
.font(.system(size: 32))
175-
.foregroundColor(AppTheme.textMuted)
176-
Text("No recent repositories")
177-
.foregroundColor(AppTheme.textMuted)
178-
}
179-
.frame(maxWidth: .infinity)
180-
.padding(.top, 60)
181-
} else {
182-
ForEach(recentReposManager.recentRepos) { repo in
183-
RecentRepoRow(repo: repo)
184-
}
185-
}
186-
}
187-
}
188-
}
189-
.frame(width: 320)
190-
.background(AppTheme.backgroundSecondary)
191+
RecentReposSidebar(
192+
recentRepos: recentReposManager.recentRepos,
193+
backgroundColor: backgroundSecondaryColor,
194+
textMutedColor: textMutedColor
195+
)
191196
}
192-
// Force re-render when theme changes via multiple triggers
193-
.id("\(themeManager.currentTheme.rawValue)-\(refreshTrigger)")
197+
// Force re-render when theme changes
198+
.id("\(themeManager.currentTheme.rawValue)-\(colorScheme)-\(refreshTrigger)")
194199
.onReceive(NotificationCenter.default.publisher(for: .themeDidChange)) { _ in
195-
// Force view refresh when theme changes
196200
refreshTrigger = UUID()
197201
}
198202
.preferredColorScheme(themeManager.currentTheme == .light ? .light :
199203
themeManager.currentTheme == .dark ? .dark : nil)
204+
.onAppear {
205+
// Ensure window appearance matches theme on appear
206+
if let window = NSApplication.shared.windows.first(where: { $0.isKeyWindow }) {
207+
window.appearance = themeManager.appearance
208+
}
209+
}
210+
}
211+
}
212+
213+
// MARK: - Recent Repos Sidebar
214+
215+
struct RecentReposSidebar: View {
216+
let recentRepos: [RecentRepository]
217+
let backgroundColor: Color
218+
let textMutedColor: Color
219+
220+
var body: some View {
221+
VStack(alignment: .leading, spacing: 0) {
222+
Text("RECENT REPOSITORIES")
223+
.font(.system(size: 11, weight: .semibold))
224+
.foregroundColor(textMutedColor)
225+
.padding(.horizontal, 20)
226+
.padding(.top, 20)
227+
.padding(.bottom, 12)
228+
229+
ScrollView {
230+
VStack(spacing: 0) {
231+
if recentRepos.isEmpty {
232+
VStack(spacing: 12) {
233+
Image(systemName: "clock")
234+
.font(.system(size: 32))
235+
.foregroundColor(textMutedColor)
236+
Text("No recent repositories")
237+
.foregroundColor(textMutedColor)
238+
}
239+
.frame(maxWidth: .infinity)
240+
.padding(.top, 60)
241+
} else {
242+
ForEach(recentRepos) { repo in
243+
RecentRepoRow(repo: repo)
244+
}
245+
}
246+
}
247+
}
248+
}
249+
.frame(width: 320)
250+
.background(backgroundColor)
200251
}
201252
}
202253

@@ -233,8 +284,21 @@ struct RecentRepoRow: View {
233284
let repo: RecentRepository
234285
@EnvironmentObject var appState: AppState
235286
@EnvironmentObject var recentReposManager: RecentRepositoriesManager
287+
@Environment(\.colorScheme) private var colorScheme
236288
@State private var isHovered = false
237289

290+
private var textPrimaryColor: Color {
291+
colorScheme == .dark ? Color.white : Color(hex: "#1D1D1F")
292+
}
293+
294+
private var textMutedColor: Color {
295+
colorScheme == .dark ? Color(hex: "#999999") : Color(hex: "#6E6E73")
296+
}
297+
298+
private var hoverColor: Color {
299+
Color.accentColor.opacity(0.1)
300+
}
301+
238302
var body: some View {
239303
Button {
240304
Task {
@@ -244,15 +308,15 @@ struct RecentRepoRow: View {
244308
HStack(spacing: 12) {
245309
Image(systemName: "folder.fill")
246310
.font(.system(size: 20))
247-
.foregroundColor(AppTheme.accent)
311+
.foregroundColor(Color.accentColor)
248312

249313
VStack(alignment: .leading, spacing: 2) {
250314
Text(repo.name)
251315
.font(.system(size: 13, weight: .medium))
252-
.foregroundColor(AppTheme.textPrimary)
316+
.foregroundColor(textPrimaryColor)
253317
Text(repo.path)
254318
.font(.system(size: 11))
255-
.foregroundColor(AppTheme.textMuted)
319+
.foregroundColor(textMutedColor)
256320
.lineLimit(1)
257321
.truncationMode(.middle)
258322
}
@@ -261,7 +325,7 @@ struct RecentRepoRow: View {
261325
}
262326
.padding(.horizontal, 20)
263327
.padding(.vertical, 10)
264-
.background(isHovered ? AppTheme.hover : Color.clear)
328+
.background(isHovered ? hoverColor : Color.clear)
265329
}
266330
.buttonStyle(.plain)
267331
.onHover { isHovered = $0 }

GitMac/Features/Branches/BranchListView.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,10 @@ struct CreatePullRequestSheet: View {
10991099
detail: title
11001100
)
11011101

1102+
// Post notification to refresh PR data across the app
1103+
NotificationCenter.default.post(name: .pullRequestCreated, object: newPR)
1104+
NotificationCenter.default.post(name: .repositoryDidRefresh, object: repo.path)
1105+
11021106
dismiss()
11031107
} catch {
11041108
NotificationManager.shared.error(
@@ -1215,4 +1219,5 @@ struct CreatePullRequestSheet: View {
12151219

12161220
extension Notification.Name {
12171221
static let renameBranch = Notification.Name("renameBranch")
1222+
static let pullRequestCreated = Notification.Name("pullRequestCreated")
12181223
}

GitMac/Features/PullRequests/PRListView.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ struct PRListView: View {
101101
await viewModel.loadPullRequests(state: filterState)
102102
}
103103
}
104+
.onReceive(NotificationCenter.default.publisher(for: .pullRequestCreated)) { _ in
105+
Task { await viewModel.loadPullRequests(state: filterState) }
106+
}
104107
}
105108
}
106109

0 commit comments

Comments
 (0)