explore page
still needs fixed for no wifi and freezing
This commit is contained in:
1 parent
cdd5cbe634
commit
edde7ddb0c
7 files changed
+122
-39
No files matched your search
@@ -268,7 +268,7 @@
|
|||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 2;
|
CURRENT_PROJECT_VERSION = 3;
|
||||||
DEVELOPMENT_ASSET_PATHS = "\"Pocket Poster/Preview Content\"";
|
DEVELOPMENT_ASSET_PATHS = "\"Pocket Poster/Preview Content\"";
|
||||||
DEVELOPMENT_TEAM = 2P4CP47H76;
|
DEVELOPMENT_TEAM = 2P4CP47H76;
|
||||||
ENABLE_PREVIEWS = YES;
|
ENABLE_PREVIEWS = YES;
|
||||||
@@ -300,7 +300,7 @@
|
|||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 2;
|
CURRENT_PROJECT_VERSION = 3;
|
||||||
DEVELOPMENT_ASSET_PATHS = "\"Pocket Poster/Preview Content\"";
|
DEVELOPMENT_ASSET_PATHS = "\"Pocket Poster/Preview Content\"";
|
||||||
DEVELOPMENT_TEAM = 2P4CP47H76;
|
DEVELOPMENT_TEAM = 2P4CP47H76;
|
||||||
ENABLE_PREVIEWS = YES;
|
ENABLE_PREVIEWS = YES;
|
||||||
|
|||||||
@@ -6,13 +6,57 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import UIKit
|
||||||
|
|
||||||
class DownloadManager {
|
class DownloadManager: ObservableObject {
|
||||||
static func getWallpaperNameFromURL(string url: String) -> String {
|
static let shared = DownloadManager()
|
||||||
|
|
||||||
|
@Published var downloadURL: String? = nil
|
||||||
|
|
||||||
|
func getWallpaperNameFromURL(string url: String) -> String {
|
||||||
return String(url.split(separator: "/").last ?? "Unknown")
|
return String(url.split(separator: "/").last ?? "Unknown")
|
||||||
}
|
}
|
||||||
|
|
||||||
static func downloadFromURL(_ url: URL) async throws -> URL {
|
func startTendiesDownload(for url: URL) {
|
||||||
|
// prohibit to only tendies files
|
||||||
|
if !url.absoluteString.hasSuffix(".tendies") {
|
||||||
|
UIApplication.shared.alert(body: NSLocalizedString("Only .tendies files can be downloaded!", comment: ""))
|
||||||
|
} else if PosterBoardManager.shared.selectedTendies.count >= PosterBoardManager.MaxTendies {
|
||||||
|
UIApplication.shared.alert(title: NSLocalizedString("Max Tendies Reached", comment: ""), body: String(format: NSLocalizedString("You can only apply %@ descriptors.", comment: ""), "\(PosterBoardManager.MaxTendies)"))
|
||||||
|
} else {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.downloadURL = url.absoluteString.replacingOccurrences(of: "pocketposter://download?url=", with: "")
|
||||||
|
UIApplication.shared.confirmAlert(title: NSLocalizedString("Download Tendies File", comment: ""), body: String(format: NSLocalizedString("Would you like to download the file %@?", comment: ""), "\(self.getWallpaperNameFromURL(string: self.downloadURL ?? "/Unknown"))"), onOK: {
|
||||||
|
self.downloadWallpaper()
|
||||||
|
}, noCancel: false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func downloadWallpaper() {
|
||||||
|
UIImpactFeedbackGenerator(style: .soft).impactOccurred()
|
||||||
|
UIApplication.shared.alert(title: NSLocalizedString("Downloading", comment: "") + " \(getWallpaperNameFromURL(string: downloadURL ?? "/Unknown"))...", body: NSLocalizedString("Please wait", comment: ""), animated: false, withButton: false)
|
||||||
|
|
||||||
|
Task {
|
||||||
|
do {
|
||||||
|
let newURL = try await downloadFromURL(string: downloadURL!)
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
PosterBoardManager.shared.selectedTendies.append(newURL)
|
||||||
|
Haptic.shared.notify(.success)
|
||||||
|
UIApplication.shared.dismissAlert(animated: false)
|
||||||
|
UIApplication.shared.alert(title: NSLocalizedString("Successfully downloaded wallpaper!", comment: ""), body: NSLocalizedString("Your downloaded .tendies will be on the Home page.", comment: "after successfully downloading tendies"))
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
Haptic.shared.notify(.error)
|
||||||
|
UIApplication.shared.dismissAlert(animated: false)
|
||||||
|
UIApplication.shared.alert(title: NSLocalizedString("Could not download wallpaper!", comment: ""), body: error.localizedDescription)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func downloadFromURL(_ url: URL) async throws -> URL {
|
||||||
print("Downloading from \(url.absoluteString)")
|
print("Downloading from \(url.absoluteString)")
|
||||||
|
|
||||||
let request = URLRequest(url: url)
|
let request = URLRequest(url: url)
|
||||||
@@ -24,12 +68,12 @@ class DownloadManager {
|
|||||||
return newURL
|
return newURL
|
||||||
}
|
}
|
||||||
|
|
||||||
static func downloadFromURL(string path: String) async throws -> URL {
|
func downloadFromURL(string path: String) async throws -> URL {
|
||||||
guard let url = URL(string: path) else { throw URLError(.unknown) }
|
guard let url = URL(string: path) else { throw URLError(.unknown) }
|
||||||
return try await downloadFromURL(url)
|
return try await downloadFromURL(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
static func copyTendies(from url: URL) throws -> URL {
|
func copyTendies(from url: URL) throws -> URL {
|
||||||
// scope the resource
|
// scope the resource
|
||||||
let accessing = url.startAccessingSecurityScopedResource()
|
let accessing = url.startAccessingSecurityScopedResource()
|
||||||
defer {
|
defer {
|
||||||
|
|||||||
@@ -3256,6 +3256,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"Explore" : {
|
||||||
|
|
||||||
},
|
},
|
||||||
"Extracting tendies..." : {
|
"Extracting tendies..." : {
|
||||||
"comment" : "happens when unzipping the files",
|
"comment" : "happens when unzipping the files",
|
||||||
|
|||||||
@@ -10,11 +10,11 @@ import SwiftUI
|
|||||||
@main
|
@main
|
||||||
struct Pocket_PosterApp: App {
|
struct Pocket_PosterApp: App {
|
||||||
// Prefs
|
// Prefs
|
||||||
|
@ObservedObject var dlManager = DownloadManager.shared
|
||||||
|
|
||||||
@AppStorage("finishedTutorial") var finishedTutorial: Bool = false
|
@AppStorage("finishedTutorial") var finishedTutorial: Bool = false
|
||||||
@AppStorage("pbHash") var pbHash: String = ""
|
@AppStorage("pbHash") var pbHash: String = ""
|
||||||
|
|
||||||
@State var downloadURL: String? = nil
|
|
||||||
|
|
||||||
var body: some Scene {
|
var body: some Scene {
|
||||||
WindowGroup {
|
WindowGroup {
|
||||||
Group {
|
Group {
|
||||||
@@ -29,17 +29,7 @@ struct Pocket_PosterApp: App {
|
|||||||
.onOpenURL(perform: { url in
|
.onOpenURL(perform: { url in
|
||||||
// Download URL
|
// Download URL
|
||||||
if url.absoluteString.starts(with: "pocketposter://download") {
|
if url.absoluteString.starts(with: "pocketposter://download") {
|
||||||
// prohibit to only tendies files
|
dlManager.startTendiesDownload(for: url)
|
||||||
if !url.absoluteString.hasSuffix(".tendies") {
|
|
||||||
UIApplication.shared.alert(body: NSLocalizedString("Only .tendies files can be downloaded!", comment: ""))
|
|
||||||
} else if PosterBoardManager.shared.selectedTendies.count >= PosterBoardManager.MaxTendies {
|
|
||||||
UIApplication.shared.alert(title: NSLocalizedString("Max Tendies Reached", comment: ""), body: String(format: NSLocalizedString("You can only apply %@ descriptors.", comment: ""), "\(PosterBoardManager.MaxTendies)"))
|
|
||||||
} else {
|
|
||||||
downloadURL = url.absoluteString.replacingOccurrences(of: "pocketposter://download?url=", with: "")
|
|
||||||
UIApplication.shared.confirmAlert(title: NSLocalizedString("Download Tendies File", comment: ""), body: String(format: NSLocalizedString("Would you like to download the file %@?", comment: ""), "\(DownloadManager.getWallpaperNameFromURL(string: downloadURL ?? "/Unknown"))"), onOK: {
|
|
||||||
downloadWallpaper()
|
|
||||||
}, noCancel: false)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// App Hash URL
|
// App Hash URL
|
||||||
else if url.absoluteString.starts(with: "pocketposter://app-hash?uuid=") {
|
else if url.absoluteString.starts(with: "pocketposter://app-hash?uuid=") {
|
||||||
@@ -51,7 +41,7 @@ struct Pocket_PosterApp: App {
|
|||||||
} else {
|
} else {
|
||||||
// copy it over to the KFC bucket
|
// copy it over to the KFC bucket
|
||||||
do {
|
do {
|
||||||
let newURL = try DownloadManager.copyTendies(from: url)
|
let newURL = try DownloadManager.shared.copyTendies(from: url)
|
||||||
PosterBoardManager.shared.selectedTendies.append(newURL)
|
PosterBoardManager.shared.selectedTendies.append(newURL)
|
||||||
Haptic.shared.notify(.success)
|
Haptic.shared.notify(.success)
|
||||||
UIApplication.shared.alert(title: String(format: NSLocalizedString("Successfully imported %@", comment: ""), "\(url.lastPathComponent)"), body: "")
|
UIApplication.shared.alert(title: String(format: NSLocalizedString("Successfully imported %@", comment: ""), "\(url.lastPathComponent)"), body: "")
|
||||||
@@ -65,24 +55,6 @@ struct Pocket_PosterApp: App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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!)
|
|
||||||
PosterBoardManager.shared.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() {
|
init() {
|
||||||
// clear the videos cache
|
// clear the videos cache
|
||||||
try? FileManager.default.removeItem(at: SymHandler.getDocumentsDirectory().appendingPathComponent("Videos", conformingTo: .directory))
|
try? FileManager.default.removeItem(at: SymHandler.getDocumentsDirectory().appendingPathComponent("Videos", conformingTo: .directory))
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
//
|
||||||
|
// WebView.swift
|
||||||
|
// Pocket Poster
|
||||||
|
//
|
||||||
|
// Created by lemin on 7/6/25.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import SwiftUI
|
||||||
|
import WebKit
|
||||||
|
|
||||||
|
struct WallpaperWebView: UIViewRepresentable {
|
||||||
|
let url: URL
|
||||||
|
|
||||||
|
init(_ url: URL) {
|
||||||
|
self.url = url
|
||||||
|
}
|
||||||
|
|
||||||
|
func makeUIView(context: Context) -> some UIView {
|
||||||
|
let configuration = WKWebViewConfiguration()
|
||||||
|
configuration.setURLSchemeHandler(AssetsSchemeHandler(), forURLScheme: "pocketposter")
|
||||||
|
let webView = WKWebView(frame: .zero, configuration: configuration)
|
||||||
|
webView.load(URLRequest(url: url))
|
||||||
|
|
||||||
|
return webView
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateUIView(_ uiView: UIViewType, context: Context) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class AssetsSchemeHandler: NSObject, WKURLSchemeHandler {
|
||||||
|
func webView(_ webView: WKWebView, start urlSchemeTask: WKURLSchemeTask) {
|
||||||
|
DispatchQueue.global().async {
|
||||||
|
print("handling scheme")
|
||||||
|
guard let url = urlSchemeTask.request.url, url.absoluteString.starts(with: "pocketposter://download") else { return }
|
||||||
|
|
||||||
|
print("url: \(url.absoluteString)")
|
||||||
|
DownloadManager.shared.startTendiesDownload(for: url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func webView(_ webView: WKWebView, stop urlSchemeTask: WKURLSchemeTask) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
//
|
||||||
|
// ExploreView.swift
|
||||||
|
// Pocket Poster
|
||||||
|
//
|
||||||
|
// Created by lemin on 7/6/25.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct ExploreView: View {
|
||||||
|
var body: some View {
|
||||||
|
WallpaperWebView(URL(string: "https://cowabun.ga/wallpapers?pocketposter=true")!)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,6 +22,10 @@ struct RootView: View {
|
|||||||
.tabItem {
|
.tabItem {
|
||||||
Label("CarPlay", systemImage: "car")
|
Label("CarPlay", systemImage: "car")
|
||||||
}
|
}
|
||||||
|
ExploreView()
|
||||||
|
.tabItem {
|
||||||
|
Label("Explore", systemImage: "safari")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user