active wallpapers tracking

This commit is contained in:
leminlimez committed 2025-06-19 04:39:31 -04:00
1 parent 069d5cf1c3
commit f305e4b2c6
4 files changed
+45 -11

No files matched your search

@@ -276,16 +276,23 @@ class PosterBoardManager: ObservableObject {
func applyCarPlay(appHash: String, wallpapers: [CarPlayWallpaper]) throws { func applyCarPlay(appHash: String, wallpapers: [CarPlayWallpaper]) throws {
// write the image // write the image
var toRemove: [URL] = [] var toRemove: [URL] = []
var activeWP: [String] = UserDefaults.standard.array(forKey: "ActiveCarPlayWallpapers") as? [String] ?? []
for wallpaper in wallpapers { for wallpaper in wallpapers {
if let data = wallpaper.selectedImageDataLight, let img = UIImage(data: data) { if let data = wallpaper.selectedImageDataLight, let img = UIImage(data: data) {
let imgURL = SymHandler.getDocumentsDirectory().appendingPathComponent("CAR\(wallpaper.name)Dynamic-Light-11.cpbitmap") let imgURL = SymHandler.getDocumentsDirectory().appendingPathComponent("CAR\(wallpaper.name)Dynamic-Light-11.cpbitmap")
img.writeToCPBitmapFile(to: imgURL.path() as NSString) img.writeToCPBitmapFile(to: imgURL.path() as NSString)
toRemove.append(imgURL) toRemove.append(imgURL)
if !activeWP.contains(wallpaper.name) {
activeWP.append(wallpaper.name)
}
} }
if let data = wallpaper.selectedImageDataDark, let img = UIImage(data: data) { if let data = wallpaper.selectedImageDataDark, let img = UIImage(data: data) {
let imgURL = SymHandler.getDocumentsDirectory().appendingPathComponent("CAR\(wallpaper.name)Dynamic-Dark-11.cpbitmap") let imgURL = SymHandler.getDocumentsDirectory().appendingPathComponent("CAR\(wallpaper.name)Dynamic-Dark-11.cpbitmap")
img.writeToCPBitmapFile(to: imgURL.path() as NSString) img.writeToCPBitmapFile(to: imgURL.path() as NSString)
toRemove.append(imgURL) toRemove.append(imgURL)
if !activeWP.contains(wallpaper.name) {
activeWP.append(wallpaper.name)
}
} }
} }
@@ -297,6 +304,7 @@ class PosterBoardManager: ObservableObject {
for imgURL in toRemove { for imgURL in toRemove {
try FileManager.default.trashItem(at: imgURL, resultingItemURL: nil) try FileManager.default.trashItem(at: imgURL, resultingItemURL: nil)
} }
UserDefaults.standard.set(activeWP, forKey: "ActiveCarPlayWallpapers")
} }
static func clearCache() throws { static func clearCache() throws {
+9
View File
@@ -138,6 +138,9 @@
}, },
"CarPlay" : { "CarPlay" : {
},
"CarPlay Applied Wallpapers Successfully Cleared!" : {
}, },
"CarPlay Wallpapers" : { "CarPlay Wallpapers" : {
@@ -969,6 +972,9 @@
} }
} }
} }
},
"Reset CarPlay Applied Wallpapers" : {
}, },
"Reset Collections" : { "Reset Collections" : {
"localizations" : { "localizations" : {
@@ -1305,6 +1311,9 @@
} }
} }
} }
},
"You can now choose your wallpapers in the CarPlay settings in your car." : {
}, },
"You can only apply %@ descriptors." : { "You can only apply %@ descriptors." : {
"localizations" : { "localizations" : {
@@ -24,6 +24,7 @@ struct CarPlayView: View {
@State var showDark: Bool = false @State var showDark: Bool = false
@AppStorage("cpHash") var cpHash: String = "" @AppStorage("cpHash") var cpHash: String = ""
@State var activeWallpapers: [String] = []
@ObservedObject var pbManager = PosterBoardManager.shared @ObservedObject var pbManager = PosterBoardManager.shared
var body: some View { var body: some View {
@@ -34,7 +35,18 @@ struct CarPlayView: View {
} else { } else {
LazyVGrid(columns: [GridItem(.adaptive(minimum: 150, maximum: 250))]) { LazyVGrid(columns: [GridItem(.adaptive(minimum: 150, maximum: 250))]) {
ForEach($wallpapers) { wallpaper in ForEach($wallpapers) { wallpaper in
WallpaperView(wallpaper: wallpaper, didChange: $didChange, showDark: $showDark) ZStack {
WallpaperView(wallpaper: wallpaper, didChange: $didChange, showDark: $showDark)
.disabled(activeWallpapers.contains(wallpaper.name.wrappedValue))
// The checkmark
if activeWallpapers.contains(wallpaper.name.wrappedValue) {
RoundedRectangle(cornerRadius: 8)
.foregroundStyle(.black.opacity(0.4))
Image(systemName: "checkmark.circle.fill")
.font(.title)
.foregroundStyle(.green)
}
}
} }
} }
.padding() .padding()
@@ -52,18 +64,11 @@ struct CarPlayView: View {
do { do {
try pbManager.applyCarPlay(appHash: cpHash, wallpapers: wallpapers) try pbManager.applyCarPlay(appHash: cpHash, wallpapers: wallpapers)
SymHandler.cleanup() // just to be extra sure SymHandler.cleanup() // just to be extra sure
try? FileManager.default.removeItem(at: pbManager.getTendiesStoreURL())
UIApplication.shared.dismissAlert(animated: false) UIApplication.shared.dismissAlert(animated: false)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.35, execute: { DispatchQueue.main.asyncAfter(deadline: .now() + 0.35, execute: {
pbManager.selectedTendies.removeAll() activeWallpapers = UserDefaults.standard.array(forKey: "ActiveCarPlayWallpapers") as? [String] ?? []
Haptic.shared.notify(.success) Haptic.shared.notify(.success)
UIApplication.shared.confirmAlert(title: NSLocalizedString("Success!", comment: ""), body: NSLocalizedString("The PosterBoard app will now open. Please close it from the app switcher.", comment: ""), onOK: { UIApplication.shared.alert(title: NSLocalizedString("Success!", comment: ""), body: NSLocalizedString("You can now choose your wallpapers in the CarPlay settings in your car.", comment: ""))
if !pbManager.openPosterBoard() {
UIApplication.shared.confirmAlert(title: NSLocalizedString("Falling Back to Shortcut", comment: ""), body: NSLocalizedString("PosterBoard failed to open directly. The fallback shortcut will now be opened.", comment: ""), onOK: {
pbManager.runShortcut(named: "PosterBoard")
}, noCancel: true)
}
}, noCancel: true)
}) })
} catch CocoaError.fileWriteUnknown { } catch CocoaError.fileWriteUnknown {
presentError(ApplyError.wrongAppHash) presentError(ApplyError.wrongAppHash)
@@ -96,6 +101,8 @@ struct CarPlayView: View {
} }
.onAppear { .onAppear {
if wallpapers.isEmpty { if wallpapers.isEmpty {
// load active wallpapers from user defaults
activeWallpapers = UserDefaults.standard.array(forKey: "ActiveCarPlayWallpapers") as? [String] ?? []
// load the wallpapers // load the wallpapers
let frameworkPath = "/System/Library/PrivateFrameworks/CarPlayUIServices.framework" let frameworkPath = "/System/Library/PrivateFrameworks/CarPlayUIServices.framework"
do { do {
@@ -183,7 +190,7 @@ struct WallpaperImageView: View {
var body: some View { var body: some View {
Image(uiImage: img) Image(uiImage: img)
.resizable() .resizable()
.aspectRatio(1.25, contentMode: .fill) .aspectRatio(1.35, contentMode: .fill)
.cornerRadius(8) .cornerRadius(8)
.clipped() .clipped()
} }
+10
View File
@@ -71,6 +71,16 @@ struct SettingsView: View {
Label("Clear App Cache", systemImage: "trash.circle") Label("Clear App Cache", systemImage: "trash.circle")
} }
.foregroundStyle(.red) .foregroundStyle(.red)
Button(action: {
UIImpactFeedbackGenerator(style: .soft).impactOccurred()
UserDefaults.standard.set(nil, forKey: "ActiveCarPlayWallpapers")
Haptic.shared.notify(.success)
UIApplication.shared.alert(title: NSLocalizedString("CarPlay Applied Wallpapers Successfully Cleared!", comment: ""), body: "")
}) {
Label("Reset CarPlay Applied Wallpapers", systemImage: "trash.circle")
}
.foregroundStyle(.red)
} header: { } header: {
Label("Actions", systemImage: "gear") Label("Actions", systemImage: "gear")
} }