Add state restoration for current account in main scene
This commit is contained in:
parent
806591f5b7
commit
ceb58f1d92
|
@ -65,6 +65,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||
}
|
||||
|
||||
switch type {
|
||||
case .mainScene:
|
||||
return "main-scene"
|
||||
|
||||
case .showConversation,
|
||||
.showTimeline,
|
||||
.checkNotifications,
|
||||
|
|
|
@ -69,6 +69,7 @@
|
|||
<string>$(PRODUCT_BUNDLE_IDENTIFIER).activity.bookmarks</string>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER).activity.my-profile</string>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER).activity.show-profile</string>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER).activity.main-scene</string>
|
||||
</array>
|
||||
<key>UIApplicationSceneManifest</key>
|
||||
<dict>
|
||||
|
|
|
@ -15,12 +15,15 @@ class MainSceneDelegate: UIResponder, UIWindowSceneDelegate {
|
|||
|
||||
var window: UIWindow?
|
||||
|
||||
private var launchActivity: NSUserActivity?
|
||||
|
||||
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
|
||||
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
|
||||
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
|
||||
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
|
||||
guard let windowScene = scene as? UIWindowScene else { return }
|
||||
|
||||
if let activity = connectionOptions.userActivities.first ?? session.stateRestorationActivity {
|
||||
launchActivity = activity
|
||||
}
|
||||
|
||||
window = UIWindow(windowScene: windowScene)
|
||||
|
||||
if let report = AppDelegate.pendingCrashReport {
|
||||
|
@ -91,6 +94,14 @@ class MainSceneDelegate: UIResponder, UIWindowSceneDelegate {
|
|||
DraftsManager.save()
|
||||
}
|
||||
|
||||
func stateRestorationActivity(for scene: UIScene) -> NSUserActivity? {
|
||||
if let mastodonController = window?.windowScene?.session.mastodonController {
|
||||
return UserActivityManager.mainSceneActivity(accountID: mastodonController.accountInfo!.id)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func sceneWillEnterForeground(_ scene: UIScene) {
|
||||
// Called as the scene transitions from the background to the foreground.
|
||||
// Use this method to undo the changes made on entering the background.
|
||||
|
@ -123,7 +134,14 @@ class MainSceneDelegate: UIResponder, UIWindowSceneDelegate {
|
|||
func showAppOrOnboardingUI(session: UISceneSession? = nil) {
|
||||
let session = session ?? window!.windowScene!.session
|
||||
if LocalData.shared.onboardingComplete {
|
||||
let account = LocalData.shared.getMostRecentAccount()!
|
||||
let account: LocalData.UserAccountInfo
|
||||
if let activity = launchActivity,
|
||||
let activityAccount = UserActivityManager.getAccount(from: activity) {
|
||||
account = activityAccount
|
||||
} else {
|
||||
account = LocalData.shared.getMostRecentAccount()!
|
||||
}
|
||||
|
||||
if session.mastodonController == nil {
|
||||
session.mastodonController = MastodonController.getForAccount(account)
|
||||
}
|
||||
|
|
|
@ -38,6 +38,15 @@ class UserActivityManager {
|
|||
return LocalData.shared.getAccount(id: id)
|
||||
}
|
||||
|
||||
// MARK: - Main Scene
|
||||
static func mainSceneActivity(accountID: String) -> NSUserActivity {
|
||||
let activity = NSUserActivity(type: .mainScene)
|
||||
activity.userInfo = [
|
||||
"accountID": accountID,
|
||||
]
|
||||
return activity
|
||||
}
|
||||
|
||||
// MARK: - New Post
|
||||
static func newPostActivity(mentioning: Account? = nil, accountID: String) -> NSUserActivity {
|
||||
// todo: update to use managed objects
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
import Foundation
|
||||
|
||||
enum UserActivityType: String {
|
||||
case mainScene = "space.vaccor.Tusker.activity.main-scene"
|
||||
case newPost = "space.vaccor.Tusker.activity.new-post"
|
||||
case checkNotifications = "space.vaccor.Tusker.activity.check-notifications"
|
||||
case showTimeline = "space.vaccor.Tusker.activity.show-timeline"
|
||||
|
@ -22,6 +23,8 @@ enum UserActivityType: String {
|
|||
extension UserActivityType {
|
||||
var handle: (NSUserActivity) -> Void {
|
||||
switch self {
|
||||
case .mainScene:
|
||||
fatalError("cannot handle main scene activity")
|
||||
case .newPost:
|
||||
return UserActivityManager.handleNewPost
|
||||
case .checkNotifications:
|
||||
|
|
Loading…
Reference in New Issue