Gemini/Gemini-iOS/UserActivities.swift

46 lines
1.2 KiB
Swift

//
// UserActivities.swift
// Gemini-iOS
//
// Created by Shadowfacts on 9/28/21.
//
import Foundation
import BrowserCore
private let type = "space.vaccor.Gemini.activity.browse"
private let encoder = PropertyListEncoder()
private let decoder = PropertyListDecoder()
extension NSUserActivity {
convenience init(geminiURL url: URL) {
self.init(activityType: type)
self.userInfo = [
"url": url,
]
}
convenience init(navigationManager manager: NavigationManager) {
self.init(activityType: type)
self.userInfo = [
"url": manager.currentURL,
]
if let data = try? encoder.encode(manager) {
self.userInfo!["manager"] = data
}
}
var navigationManager: NavigationManager? {
guard activityType == type,
let data = userInfo?["manager"] as? Data,
let manager = try? decoder.decode(NavigationManager.self, from: data) else { return nil }
return manager
}
var geminiURL: URL? {
guard activityType == type,
let url = userInfo?["url"] as? URL else { return nil }
return url
}
}