forked from shadowfacts/Tusker
Add window titles to main and compose scenes
This commit is contained in:
parent
0a1dc423d4
commit
86143c5887
|
@ -7,11 +7,14 @@
|
|||
//
|
||||
|
||||
import UIKit
|
||||
import Combine
|
||||
|
||||
class ComposeSceneDelegate: UIResponder, UIWindowSceneDelegate {
|
||||
|
||||
var window: UIWindow?
|
||||
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
|
||||
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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue