forked from shadowfacts/Tusker
Add Open in New Window menu item to profiles
This commit is contained in:
parent
40f5be28f6
commit
c8a45d8eef
|
@ -37,7 +37,8 @@ extension MenuPreviewProvider {
|
|||
guard let mastodonController = mastodonController,
|
||||
let account = mastodonController.persistentContainer.account(for: accountID) else { return [] }
|
||||
|
||||
guard mastodonController.loggedIn else {
|
||||
guard let loggedInAccountID = mastodonController.accountInfo?.id else {
|
||||
// user is logged out
|
||||
return [
|
||||
openInSafariAction(url: account.url),
|
||||
createAction(identifier: "share", title: "Share", systemImageName: "square.and.arrow.up", handler: { [weak self, weak sourceView] (_) in
|
||||
|
@ -90,7 +91,7 @@ extension MenuPreviewProvider {
|
|||
}))
|
||||
}
|
||||
|
||||
let shareSection = [
|
||||
var shareSection = [
|
||||
openInSafariAction(url: account.url),
|
||||
createAction(identifier: "share", title: "Share", systemImageName: "square.and.arrow.up", handler: { [weak self, weak sourceView] (_) in
|
||||
guard let self = self else { return }
|
||||
|
@ -98,6 +99,8 @@ extension MenuPreviewProvider {
|
|||
})
|
||||
]
|
||||
|
||||
addOpenInNewWindow(actions: &shareSection, activity: UserActivityManager.showProfileActivity(id: accountID, accountID: loggedInAccountID))
|
||||
|
||||
return [
|
||||
UIMenu(title: "", image: nil, identifier: nil, options: [.displayInline], children: shareSection),
|
||||
UIMenu(title: "", image: nil, identifier: nil, options: [.displayInline], children: actionsSection),
|
||||
|
@ -139,7 +142,8 @@ extension MenuPreviewProvider {
|
|||
func actionsForStatus(_ status: StatusMO, sourceView: UIView?, includeReply: Bool = true) -> [UIMenuElement] {
|
||||
guard let mastodonController = mastodonController else { return [] }
|
||||
|
||||
guard mastodonController.loggedIn else {
|
||||
guard let accountID = mastodonController.accountInfo?.id else {
|
||||
// user is logged out
|
||||
return [
|
||||
openInSafariAction(url: status.url!),
|
||||
createAction(identifier: "share", title: "Share", systemImageName: "square.and.arrow.up", handler: { [weak self, weak sourceView] (_) in
|
||||
|
@ -216,15 +220,7 @@ extension MenuPreviewProvider {
|
|||
}),
|
||||
]
|
||||
|
||||
if UIDevice.current.userInterfaceIdiom == .pad || UIDevice.current.userInterfaceIdiom == .mac {
|
||||
shareSection.append(createAction(identifier: "new_window", title: "Open in New Window", systemImageName: "rectangle.badge.plus", handler: { (_) in
|
||||
guard let id = mastodonController.accountInfo?.id else {
|
||||
return
|
||||
}
|
||||
// todo: this should try to find an existing session
|
||||
UIApplication.shared.requestSceneSessionActivation(nil, userActivity: UserActivityManager.showConversationActivity(mainStatusID: status.id, accountID: id), options: nil, errorHandler: nil)
|
||||
}))
|
||||
}
|
||||
addOpenInNewWindow(actions: &shareSection, activity: UserActivityManager.showConversationActivity(mainStatusID: status.id, accountID: accountID))
|
||||
|
||||
return [
|
||||
UIMenu(title: "", image: nil, identifier: nil, options: [.displayInline], children: shareSection),
|
||||
|
@ -248,6 +244,28 @@ extension MenuPreviewProvider {
|
|||
})
|
||||
}
|
||||
|
||||
private func addOpenInNewWindow(actions: inout [UIAction], activity: @escaping @autoclosure () -> NSUserActivity) {
|
||||
#if SDK_IOS_15
|
||||
if #available(iOS 15.0, *) {
|
||||
let options = UIWindowScene.ActivationRequestOptions()
|
||||
options.preferredPresentationStyle = .automatic
|
||||
actions.append(UIWindowScene.ActivationAction { (_) in
|
||||
return .init(userActivity: activity(), options: options, preview: nil)
|
||||
})
|
||||
} else if UIDevice.current.userInterfaceIdiom == .pad || UIDevice.current.userInterfaceIdiom == .mac {
|
||||
actions.append(createAction(identifier: "new_window", title: "Open in New Window", systemImageName: "rectangle.badge.plus", handler: { (_) in
|
||||
UIApplication.shared.requestSceneSessionActivation(nil, userActivity: activity(), options: nil, errorHandler: nil)
|
||||
}))
|
||||
}
|
||||
#else
|
||||
if UIDevice.current.userInterfaceIdiom == .pad || UIDevice.current.userInterfaceIdiom == .mac {
|
||||
actions.append(createAction(identifier: "new_window", title: "Open in New Window", systemImageName: "rectangle.badge.plus", handler: { (_) in
|
||||
UIApplication.shared.requestSceneSessionActivation(nil, userActivity: activity(), options: nil, errorHandler: nil)
|
||||
}))
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension LargeImageViewController: CustomPreviewPresenting {
|
||||
|
|
Loading…
Reference in New Issue