active wallpapers tracking
This commit is contained in:
1 parent
069d5cf1c3
commit
f305e4b2c6
4 files changed
+44
-10
No files matched your search
@@ -276,16 +276,23 @@ class PosterBoardManager: ObservableObject {
|
||||
func applyCarPlay(appHash: String, wallpapers: [CarPlayWallpaper]) throws {
|
||||
// write the image
|
||||
var toRemove: [URL] = []
|
||||
var activeWP: [String] = UserDefaults.standard.array(forKey: "ActiveCarPlayWallpapers") as? [String] ?? []
|
||||
for wallpaper in wallpapers {
|
||||
if let data = wallpaper.selectedImageDataLight, let img = UIImage(data: data) {
|
||||
let imgURL = SymHandler.getDocumentsDirectory().appendingPathComponent("CAR\(wallpaper.name)Dynamic-Light-11.cpbitmap")
|
||||
img.writeToCPBitmapFile(to: imgURL.path() as NSString)
|
||||
toRemove.append(imgURL)
|
||||
if !activeWP.contains(wallpaper.name) {
|
||||
activeWP.append(wallpaper.name)
|
||||
}
|
||||
}
|
||||
if let data = wallpaper.selectedImageDataDark, let img = UIImage(data: data) {
|
||||
let imgURL = SymHandler.getDocumentsDirectory().appendingPathComponent("CAR\(wallpaper.name)Dynamic-Dark-11.cpbitmap")
|
||||
img.writeToCPBitmapFile(to: imgURL.path() as NSString)
|
||||
toRemove.append(imgURL)
|
||||
if !activeWP.contains(wallpaper.name) {
|
||||
activeWP.append(wallpaper.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,6 +304,7 @@ class PosterBoardManager: ObservableObject {
|
||||
for imgURL in toRemove {
|
||||
try FileManager.default.trashItem(at: imgURL, resultingItemURL: nil)
|
||||
}
|
||||
UserDefaults.standard.set(activeWP, forKey: "ActiveCarPlayWallpapers")
|
||||
}
|
||||
|
||||
static func clearCache() throws {
|
||||
|
||||
@@ -138,6 +138,9 @@
|
||||
},
|
||||
"CarPlay" : {
|
||||
|
||||
},
|
||||
"CarPlay Applied Wallpapers Successfully Cleared!" : {
|
||||
|
||||
},
|
||||
"CarPlay Wallpapers" : {
|
||||
|
||||
@@ -969,6 +972,9 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"Reset CarPlay Applied Wallpapers" : {
|
||||
|
||||
},
|
||||
"Reset Collections" : {
|
||||
"localizations" : {
|
||||
@@ -1305,6 +1311,9 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"You can now choose your wallpapers in the CarPlay settings in your car." : {
|
||||
|
||||
},
|
||||
"You can only apply %@ descriptors." : {
|
||||
"localizations" : {
|
||||
|
||||
@@ -24,6 +24,7 @@ struct CarPlayView: View {
|
||||
@State var showDark: Bool = false
|
||||
|
||||
@AppStorage("cpHash") var cpHash: String = ""
|
||||
@State var activeWallpapers: [String] = []
|
||||
@ObservedObject var pbManager = PosterBoardManager.shared
|
||||
|
||||
var body: some View {
|
||||
@@ -34,7 +35,18 @@ struct CarPlayView: View {
|
||||
} else {
|
||||
LazyVGrid(columns: [GridItem(.adaptive(minimum: 150, maximum: 250))]) {
|
||||
ForEach($wallpapers) { wallpaper in
|
||||
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()
|
||||
@@ -52,18 +64,11 @@ struct CarPlayView: View {
|
||||
do {
|
||||
try pbManager.applyCarPlay(appHash: cpHash, wallpapers: wallpapers)
|
||||
SymHandler.cleanup() // just to be extra sure
|
||||
try? FileManager.default.removeItem(at: pbManager.getTendiesStoreURL())
|
||||
UIApplication.shared.dismissAlert(animated: false)
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.35, execute: {
|
||||
pbManager.selectedTendies.removeAll()
|
||||
activeWallpapers = UserDefaults.standard.array(forKey: "ActiveCarPlayWallpapers") as? [String] ?? []
|
||||
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: {
|
||||
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)
|
||||
UIApplication.shared.alert(title: NSLocalizedString("Success!", comment: ""), body: NSLocalizedString("You can now choose your wallpapers in the CarPlay settings in your car.", comment: ""))
|
||||
})
|
||||
} catch CocoaError.fileWriteUnknown {
|
||||
presentError(ApplyError.wrongAppHash)
|
||||
@@ -96,6 +101,8 @@ struct CarPlayView: View {
|
||||
}
|
||||
.onAppear {
|
||||
if wallpapers.isEmpty {
|
||||
// load active wallpapers from user defaults
|
||||
activeWallpapers = UserDefaults.standard.array(forKey: "ActiveCarPlayWallpapers") as? [String] ?? []
|
||||
// load the wallpapers
|
||||
let frameworkPath = "/System/Library/PrivateFrameworks/CarPlayUIServices.framework"
|
||||
do {
|
||||
@@ -183,7 +190,7 @@ struct WallpaperImageView: View {
|
||||
var body: some View {
|
||||
Image(uiImage: img)
|
||||
.resizable()
|
||||
.aspectRatio(1.25, contentMode: .fill)
|
||||
.aspectRatio(1.35, contentMode: .fill)
|
||||
.cornerRadius(8)
|
||||
.clipped()
|
||||
}
|
||||
|
||||
@@ -71,6 +71,16 @@ struct SettingsView: View {
|
||||
Label("Clear App Cache", systemImage: "trash.circle")
|
||||
}
|
||||
.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: {
|
||||
Label("Actions", systemImage: "gear")
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user