From 5bb69b5369cc997b0c6725a90417dece8fa5b31f Mon Sep 17 00:00:00 2001 From: leminlimez <59540996+leminlimez@users.noreply.github.com> Date: Wed, 4 Jun 2025 04:05:04 -0400 Subject: [PATCH] add tendies file limit --- .../Controllers/PosterBoardManager.swift | 2 ++ Pocket Poster/Pocket_PosterApp.swift | 30 ++++++++++++------- Pocket Poster/Views/ContentView.swift | 6 +++- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/Pocket Poster/Controllers/PosterBoardManager.swift b/Pocket Poster/Controllers/PosterBoardManager.swift index b89d0f3..27acf1e 100644 --- a/Pocket Poster/Controllers/PosterBoardManager.swift +++ b/Pocket Poster/Controllers/PosterBoardManager.swift @@ -13,6 +13,8 @@ class PosterBoardManager { static let ShortcutURL = "https://www.icloud.com/shortcuts/a28d2c02ca11453cb5b8f91c12cfa692" static let WallpapersURL = "https://cowabun.ga/wallpapers" + static let MaxTendies = 10 + static func getTendiesStoreURL() -> URL { let tendiesStoreURL = SymHandler.getDocumentsDirectory().appendingPathComponent("KFC Bucket", conformingTo: .directory) // create it if it doesn't exist diff --git a/Pocket Poster/Pocket_PosterApp.swift b/Pocket Poster/Pocket_PosterApp.swift index ef652ae..14e3475 100644 --- a/Pocket Poster/Pocket_PosterApp.swift +++ b/Pocket Poster/Pocket_PosterApp.swift @@ -40,23 +40,31 @@ struct Pocket_PosterApp: App { .onOpenURL(perform: { url in // Download URL if url.absoluteString.starts(with: "pocketposter://download") { - downloadURL = url.absoluteString.replacingOccurrences(of: "pocketposter://download?url=", with: "") - showDownloadAlert = true + if selectedTendies.count >= PosterBoardManager.MaxTendies { + UIApplication.shared.alert(title: "Max Tendies Reached", body: "You can only apply \(PosterBoardManager.MaxTendies) descriptors.") + } else { + downloadURL = url.absoluteString.replacingOccurrences(of: "pocketposter://download?url=", with: "") + showDownloadAlert = true + } } // App Hash URL else if url.absoluteString.starts(with: "pocketposter://app-hash?uuid=") { pbHash = url.absoluteString.replacingOccurrences(of: "pocketposter://app-hash?uuid=", with: "") } else if url.pathExtension == "tendies" { - // copy it over to the KFC bucket - do { - let newURL = try DownloadManager.copyTendies(from: url) - selectedTendies.append(newURL) - Haptic.shared.notify(.success) - UIApplication.shared.alert(title: "Successfully imported \(url.lastPathComponent)", body: "") - } catch { - Haptic.shared.notify(.error) - UIApplication.shared.alert(title: "Failed to import tendies", body: error.localizedDescription) + if selectedTendies.count >= PosterBoardManager.MaxTendies { + UIApplication.shared.alert(title: "Max Tendies Reached", body: "You can only apply \(PosterBoardManager.MaxTendies) descriptors.") + } else { + // copy it over to the KFC bucket + do { + let newURL = try DownloadManager.copyTendies(from: url) + selectedTendies.append(newURL) + Haptic.shared.notify(.success) + UIApplication.shared.alert(title: "Successfully imported \(url.lastPathComponent)", body: "") + } catch { + Haptic.shared.notify(.error) + UIApplication.shared.alert(title: "Failed to import tendies", body: error.localizedDescription) + } } } }) diff --git a/Pocket Poster/Views/ContentView.swift b/Pocket Poster/Views/ContentView.swift index 09595cb..7827070 100644 --- a/Pocket Poster/Views/ContentView.swift +++ b/Pocket Poster/Views/ContentView.swift @@ -130,7 +130,11 @@ struct ContentView: View { .fileImporter(isPresented: $showTendiesImporter, allowedContentTypes: [UTType(filenameExtension: "tendies", conformingTo: .data)!], allowsMultipleSelection: true, onCompletion: { result in switch result { case .success(let url): - selectedTendies.wrappedValue.append(contentsOf: url) + if selectedTendies.wrappedValue.count + url.count > PosterBoardManager.MaxTendies { + UIApplication.shared.alert(title: "Max Tendies Reached", body: "You can only apply \(PosterBoardManager.MaxTendies) descriptors.") + } else { + selectedTendies.wrappedValue.append(contentsOf: url) + } case .failure(let error): lastError = error.localizedDescription showErrorAlert.toggle()