downloading tendie from url scheme

This commit is contained in:
leminlimez committed 2025-06-01 07:35:22 -04:00
1 parent 7c0cb386a7
commit 744a243080
6 files changed
+176 -2

No files matched your search

+36 -1
View File
@@ -27,6 +27,9 @@ struct ContentView: View {
@State var showSuccessAlert = false
@State var lastError: String?
@State var downloadURL: String? = nil
@State var showDownloadAlert = false
var body: some View {
NavigationStack {
ScrollView {
@@ -120,8 +123,19 @@ struct ContentView: View {
} message: {
Text(lastError ?? "???")
}
.alert("Download Tendies File", isPresented: $showDownloadAlert) {
Button("OK") {
downloadWallpaper()
}
Button("Cancel", role: .cancel) {}
} message: {
Text("Would you like to download the file \(downloadURL ?? "UNKNOWN")?")
}
.onOpenURL(perform: { url in
if url.pathExtension == "tendies" {
if url.absoluteString.starts(with: "pocketposter://download") {
downloadURL = url.absoluteString.replacingOccurrences(of: "pocketposter://download?url=", with: "")
}
else if url.pathExtension == "tendies" {
if selectedTendies == nil {
selectedTendies = []
}
@@ -136,6 +150,27 @@ struct ContentView: View {
}
}
func downloadWallpaper() {
UIImpactFeedbackGenerator(style: .soft).impactOccurred()
UIApplication.shared.alert(title: NSLocalizedString("Downloading", comment: "") + " \(DownloadManager.getWallpaperNameFromURL(string: downloadURL ?? "/Unknown"))...", body: NSLocalizedString("Please wait", comment: ""), animated: false, withButton: false)
Task {
do {
let newURL = try await DownloadManager.downloadFromURL(string: downloadURL!)
if selectedTendies == nil {
selectedTendies = []
}
selectedTendies?.append(newURL)
Haptic.shared.notify(.success)
UIApplication.shared.dismissAlert(animated: true)
} catch {
Haptic.shared.notify(.error)
UIApplication.shared.dismissAlert(animated: true)
UIApplication.shared.alert(title: NSLocalizedString("Could not download wallpaper!", comment: ""), body: error.localizedDescription)
}
}
}
init() {
// Fix file picker
let fixMethod = class_getInstanceMethod(UIDocumentPickerViewController.self, #selector(UIDocumentPickerViewController.fix_init(forOpeningContentTypes:asCopy:)))!
+1 -1
View File
@@ -24,7 +24,7 @@ struct SettingsView: View {
.foregroundColor(.primary)
Spacer()
}
TextField("App Hash", text: $pbHash)
TextField("Enter App Hash", text: $pbHash)
.textFieldStyle(RoundedBorderTextFieldStyle())
.font(.system(.body, design: .monospaced))
}