save changed images

This commit is contained in:
leminlimez committed 2025-06-23 14:25:54 -04:00
1 parent 7c2a031463
commit d5833dfb81
5 files changed
+36 -19

No files matched your search

@@ -103,6 +103,7 @@ struct CarPlayView: View {
// load active wallpapers from user defaults
activeWallpapers = UserDefaults.standard.array(forKey: "ActiveCarPlayWallpapers") as? [String] ?? []
// load the wallpapers
let cppURL = PosterBoardManager.shared.getCarPlayPhotosURL()
let frameworkPath = "/System/Library/PrivateFrameworks/CarPlayUIServices.framework"
do {
for file in try FileManager.default.contentsOfDirectory(at: URL(fileURLWithPath: frameworkPath), includingPropertiesForKeys: nil, options: .skipsHiddenFiles) {
@@ -114,7 +115,14 @@ struct CarPlayView: View {
darkImg = UIImage(data: darkData) ?? wpImg
}
let name = file.lastPathComponent.replacingOccurrences(of: "-Light.heic", with: "")
wallpapers.append(.init(name: name, lightImage: wpImg, darkImage: darkImg, changed: false))
// fetch the selected image if they exist
let selectedLight: Data? = try? Data(contentsOf: cppURL.appendingPathComponent("\(name)-Light"))
let selectedDark: Data? = try? Data(contentsOf: cppURL.appendingPathComponent("\(name)-Dark"))
wallpapers.append(.init(
name: name,
lightImage: wpImg, darkImage: darkImg,
selectedImageDataLight: selectedLight, selectedImageDataDark: selectedDark
))
}
}
}
+1
View File
@@ -84,6 +84,7 @@ struct SettingsView: View {
Button(action: {
UIImpactFeedbackGenerator(style: .soft).impactOccurred()
UserDefaults.standard.set(nil, forKey: "ActiveCarPlayWallpapers")
try? FileManager.default.removeItem(at: PosterBoardManager.shared.getCarPlayPhotosURL())
Haptic.shared.notify(.success)
UIApplication.shared.alert(title: NSLocalizedString("CarPlay Applied Wallpapers Successfully Cleared!", comment: ""), body: "")
}) {