Version 1 in App Store
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
//
|
||||
// MAThemeManager.swift
|
||||
// Mobile Music Assistant
|
||||
//
|
||||
// Created by Sven Hanold on 26.03.26.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
@Observable
|
||||
class MAThemeManager {
|
||||
var colorScheme: AppColorScheme {
|
||||
didSet {
|
||||
UserDefaults.standard.set(colorScheme.rawValue, forKey: "appColorScheme")
|
||||
}
|
||||
}
|
||||
|
||||
init() {
|
||||
let savedValue = UserDefaults.standard.string(forKey: "appColorScheme") ?? "system"
|
||||
colorScheme = AppColorScheme(rawValue: savedValue) ?? .system
|
||||
}
|
||||
|
||||
var preferredColorScheme: ColorScheme? {
|
||||
switch colorScheme {
|
||||
case .system:
|
||||
return nil
|
||||
case .light:
|
||||
return .light
|
||||
case .dark:
|
||||
return .dark
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum AppColorScheme: String, CaseIterable, Identifiable {
|
||||
case system = "system"
|
||||
case light = "light"
|
||||
case dark = "dark"
|
||||
|
||||
var id: String { rawValue }
|
||||
|
||||
var displayName: String {
|
||||
switch self {
|
||||
case .system:
|
||||
return "System"
|
||||
case .light:
|
||||
return "Light"
|
||||
case .dark:
|
||||
return "Dark"
|
||||
}
|
||||
}
|
||||
|
||||
var icon: String {
|
||||
switch self {
|
||||
case .system:
|
||||
return "circle.lefthalf.filled"
|
||||
case .light:
|
||||
return "sun.max.fill"
|
||||
case .dark:
|
||||
return "moon.fill"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Environment Key
|
||||
|
||||
private struct ThemeManagerKey: EnvironmentKey {
|
||||
static let defaultValue = MAThemeManager()
|
||||
}
|
||||
|
||||
extension EnvironmentValues {
|
||||
var themeManager: MAThemeManager {
|
||||
get { self[ThemeManagerKey.self] }
|
||||
set { self[ThemeManagerKey.self] = newValue }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user