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
+29 -31

No files matched your search

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