handle carplay and pb hashes separately
This commit is contained in:
1 parent
94f78c9f4e
commit
faaef84376
3 files changed
+26
-28
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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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" : {
|
||||||
|
|||||||
@@ -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()) {
|
||||||
|
// 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()
|
cancelWaitForHash()
|
||||||
}, noCancel: true)
|
}, 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"
|
|
||||||
}
|
}
|
||||||
let items = contents.split(separator: separator)
|
// check for carplay hash
|
||||||
if let pb = items.first {
|
let carplayPath = SymHandler.getCarPlayHashURL()
|
||||||
pbHash = String(pb)
|
if FileManager.default.fileExists(atPath: carplayPath.path()) {
|
||||||
}
|
let carplayContents = try String(contentsOf: carplayPath)
|
||||||
if items.count >= 2 {
|
try? FileManager.default.removeItem(at: carplayPath)
|
||||||
cpHash = String(items[1])
|
await MainActor.run {
|
||||||
|
cpHash = carplayContents
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
Reference in new issue
Block a user