2021-09-29 01:03:37 +00:00
|
|
|
//
|
|
|
|
// UserActivities.swift
|
|
|
|
// Gemini-iOS
|
|
|
|
//
|
|
|
|
// Created by Shadowfacts on 9/28/21.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import BrowserCore
|
|
|
|
|
2021-10-02 14:53:05 +00:00
|
|
|
private let type = "space.vaccor.Gemini.activity.browse"
|
2021-09-29 02:13:28 +00:00
|
|
|
private let encoder = PropertyListEncoder()
|
|
|
|
private let decoder = PropertyListDecoder()
|
2021-09-29 01:03:37 +00:00
|
|
|
|
|
|
|
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,
|
|
|
|
]
|
2021-09-29 02:13:28 +00:00
|
|
|
if let data = try? encoder.encode(manager) {
|
|
|
|
self.userInfo!["manager"] = data
|
|
|
|
}
|
2021-09-29 01:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var navigationManager: NavigationManager? {
|
|
|
|
guard activityType == type,
|
2021-09-29 02:13:28 +00:00
|
|
|
let data = userInfo?["manager"] as? Data,
|
|
|
|
let manager = try? decoder.decode(NavigationManager.self, from: data) else { return nil }
|
2021-09-29 01:03:37 +00:00
|
|
|
return manager
|
|
|
|
}
|
|
|
|
|
|
|
|
var geminiURL: URL? {
|
|
|
|
guard activityType == type,
|
|
|
|
let url = userInfo?["url"] as? URL else { return nil }
|
|
|
|
return url
|
|
|
|
}
|
|
|
|
}
|