save changed images
This commit is contained in:
1 parent
7c2a031463
commit
d5833dfb81
5 files changed
+35
-18
No files matched your search
@@ -268,7 +268,7 @@
|
|||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 0;
|
CURRENT_PROJECT_VERSION = 1;
|
||||||
DEVELOPMENT_ASSET_PATHS = "\"Pocket Poster/Preview Content\"";
|
DEVELOPMENT_ASSET_PATHS = "\"Pocket Poster/Preview Content\"";
|
||||||
DEVELOPMENT_TEAM = 2P4CP47H76;
|
DEVELOPMENT_TEAM = 2P4CP47H76;
|
||||||
ENABLE_PREVIEWS = YES;
|
ENABLE_PREVIEWS = YES;
|
||||||
@@ -285,7 +285,7 @@
|
|||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
);
|
);
|
||||||
MARKETING_VERSION = 2.0;
|
MARKETING_VERSION = 3.0;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = "com.lemin.Pocket-Poster";
|
PRODUCT_BUNDLE_IDENTIFIER = "com.lemin.Pocket-Poster";
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||||
@@ -300,7 +300,7 @@
|
|||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 0;
|
CURRENT_PROJECT_VERSION = 1;
|
||||||
DEVELOPMENT_ASSET_PATHS = "\"Pocket Poster/Preview Content\"";
|
DEVELOPMENT_ASSET_PATHS = "\"Pocket Poster/Preview Content\"";
|
||||||
DEVELOPMENT_TEAM = 2P4CP47H76;
|
DEVELOPMENT_TEAM = 2P4CP47H76;
|
||||||
ENABLE_PREVIEWS = YES;
|
ENABLE_PREVIEWS = YES;
|
||||||
@@ -317,7 +317,7 @@
|
|||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
);
|
);
|
||||||
MARKETING_VERSION = 2.0;
|
MARKETING_VERSION = 3.0;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = "com.lemin.Pocket-Poster";
|
PRODUCT_BUNDLE_IDENTIFIER = "com.lemin.Pocket-Poster";
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ struct CarPlayWallpaper: Identifiable {
|
|||||||
var darkImage: UIImage
|
var darkImage: UIImage
|
||||||
var selectedImageDataLight: Data?
|
var selectedImageDataLight: Data?
|
||||||
var selectedImageDataDark: Data?
|
var selectedImageDataDark: Data?
|
||||||
var changed: Bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension CarPlayWallpaper: Reorderable {
|
extension CarPlayWallpaper: Reorderable {
|
||||||
|
|||||||
@@ -278,15 +278,26 @@ class PosterBoardManager: ObservableObject {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getCarPlayPhotosURL() -> URL {
|
||||||
|
let cppURL = SymHandler.getDocumentsDirectory().appendingPathComponent("CarPlayPhotos", conformingTo: .directory)
|
||||||
|
// create it if it doesn't exist
|
||||||
|
if !FileManager.default.fileExists(atPath: cppURL.path()) {
|
||||||
|
try? FileManager.default.createDirectory(at: cppURL, withIntermediateDirectories: true)
|
||||||
|
}
|
||||||
|
return cppURL
|
||||||
|
}
|
||||||
|
|
||||||
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] ?? []
|
var activeWP: [String] = UserDefaults.standard.array(forKey: "ActiveCarPlayWallpapers") as? [String] ?? []
|
||||||
|
let cppURL = getCarPlayPhotosURL()
|
||||||
let cacheVer = getCarPlayCacheVersion()
|
let cacheVer = getCarPlayCacheVersion()
|
||||||
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\(cacheVer).cpbitmap")
|
let imgURL = SymHandler.getDocumentsDirectory().appendingPathComponent("CAR\(wallpaper.name)Dynamic-Light\(cacheVer).cpbitmap")
|
||||||
img.writeToCPBitmapFile(to: imgURL.path() as NSString)
|
img.writeToCPBitmapFile(to: imgURL.path() as NSString)
|
||||||
|
try? data.write(to: cppURL.appendingPathComponent("\(wallpaper.name)-Light"))
|
||||||
toRemove.append(imgURL)
|
toRemove.append(imgURL)
|
||||||
if !activeWP.contains(wallpaper.name) {
|
if !activeWP.contains(wallpaper.name) {
|
||||||
activeWP.append(wallpaper.name)
|
activeWP.append(wallpaper.name)
|
||||||
@@ -295,6 +306,7 @@ class PosterBoardManager: ObservableObject {
|
|||||||
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\(cacheVer).cpbitmap")
|
let imgURL = SymHandler.getDocumentsDirectory().appendingPathComponent("CAR\(wallpaper.name)Dynamic-Dark\(cacheVer).cpbitmap")
|
||||||
img.writeToCPBitmapFile(to: imgURL.path() as NSString)
|
img.writeToCPBitmapFile(to: imgURL.path() as NSString)
|
||||||
|
try? data.write(to: cppURL.appendingPathComponent("\(wallpaper.name)-Dark"))
|
||||||
toRemove.append(imgURL)
|
toRemove.append(imgURL)
|
||||||
if !activeWP.contains(wallpaper.name) {
|
if !activeWP.contains(wallpaper.name) {
|
||||||
activeWP.append(wallpaper.name)
|
activeWP.append(wallpaper.name)
|
||||||
@@ -303,28 +315,25 @@ class PosterBoardManager: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// symlink and apply
|
// symlink and apply
|
||||||
// let _ = try SymHandler.createAppSymlink(for: "\(appHash)/Library/Caches/MappedImageCache/com.apple.CarPlayApp.wallpaper-images")
|
let _ = try SymHandler.createAppSymlink(for: "\(appHash)/Library/Caches/MappedImageCache/com.apple.CarPlayApp.wallpaper-images")
|
||||||
// defer {
|
|
||||||
// SymHandler.cleanup()
|
|
||||||
// }
|
|
||||||
// for imgURL in toRemove {
|
|
||||||
// try FileManager.default.trashItem(at: imgURL, resultingItemURL: nil)
|
|
||||||
// }
|
|
||||||
// UserDefaults.standard.set(activeWP, forKey: "ActiveCarPlayWallpapers")
|
|
||||||
// let test = SymHandler.getDocumentsDirectory().appendingPathComponent("Caches")
|
|
||||||
// try Data(count: 0).write(to: test)
|
|
||||||
let hmm = try SymHandler.createAppSymlink(for: "\(appHash)/Library")
|
|
||||||
defer {
|
defer {
|
||||||
SymHandler.cleanup()
|
SymHandler.cleanup()
|
||||||
}
|
}
|
||||||
try FileManager.default.removeItem(at: hmm.appendingPathComponent("Caches"))
|
for imgURL in toRemove {
|
||||||
|
try FileManager.default.trashItem(at: imgURL, resultingItemURL: nil)
|
||||||
|
}
|
||||||
|
UserDefaults.standard.set(activeWP, forKey: "ActiveCarPlayWallpapers")
|
||||||
|
let test = SymHandler.getDocumentsDirectory().appendingPathComponent("Caches")
|
||||||
|
try Data(count: 0).write(to: test)
|
||||||
}
|
}
|
||||||
|
|
||||||
static func clearCache() throws {
|
static func clearCache() throws {
|
||||||
SymHandler.cleanup()
|
SymHandler.cleanup()
|
||||||
let docDir = SymHandler.getDocumentsDirectory()
|
let docDir = SymHandler.getDocumentsDirectory()
|
||||||
for file in try FileManager.default.contentsOfDirectory(at: docDir, includingPropertiesForKeys: nil) {
|
for file in try FileManager.default.contentsOfDirectory(at: docDir, includingPropertiesForKeys: nil) {
|
||||||
|
if file.lastPathComponent != "CarPlayPhotos" {
|
||||||
try FileManager.default.removeItem(at: file)
|
try FileManager.default.removeItem(at: file)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -103,6 +103,7 @@ struct CarPlayView: View {
|
|||||||
// load active wallpapers from user defaults
|
// load active wallpapers from user defaults
|
||||||
activeWallpapers = UserDefaults.standard.array(forKey: "ActiveCarPlayWallpapers") as? [String] ?? []
|
activeWallpapers = UserDefaults.standard.array(forKey: "ActiveCarPlayWallpapers") as? [String] ?? []
|
||||||
// load the wallpapers
|
// load the wallpapers
|
||||||
|
let cppURL = PosterBoardManager.shared.getCarPlayPhotosURL()
|
||||||
let frameworkPath = "/System/Library/PrivateFrameworks/CarPlayUIServices.framework"
|
let frameworkPath = "/System/Library/PrivateFrameworks/CarPlayUIServices.framework"
|
||||||
do {
|
do {
|
||||||
for file in try FileManager.default.contentsOfDirectory(at: URL(fileURLWithPath: frameworkPath), includingPropertiesForKeys: nil, options: .skipsHiddenFiles) {
|
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
|
darkImg = UIImage(data: darkData) ?? wpImg
|
||||||
}
|
}
|
||||||
let name = file.lastPathComponent.replacingOccurrences(of: "-Light.heic", with: "")
|
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
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ struct SettingsView: View {
|
|||||||
Button(action: {
|
Button(action: {
|
||||||
UIImpactFeedbackGenerator(style: .soft).impactOccurred()
|
UIImpactFeedbackGenerator(style: .soft).impactOccurred()
|
||||||
UserDefaults.standard.set(nil, forKey: "ActiveCarPlayWallpapers")
|
UserDefaults.standard.set(nil, forKey: "ActiveCarPlayWallpapers")
|
||||||
|
try? FileManager.default.removeItem(at: PosterBoardManager.shared.getCarPlayPhotosURL())
|
||||||
Haptic.shared.notify(.success)
|
Haptic.shared.notify(.success)
|
||||||
UIApplication.shared.alert(title: NSLocalizedString("CarPlay Applied Wallpapers Successfully Cleared!", comment: ""), body: "")
|
UIApplication.shared.alert(title: NSLocalizedString("CarPlay Applied Wallpapers Successfully Cleared!", comment: ""), body: "")
|
||||||
}) {
|
}) {
|
||||||
|
|||||||
Reference in new issue
Block a user