2021-04-08 12:52:35 +02:00
|
|
|
//
|
|
|
|
// SafariActivity.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by MainasuK Cirno on 2021-4-8.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
import SafariServices
|
|
|
|
|
|
|
|
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? {
|
|
|
|
return L10n.Common.Controls.Actions.openInSafari
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
sceneCoordinator?.present(scene: .safari(url: url as URL), from: nil, transition: .safariPresent(animated: true, completion: nil))
|
|
|
|
activityDidFinish(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|