Refactoring

This commit is contained in:
Federico Imberti 2026-01-02 09:49:55 +01:00
commit 2e5be4d4c6

View file

@ -466,7 +466,7 @@ extension FocusModeType {
func getCustomAccentColorFromFile() -> Color { func getCustomAccentColorFromFile() -> Color {
return FocusMetadataReader.shared return FocusMetadataReader.shared
.getColor(for: DoNotDisturbManager.shared.currentFocusModeName) .getAccentColor(for: DoNotDisturbManager.shared.currentFocusModeName)
} }
} }
@ -987,8 +987,6 @@ private final class FocusMetadataReader {
static let shared = FocusMetadataReader() static let shared = FocusMetadataReader()
private func getModeConfig(for focusName: String) -> DNDMode? { private func getModeConfig(for focusName: String) -> DNDMode? {
print(">>> Debug: Reading from \(pathToDatabase.path)")
do { do {
let data = try Data(contentsOf: pathToDatabase) let data = try Data(contentsOf: pathToDatabase)
let root = try JSONDecoder().decode(DNDConfigRoot.self, from: data) let root = try JSONDecoder().decode(DNDConfigRoot.self, from: data)
@ -996,25 +994,29 @@ private final class FocusMetadataReader {
for entry in root.data { for entry in root.data {
for wrapper in entry.modeConfigurations.values { for wrapper in entry.modeConfigurations.values {
if wrapper.mode.name if wrapper.mode.name
.localizedCaseInsensitiveContains(focusName){ .localizedCaseInsensitiveCompare(focusName) == .orderedSame {
return wrapper.mode return wrapper.mode
} }
} }
} }
} catch { } catch {
print(">>> JSON Error: \(error)") print("JSON Error: \(error)")
} }
return nil return nil
} }
/// Fetch the icon for the current focus from disk. If the focus is not found return the placeholder `app.badge`
/// - Returns A string representing the sfSymbol of the current focus
func getIcon(for focus: String) -> String { func getIcon(for focus: String) -> String {
guard let mode = getModeConfig(for: focus) else { return "app.badge" } guard let mode = getModeConfig(for: focus) else { return "app.badge" }
return mode.symbolImageName ?? "app.badge" return mode.symbolImageName ?? "app.badge"
} }
func getColor(for focus: String) -> Color { /// Fetch the accent color for the current focus from disk. If the focus is not found return the placeholder `Color.indigo`
/// - Returns A Color representing the accent color for the current focus
func getAccentColor(for focus: String) -> Color {
guard let mode = getModeConfig(for: focus), guard let mode = getModeConfig(for: focus),
let colorName = mode.tintColorName else { return .gray } let colorName = mode.tintColorName else { return .indigo }
return Color.stringToColor(for: colorName) return Color.stringToColor(for: colorName)
} }