2021-04-08 12:52:35 +02:00
|
|
|
//
|
|
|
|
// SafariActivity.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by MainasuK Cirno on 2021-4-8.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
import SafariServices
|
2022-01-27 14:23:39 +01:00
|
|
|
import MastodonAsset
|
|
|
|
import MastodonLocalization
|
2021-04-08 12:52:35 +02:00
|
|
|
|
|
|
|
final class SafariActivity: UIActivity {
|
|
|
|
|
|
|
|
weak var sceneCoordinator: SceneCoordinator?
|
|
|
|
var url: NSURL?
|
|
|
|
|
|
|
|
init(sceneCoordinator: SceneCoordinator) {
|
|
|
|
self.sceneCoordinator = sceneCoordinator
|
|
|
|
}
|
|
|
|
|
|
|
|
override var activityType: UIActivity.ActivityType? {
|
2021-06-11 22:37:54 +02:00
|
|
|
return UIActivity.ActivityType("org.joinmastodon.app.safari-activity")
|
2021-04-08 12:52:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override var activityTitle: String? {
|
2022-03-10 09:20:42 +01:00
|
|
|
return UserDefaults.shared.preferredUsingDefaultBrowser ? L10n.Common.Controls.Actions.openInBrowser : L10n.Common.Controls.Actions.openInSafari
|
2021-04-08 12:52:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override var activityImage: UIImage? {
|
|
|
|
return UIImage(systemName: "safari")
|
|
|
|
}
|
|
|
|
|
|
|
|
override func canPerform(withActivityItems activityItems: [Any]) -> Bool {
|
|
|
|
for item in activityItems {
|
|
|
|
guard let _ = item as? NSURL, sceneCoordinator != nil else { continue }
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
override func prepare(withActivityItems activityItems: [Any]) {
|
|
|
|
for item in activityItems {
|
|
|
|
guard let url = item as? NSURL else { continue }
|
|
|
|
self.url = url
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override var activityViewController: UIViewController? {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
override func perform() {
|
|
|
|
guard let url = url else {
|
|
|
|
activityDidFinish(false)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-01-27 14:23:39 +01:00
|
|
|
Task {
|
|
|
|
await sceneCoordinator?.present(scene: .safari(url: url as URL), from: nil, transition: .safariPresent(animated: true, completion: nil))
|
|
|
|
activityDidFinish(true)
|
|
|
|
}
|
2021-04-08 12:52:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|