Compare commits

..

3 Commits

3 changed files with 23 additions and 10 deletions

View File

@ -20,7 +20,11 @@ public final class ComposeController: ViewController {
public typealias ReplyContentView = (any StatusProtocol, @escaping (CGFloat) -> Void) -> AnyView
public typealias EmojiImageView = (Emoji) -> AnyView
@Published public private(set) var draft: Draft
@Published public private(set) var draft: Draft {
didSet {
assert(draft.managedObjectContext == DraftsPersistentContainer.shared.viewContext)
}
}
@Published public var config: ComposeUIConfig
@Published public var mastodonController: ComposeMastodonContext
let fetchAvatar: AvatarImageView.FetchAvatar
@ -106,6 +110,7 @@ public final class ComposeController: ViewController {
emojiImageView: @escaping EmojiImageView
) {
self.draft = draft
assert(draft.managedObjectContext == DraftsPersistentContainer.shared.viewContext)
self.config = config
self.mastodonController = mastodonController
self.fetchAvatar = fetchAvatar

View File

@ -35,7 +35,7 @@ class MainSceneDelegate: UIResponder, UIWindowSceneDelegate, TuskerSceneDelegate
window = UIWindow(windowScene: windowScene)
showAppOrOnboardingUI(session: session)
if connectionOptions.urlContexts.count > 0 {
if !connectionOptions.urlContexts.isEmpty {
self.scene(scene, openURLContexts: connectionOptions.urlContexts)
}
@ -50,14 +50,21 @@ class MainSceneDelegate: UIResponder, UIWindowSceneDelegate, TuskerSceneDelegate
}
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
if URLContexts.count > 1 {
fatalError("Cannot open more than 1 URL")
guard let url = URLContexts.first?.url,
var components = URLComponents(url: url, resolvingAgainstBaseURL: false),
let rootViewController else {
return
}
let url = URLContexts.first!.url
if var components = URLComponents(url: url, resolvingAgainstBaseURL: false),
let rootViewController = rootViewController {
if components.host == "compose" {
if let mastodonController = window!.windowScene!.session.mastodonController {
let draft = mastodonController.createDraft()
let text = components.queryItems?.first(where: { $0.name == "text" })?.value
draft.text = text ?? ""
rootViewController.compose(editing: draft, animated: true, isDucked: false)
}
} else {
// Assume anything else is a search query
components.scheme = "https"
let query = components.string!
rootViewController.performSearch(query: query)

View File

@ -211,9 +211,10 @@ extension TimelineLikeCollectionViewController {
extension TimelineLikeCollectionViewController {
// apply(_:animatingDifferences:) is marked as nonisolated, so just awaiting it doesn't dispatch to the main thread, unlike other async @MainActor methods
// but we always want to update the data source on the main thread for consistency, so this method does that
@MainActor
func apply(_ snapshot: NSDiffableDataSourceSnapshot<Section, Item>, animatingDifferences: Bool) async {
await self.dataSource.apply(snapshot, animatingDifferences: animatingDifferences)
await MainActor.run {
dataSource?.apply(snapshot, animatingDifferences: animatingDifferences)
}
}
@MainActor