diff --git a/Tusker/Scenes/ComposeSceneDelegate.swift b/Tusker/Scenes/ComposeSceneDelegate.swift index 9ee0b645..3836317a 100644 --- a/Tusker/Scenes/ComposeSceneDelegate.swift +++ b/Tusker/Scenes/ComposeSceneDelegate.swift @@ -7,11 +7,14 @@ // import UIKit +import Combine class ComposeSceneDelegate: UIResponder, UIWindowSceneDelegate { var window: UIWindow? + private var cancellables = Set() + func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { guard let windowScene = scene as? UIWindowScene else { return @@ -56,6 +59,11 @@ class ComposeSceneDelegate: UIResponder, UIWindowSceneDelegate { composeVC.delegate = self let nav = EnhancedNavigationViewController(rootViewController: composeVC) + updateTitle(draft: composeVC.draft) + composeVC.uiState.$draft + .sink { [unowned self] in self.updateTitle(draft: $0) } + .store(in: &cancellables) + window = UIWindow(windowScene: windowScene) window!.rootViewController = nav window!.makeKeyAndVisible() @@ -78,6 +86,19 @@ class ComposeSceneDelegate: UIResponder, UIWindowSceneDelegate { return scene.userActivity } + private func updateTitle(draft: Draft) { + guard let scene = window?.windowScene, + let mastodonController = scene.session.mastodonController else { + return + } + if let inReplyToID = draft.inReplyToID, + let inReplyTo = mastodonController.persistentContainer.status(for: inReplyToID) { + scene.title = "Reply to @\(inReplyTo.account.acct)" + } else { + scene.title = "New Post" + } + } + @objc private func themePrefChanged() { window?.overrideUserInterfaceStyle = Preferences.shared.theme } diff --git a/Tusker/Scenes/MainSceneDelegate.swift b/Tusker/Scenes/MainSceneDelegate.swift index 910dfb75..4de2434a 100644 --- a/Tusker/Scenes/MainSceneDelegate.swift +++ b/Tusker/Scenes/MainSceneDelegate.swift @@ -185,6 +185,15 @@ class MainSceneDelegate: UIResponder, UIWindowSceneDelegate, TuskerSceneDelegate LocalData.shared.setMostRecentAccount(account) window!.windowScene!.session.mastodonController = MastodonController.getForAccount(account) + // iPadOS shows the title below the App Name + // macOS uses the title as the window title, but uses the subtitle in addition to the default window title (the app name) + // so this way we get basically the same behavior on both + if ProcessInfo.processInfo.isiOSAppOnMac || ProcessInfo.processInfo.isMacCatalystApp { + window!.windowScene!.subtitle = account.instanceURL.host! + } else { + window!.windowScene!.title = account.instanceURL.host! + } + let newRoot = createAppUI() if let container = window?.rootViewController as? AccountSwitchingContainerViewController { let direction: AccountSwitchingContainerViewController.AnimationDirection