ReadKeep/readeck/UI/readeckApp.swift
Ilyas Hallak 82f9d8a5a9 feat: Add URL Share Extension with API integration
- Add ShareViewController with complete URL extraction logic
- Support URL sharing from Safari, Chrome and other apps
- Extract URLs from different content types (URL, plain text, property list)
- Implement direct API call to create bookmarks from share extension
- Add Core Data integration to fetch authentication token
- Include proper error handling and user feedback with alerts
- Support title extraction and user text input for bookmark creation

Technical implementation:
- Handle UTType.url, UTType.plainText, and UTType.propertyList
- Async/await pattern for API requests
- NSDataDetector for URL extraction from text
- Property list parsing for Safari-style sharing
- Loading and success/error alerts for better UX
2025-06-12 23:21:55 +02:00

50 lines
1.4 KiB
Swift

//
// readeckApp.swift
// readeck
//
// Created by Ilyas Hallak on 10.06.25.
//
import SwiftUI
@main
struct readeckApp: App {
let persistenceController = PersistenceController.shared
var body: some Scene {
WindowGroup {
MainTabView()
.environment(\.managedObjectContext, persistenceController.container.viewContext)
.onOpenURL { url in
handleIncomingURL(url)
}
}
}
private func handleIncomingURL(_ url: URL) {
guard url.scheme == "readeck",
url.host == "add-bookmark" else {
return
}
let components = URLComponents(url: url, resolvingAgainstBaseURL: true)
let queryItems = components?.queryItems
let urlToAdd = queryItems?.first(where: { $0.name == "url" })?.value
let title = queryItems?.first(where: { $0.name == "title" })?.value
let notes = queryItems?.first(where: { $0.name == "notes" })?.value
// Öffne AddBookmarkView mit den Daten
// Hier kannst du eine Notification posten oder einen State ändern
NotificationCenter.default.post(
name: NSNotification.Name("AddBookmarkFromShare"),
object: nil,
userInfo: [
"url": urlToAdd ?? "",
"title": title ?? "",
"notes": notes ?? ""
]
)
}
}