From 440157ca4435a0f9d6f486343718892bf810cdb7 Mon Sep 17 00:00:00 2001 From: Lukas Pistrol Date: Thu, 26 Sep 2024 15:13:27 +0200 Subject: [PATCH] fix crash of app in macOS 15 --- .../Extensions/Color+RawRepresentable.swift | 2 +- .../BackupState/Internal/_InProgressState.swift | 13 ++++++++----- .../Model/BackupState/Internal/_State.swift | 3 ++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/TimeMachineStatus/Extensions/Color+RawRepresentable.swift b/TimeMachineStatus/Extensions/Color+RawRepresentable.swift index cb98b3e..6501a29 100644 --- a/TimeMachineStatus/Extensions/Color+RawRepresentable.swift +++ b/TimeMachineStatus/Extensions/Color+RawRepresentable.swift @@ -11,7 +11,7 @@ import SwiftUI -extension Color: RawRepresentable { +extension Color: @retroactive RawRepresentable { public init?(rawValue: String) { guard let data = Data(base64Encoded: rawValue) else { self = .black diff --git a/TimeMachineStatus/Model/BackupState/Internal/_InProgressState.swift b/TimeMachineStatus/Model/BackupState/Internal/_InProgressState.swift index c443e91..7b0d05f 100644 --- a/TimeMachineStatus/Model/BackupState/Internal/_InProgressState.swift +++ b/TimeMachineStatus/Model/BackupState/Internal/_InProgressState.swift @@ -20,17 +20,20 @@ extension BackupState { required init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) - let stateChangeString = try container.decode(String.self, forKey: .stateChange) - self.stateChange = if let date = _dateFormatter.date(from: stateChangeString) { - date + if let stateChangeString = try container.decodeIfPresent(String.self, forKey: .stateChange) { + self.stateChange = if let date = _dateFormatter.date(from: stateChangeString) { + date + } else { + throw BackupStateError.couldNotConvertStringToDate(string: stateChangeString) + } } else { - throw BackupStateError.couldNotConvertStringToDate(string: stateChangeString) + self.stateChange = nil } self.destinationMountPoint = try container.decode(String.self, forKey: .destinationMountPoint) try super.init(from: decoder) } - let stateChange: Date + let stateChange: Date? let destinationMountPoint: String } } diff --git a/TimeMachineStatus/Model/BackupState/Internal/_State.swift b/TimeMachineStatus/Model/BackupState/Internal/_State.swift index b25504d..01de7e5 100644 --- a/TimeMachineStatus/Model/BackupState/Internal/_State.swift +++ b/TimeMachineStatus/Model/BackupState/Internal/_State.swift @@ -65,9 +65,10 @@ extension BackupState { return ._finishing case "Stopping": return ._stopping - case "ThinningPostBackup": + case "ThinningPostBackup", "LazyThinning": return ._thinning default: + log.error("Unknown phase: \(phase)") fatalError("Unknown phase: \(phase)") } } else {