handle carplay and pb hashes separately

This commit is contained in:
leminlimez committed 2025-07-12 11:38:09 -04:00
1 parent 94f78c9f4e
commit faaef84376
3 files changed
+26 -28

No files matched your search

@@ -23,6 +23,13 @@ class SymHandler {
return getDocumentsDirectory()
}
static func getAppHashURL() -> URL {
return getLCDocumentsDirectory().appendingPathComponent("NuggetAppHash")
}
static func getCarPlayHashURL() -> URL {
return getLCDocumentsDirectory().appendingPathComponent("NuggetCarPlayHash")
}
private static func getSymlinkURL() -> URL {
return getLCDocumentsDirectory().appendingPathComponent(".Trash", conformingTo: .symbolicLink)
}
+6
View File
@@ -1164,6 +1164,9 @@
}
}
}
},
"Connect your device to Nugget and click the \"Pocket Poster Helper\" button." : {
},
"Could not download wallpaper!" : {
"localizations" : {
@@ -9060,6 +9063,9 @@
}
}
}
},
"Waiting for app hash..." : {
},
"Website Designer" : {
"localizations" : {
+13 -28
View File
@@ -23,30 +23,16 @@ struct SettingsView: View {
TextField("Enter App Hash", text: $pbHash)
.textFieldStyle(RoundedBorderTextFieldStyle())
.font(.system(.body, design: .monospaced))
.onChange(of: pbHash) { _ in
var separator: String? = nil
if pbHash.contains(" ") {
separator = " "
} else if pbHash.contains("\n") {
separator = "\n"
}
if let separator = separator {
let items = pbHash.split(separator: separator)
if let pb = items.first {
pbHash = String(pb)
}
if items.count >= 2 {
cpHash = String(items[1])
}
}
}
HStack {
Spacer()
// Run task to check until file exists from Nugget pc over AFC
Button(action: {
UIApplication.shared.confirmAlert(title: "Waiting for app hash...", body: "Connect your device to Nugget and click the \"Pocket Poster Helper\" button.", confirmTitle: "Cancel", onOK: {
if !FileManager.default.fileExists(atPath: SymHandler.getAppHashURL().path()) {
// don't show the alert because it is already there
UIApplication.shared.confirmAlert(title: NSLocalizedString("Waiting for app hash...", comment: ""), body: NSLocalizedString("Connect your device to Nugget and click the \"Pocket Poster Helper\" button.", comment: ""), confirmTitle: NSLocalizedString("Cancel", comment: ""), onOK: {
cancelWaitForHash()
}, noCancel: true)
}
startWaitForHash()
}) {
Text("Detect")
@@ -151,7 +137,7 @@ struct SettingsView: View {
func startWaitForHash() {
checkingForHash = true
hashCheckTask = Task {
let filePath = SymHandler.getLCDocumentsDirectory().appendingPathComponent("NuggetAppHash")
let filePath = SymHandler.getAppHashURL()
while !FileManager.default.fileExists(atPath: filePath.path()) {
try? await Task.sleep(nanoseconds: 500_000_000) // Sleep 0.5s
try Task.checkCancellation()
@@ -161,16 +147,15 @@ struct SettingsView: View {
let contents = try String(contentsOf: filePath)
try? FileManager.default.removeItem(at: filePath)
await MainActor.run {
var separator = " "
if contents.contains("\n") {
separator = "\n"
pbHash = contents
}
let items = contents.split(separator: separator)
if let pb = items.first {
pbHash = String(pb)
}
if items.count >= 2 {
cpHash = String(items[1])
// check for carplay hash
let carplayPath = SymHandler.getCarPlayHashURL()
if FileManager.default.fileExists(atPath: carplayPath.path()) {
let carplayContents = try String(contentsOf: carplayPath)
try? FileManager.default.removeItem(at: carplayPath)
await MainActor.run {
cpHash = carplayContents
}
}
} catch {