Add window titles to main and compose scenes

This commit is contained in:
Shadowfacts 2022-12-22 15:02:49 -05:00
parent 0a1dc423d4
commit 86143c5887
2 changed files with 30 additions and 0 deletions

View File

@ -7,11 +7,14 @@
// //
import UIKit import UIKit
import Combine
class ComposeSceneDelegate: UIResponder, UIWindowSceneDelegate { class ComposeSceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow? var window: UIWindow?
private var cancellables = Set<AnyCancellable>()
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = scene as? UIWindowScene else { guard let windowScene = scene as? UIWindowScene else {
return return
@ -56,6 +59,11 @@ class ComposeSceneDelegate: UIResponder, UIWindowSceneDelegate {
composeVC.delegate = self composeVC.delegate = self
let nav = EnhancedNavigationViewController(rootViewController: composeVC) 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 = UIWindow(windowScene: windowScene)
window!.rootViewController = nav window!.rootViewController = nav
window!.makeKeyAndVisible() window!.makeKeyAndVisible()
@ -78,6 +86,19 @@ class ComposeSceneDelegate: UIResponder, UIWindowSceneDelegate {
return scene.userActivity 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() { @objc private func themePrefChanged() {
window?.overrideUserInterfaceStyle = Preferences.shared.theme window?.overrideUserInterfaceStyle = Preferences.shared.theme
} }

View File

@ -185,6 +185,15 @@ class MainSceneDelegate: UIResponder, UIWindowSceneDelegate, TuskerSceneDelegate
LocalData.shared.setMostRecentAccount(account) LocalData.shared.setMostRecentAccount(account)
window!.windowScene!.session.mastodonController = MastodonController.getForAccount(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() let newRoot = createAppUI()
if let container = window?.rootViewController as? AccountSwitchingContainerViewController { if let container = window?.rootViewController as? AccountSwitchingContainerViewController {
let direction: AccountSwitchingContainerViewController.AnimationDirection let direction: AccountSwitchingContainerViewController.AnimationDirection