get wallpapers in order
This commit is contained in:
1 parent
2f99384650
commit
918af3baa3
6 files changed
+108
-16
No files matched your search
@@ -0,0 +1,23 @@
|
|||||||
|
//
|
||||||
|
// CarPlayWallpaper.swift
|
||||||
|
// Pocket Poster
|
||||||
|
//
|
||||||
|
// Created by lemin on 6/22/25.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct CarPlayWallpaper: Identifiable {
|
||||||
|
var id = UUID()
|
||||||
|
var name: String
|
||||||
|
var lightImage: UIImage
|
||||||
|
var darkImage: UIImage
|
||||||
|
var selectedImageDataLight: Data?
|
||||||
|
var selectedImageDataDark: Data?
|
||||||
|
var changed: Bool
|
||||||
|
}
|
||||||
|
|
||||||
|
extension CarPlayWallpaper: Reorderable {
|
||||||
|
typealias OrderElement = String
|
||||||
|
var orderElement: OrderElement { name }
|
||||||
|
}
|
||||||
@@ -245,6 +245,39 @@ class PosterBoardManager: ObservableObject {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getCarPlayWallpaperNames() -> [String]? {
|
||||||
|
dlopen("/System/Library/PrivateFrameworks/CarPlayUIServices.framework/CarPlayUIServices", RTLD_GLOBAL)
|
||||||
|
|
||||||
|
if #available(iOS 18.0, *) {
|
||||||
|
// iOS 18 method (it got moved)
|
||||||
|
guard let obj = objc_getClass("CRSUISystemWallpaper") as? NSObject else { print("no class"); return nil }
|
||||||
|
|
||||||
|
if let success = obj.perform(Selector(("wallpapers"))), let arr = success.takeUnretainedValue() as? [NSObject] {
|
||||||
|
var namesList: [String] = []
|
||||||
|
for wp in arr {
|
||||||
|
if let wpACName = wp.perform(Selector(("wallpaperAssetCatalogName"))), let result = wpACName.takeUnretainedValue() as? String {
|
||||||
|
namesList.append(result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return namesList
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// iOS 17-
|
||||||
|
guard let obj = objc_getClass("CRSUIWallpaperPreferences") as? NSObject else { print("no class"); return nil }
|
||||||
|
if let success = obj.perform(Selector(("availableWallpapers"))), let arr = success.takeUnretainedValue() as? [NSObject] {
|
||||||
|
var namesList: [String] = []
|
||||||
|
for wp in arr {
|
||||||
|
if let wpACName = wp.perform(Selector(("wallpaperAssetCatalogName"))), let result = wpACName.takeUnretainedValue() as? String {
|
||||||
|
namesList.append(result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return namesList
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
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] = []
|
||||||
@@ -270,14 +303,21 @@ 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()
|
||||||
}
|
}
|
||||||
for imgURL in toRemove {
|
try FileManager.default.removeItem(at: hmm.appendingPathComponent("Caches"))
|
||||||
try FileManager.default.trashItem(at: imgURL, resultingItemURL: nil)
|
|
||||||
}
|
|
||||||
UserDefaults.standard.set(activeWP, forKey: "ActiveCarPlayWallpapers")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static func clearCache() throws {
|
static func clearCache() throws {
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
//
|
||||||
|
// Reorderable.swift
|
||||||
|
// Pocket Poster
|
||||||
|
//
|
||||||
|
// Created by lemin on 6/22/25.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
protocol Reorderable {
|
||||||
|
associatedtype OrderElement: Equatable
|
||||||
|
var orderElement: OrderElement { get }
|
||||||
|
}
|
||||||
|
|
||||||
|
extension Array where Element: Reorderable {
|
||||||
|
|
||||||
|
func reorder(by preferredOrder: [Element.OrderElement]) -> [Element] {
|
||||||
|
sorted {
|
||||||
|
guard let first = preferredOrder.firstIndex(of: $0.orderElement) else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let second = preferredOrder.firstIndex(of: $1.orderElement) else {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return first < second
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
File renamed without changes.
@@ -3421,6 +3421,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"Failed to fetch CarPlay wallpapers" : {
|
||||||
|
|
||||||
},
|
},
|
||||||
"Failed to import tendies" : {
|
"Failed to import tendies" : {
|
||||||
"localizations" : {
|
"localizations" : {
|
||||||
|
|||||||
@@ -8,16 +8,6 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
import PhotosUI
|
import PhotosUI
|
||||||
|
|
||||||
struct CarPlayWallpaper: Identifiable {
|
|
||||||
var id = UUID()
|
|
||||||
var name: String
|
|
||||||
var lightImage: UIImage
|
|
||||||
var darkImage: UIImage
|
|
||||||
var selectedImageDataLight: Data?
|
|
||||||
var selectedImageDataDark: Data?
|
|
||||||
var changed: Bool
|
|
||||||
}
|
|
||||||
|
|
||||||
struct CarPlayView: View {
|
struct CarPlayView: View {
|
||||||
@State var wallpapers: [CarPlayWallpaper] = []
|
@State var wallpapers: [CarPlayWallpaper] = []
|
||||||
@State var didChange: Bool = false
|
@State var didChange: Bool = false
|
||||||
@@ -128,8 +118,12 @@ struct CarPlayView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// sort them
|
||||||
|
if let sortedWallpapers = PosterBoardManager.shared.getCarPlayWallpaperNames() {
|
||||||
|
wallpapers = wallpapers.reorder(by: sortedWallpapers)
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
print(error.localizedDescription)
|
UIApplication.shared.alert(body: NSLocalizedString("Failed to fetch CarPlay wallpapers", comment: "") + ":\n\(error.localizedDescription)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -178,6 +172,7 @@ struct WallpaperView: View {
|
|||||||
.stroke(.gray, lineWidth: 2)
|
.stroke(.gray, lineWidth: 2)
|
||||||
}
|
}
|
||||||
.onChange(of: selectedItem) { newItem in
|
.onChange(of: selectedItem) { newItem in
|
||||||
|
if newItem == nil { return }
|
||||||
Task {
|
Task {
|
||||||
// Retrieve selected asset in the form of Data
|
// Retrieve selected asset in the form of Data
|
||||||
if let data = try? await newItem?.loadTransferable(type: Data.self) {
|
if let data = try? await newItem?.loadTransferable(type: Data.self) {
|
||||||
@@ -186,6 +181,7 @@ struct WallpaperView: View {
|
|||||||
} else {
|
} else {
|
||||||
wallpaper.selectedImageDataLight = data
|
wallpaper.selectedImageDataLight = data
|
||||||
}
|
}
|
||||||
|
selectedItem = nil
|
||||||
withAnimation {
|
withAnimation {
|
||||||
didChange = true
|
didChange = true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user