Skip to content

Commit

Permalink
Add light logo config and dynamic logo loading
Browse files Browse the repository at this point in the history
  • Loading branch information
almenscorner committed Dec 5, 2024
1 parent 17edf5e commit 5b19005
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
22 changes: 18 additions & 4 deletions SupportCompanion/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ struct ContentView: View {
@State private var showLogo: Bool = false
@State private var isShowingPopup = false
@State private var modalButtonHovered: Bool = false
@Environment(\.colorScheme) var colorScheme

var body: some View {
let sidebarItems = generateSidebarItems(preferences: appState.preferences, stateManager: webViewStateManager)
let base64Logo: String = appState.preferences.brandLogo

NavigationSplitView {
VStack(spacing: 10) {
Expand All @@ -33,15 +33,15 @@ struct ContentView: View {
.resizable()
.scaledToFit()
.padding(.top, 20) // Minimal padding
.padding(.horizontal)
.padding(.horizontal, 20)
}

// Title Section
if !appState.preferences.brandName.isEmpty {
Text(appState.preferences.brandName)
.font(.title)
.multilineTextAlignment(.center)
.padding(.top, 5) // Bring the title closer to the logo
.padding(.top, 20) // Bring the title closer to the logo
}

Spacer() // Push content to the center dynamically
Expand All @@ -52,11 +52,20 @@ struct ContentView: View {
}
.listStyle(SidebarListStyle())
.onAppear {
loadLogo(base64Logo: base64Logo)
loadLogoForCurrentColorScheme()
if selectedItem == nil {
selectedItem = sidebarItems.first
}
}
.onChange(of: colorScheme) { _, _ in
loadLogoForCurrentColorScheme()
}
.onChange(of: appState.preferences.brandLogo) { _, _ in
loadLogoForCurrentColorScheme()
}
.onChange(of: appState.preferences.brandLogoLight) { _, _ in
loadLogoForCurrentColorScheme()
}
.onReceive(NotificationCenter.default.publisher(for: .handleIncomingURL)) { notification in
if let url = notification.object as? URL {
handleIncomingURL(url, items: sidebarItems)
Expand Down Expand Up @@ -140,6 +149,11 @@ struct ContentView: View {
}
}

private func loadLogoForCurrentColorScheme() {
let base64Logo = colorScheme == .dark ? appState.preferences.brandLogo : appState.preferences.brandLogoLight.isEmpty ? appState.preferences.brandLogo : appState.preferences.brandLogoLight
loadLogo(base64Logo: base64Logo)
}

private func loadLogo(base64Logo: String) {
if base64Logo.isEmpty {
showLogo = false
Expand Down
2 changes: 2 additions & 0 deletions SupportCompanion/Preferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class Preferences: ObservableObject {

@AppStorage("BrandLogo") var brandLogo: String = ""

@AppStorage("BrandLogoLight") var brandLogoLight: String = ""

@AppStorage("AccentColor") var accentColor: String?

// MARK: - Menu
Expand Down

0 comments on commit 5b19005

Please sign in to comment.