Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions Sources/ExtensionKit/iMastExtensionKit.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//
// iMastExtensionKit.swift
//
// iMast https://github.com/cinderella-project/iMast
//
// Created by user on 2025/07/01.
//
// ------------------------------------------------------------------------
//
// Copyright 2017-2021 rinsuki and other contributors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import Foundation
import ExtensionKit

public struct SocialUser: Codable {
public var uri: String
public var acct: String

public init(uri: String, acct: String) {
self.uri = uri
self.acct = acct
}
}

public struct SocialPost: Codable {
public var uri: String
public var author: SocialUser

public init(uri: String, author: SocialUser) {
self.uri = uri
self.author = author
}
}

public enum PostActionResult: Codable {
case composeReply(text: String)
}

public protocol _SocialExtension: AnyObject, Sendable, AppExtension {

}

extension _SocialExtension {
}

public protocol PostActionExtension: _SocialExtension {
func performAction(for post: SocialPost) -> PostActionResult?
}

extension PostActionExtension {
public var configuration: ConnectionHandler {
return ConnectionHandler { request in
request.accept { [weak self] (post: SocialPost) in
return self?.performAction(for: post)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import UIKit
import Mew
import Ikemen
import iMastiOSCore
import ExtensionFoundation
import iMastExtensionKit

class MastodonPostDetailReactionBarViewController: UIViewController, Instantiatable, Injectable {
typealias Input = MastodonPost
Expand Down Expand Up @@ -126,32 +128,74 @@ class MastodonPostDetailReactionBarViewController: UIViewController, Instantiata
}

func buildOthersMenu() async throws -> [UIMenuElement] {
var elements = [UICommand]()
var elements = [UIMenuElement]()
let version = try await environment.getIntVersion()
if version.supportingFeature(.bookmark) {
if input.bookmarked {
elements.append(.init(title: "ブックマークから削除", image: UIImage(systemName: "bookmark.slash"), action: #selector(removeFromBookmark)))
elements.append(UICommand(title: "ブックマークから削除", image: UIImage(systemName: "bookmark.slash"), action: #selector(removeFromBookmark)))
} else {
elements.append(.init(title: "ブックマーク", image: UIImage(systemName: "bookmark"), action: #selector(addToBookmark)))
elements.append(UICommand(title: "ブックマーク", image: UIImage(systemName: "bookmark"), action: #selector(addToBookmark)))
}
}
if version.supportingFeature(.editPost) {
if input.account.acct == environment.screenName {
elements.append(.init(title: L10n.NewPost.edit, image: UIImage(systemName: "pencil"), action: #selector(openEditPostVC)))
elements.append(UICommand(title: L10n.NewPost.edit, image: UIImage(systemName: "pencil"), action: #selector(openEditPostVC)))
}
}
elements.append(.init(title: L10n.Localizable.PostDetail.share, image: UIImage(systemName: "square.and.arrow.up"), action: #selector(openShareSheet)))
elements.append(.init(title: L10n.Localizable.Bunmyaku.title, image: UIImage(systemName: "list.bullet.indent"), action: #selector(openBunmyakuVC)))
elements.append(UICommand(title: L10n.Localizable.PostDetail.share, image: UIImage(systemName: "square.and.arrow.up"), action: #selector(openShareSheet)))
if #available(iOS 26, *) {
elements.append(UIMenu(title: "拡張機能", image: UIImage(systemName: "puzzlepiece.extension"), children: [UIDeferredMenuElement({ callback in
Task {
let monitor = try? await AppExtensionPoint.Monitor(appExtensionPoint: .postActionExtension)
var items: [UIMenuElement] = []
for identity in monitor?.identities ?? [] {
items.append(UIAction(title: identity.localizedName, handler: { _ in
self.handleExtension(identity: identity)
}))
}
await MainActor.run {
callback(items)
}
}
})]))
}
elements.append(UICommand(title: L10n.Localizable.Bunmyaku.title, image: UIImage(systemName: "list.bullet.indent"), action: #selector(openBunmyakuVC)))
if input.hasCustomEmoji {
elements.append(.init(title: L10n.Localizable.CustomEmojis.title, action: #selector(openEmojiListVC)))
elements.append(UICommand(title: L10n.Localizable.CustomEmojis.title, action: #selector(openEmojiListVC)))
}
if environment.screenName == input.account.acct {
elements.append(.init(title: L10n.Localizable.PostDetail.delete, image: UIImage(systemName: "trash"), action: #selector(confirmDeletePost), attributes: .destructive))
elements.append(UICommand(title: L10n.Localizable.PostDetail.delete, image: UIImage(systemName: "trash"), action: #selector(confirmDeletePost), attributes: .destructive))
}
elements.append(.init(title: L10n.Localizable.PostDetail.reportAbuse, image: UIImage(systemName: "exclamationmark.bubble"), action: #selector(openAbuseVC)))
elements.append(UICommand(title: L10n.Localizable.PostDetail.reportAbuse, image: UIImage(systemName: "exclamationmark.bubble"), action: #selector(openAbuseVC)))
return elements
}

@available(iOS 26, *)
func handleExtension(identity: AppExtensionIdentity) {
let input = self.input.originalPost
Task {
let config = AppExtensionProcess.Configuration(appExtensionIdentity: identity)
let proc = try await AppExtensionProcess(configuration: config)
let connection = try proc.makeXPCSession()
try connection.activate()
try connection.send(SocialPost(uri: "", author: .init(uri: "", acct: input.account.acct))) { (result: Result<PostActionResult, any Error>) in
switch result {
case .success(.composeReply(let text)):
DispatchQueue.main.async {
let post = self.input.originalPost
self.showAsWindow(userActivity: .init(newPostWithMastodonUserToken: self.environment) ※ {
$0.setNewPostReplyInfo(post)
$0.newPostSuffix = text
}, fallback: .push)
}
default:
print(result)
}
connection.cancel(reason: "")
}
}
}

@objc func openReplyVC() {
let post = self.input.originalPost
showAsWindow(userActivity: .init(newPostWithMastodonUserToken: environment) ※ {
Expand Down
33 changes: 33 additions & 0 deletions Sources/iOS/App/ExternalExtensionSupport/ExtensionPoint.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// ExtensionPoint.swift
//
// iMast https://github.com/cinderella-project/iMast
//
// Created by user on 2025/07/01.
//
// ------------------------------------------------------------------------
//
// Copyright 2017-2021 rinsuki and other contributors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import ExtensionFoundation

@available(iOS 26.0, *)
extension AppExtensionPoint {
@Definition
public static var postActionExtension: AppExtensionPoint {
Name("PostActionV1")
Scope(restriction: .none)
}
}
20 changes: 20 additions & 0 deletions Sources/iOS/App/Screens/OtherMenu/Settings/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import SwiftUI
import iMastiOSCore
import SDWebImage
import SafariServices
import ExtensionKit

class NewSettingsViewController: UIHostingController<SettingsView> {
init() {
Expand Down Expand Up @@ -393,13 +394,32 @@ struct DeveloperSettingsView: View {
Button("OK") {
}
}
if #available(iOS 26.0, *) {
NavigationLink {
ExtensionManageView()
} label: {
Text("Manage Extensions")
}
}
}
}
.attach(errorReporter: errorReporter)
.navigationTitle("内部設定")
}
}

@available(iOS 26.0, *)
struct ExtensionManageView: View, UIViewControllerRepresentable {
typealias UIViewControllerType = EXAppExtensionBrowserViewController

func makeUIViewController(context: Context) -> UIViewControllerType {
EXAppExtensionBrowserViewController()
}

func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) {
}
}

struct SettingsView_Previews: PreviewProvider {
static var previews: some View {
SettingsView()
Expand Down
Loading
Loading