diff --git a/Pocket Poster/Controllers/SymHandler.swift b/Pocket Poster/Controllers/SymHandler.swift index a38d391..0f5729c 100644 --- a/Pocket Poster/Controllers/SymHandler.swift +++ b/Pocket Poster/Controllers/SymHandler.swift @@ -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) } diff --git a/Pocket Poster/Localizable.xcstrings b/Pocket Poster/Localizable.xcstrings index 4953e09..2e2ebcf 100644 --- a/Pocket Poster/Localizable.xcstrings +++ b/Pocket Poster/Localizable.xcstrings @@ -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" : { diff --git a/Pocket Poster/Views/SettingsView.swift b/Pocket Poster/Views/SettingsView.swift index d4d3314..e65b903 100644 --- a/Pocket Poster/Views/SettingsView.swift +++ b/Pocket Poster/Views/SettingsView.swift @@ -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: { - cancelWaitForHash() - }, noCancel: true) + 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" - } - let items = contents.split(separator: separator) - if let pb = items.first { - pbHash = String(pb) - } - if items.count >= 2 { - cpHash = String(items[1]) + pbHash = contents + } + // 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 {