From e042754be17db0f21ab3ed14d8c156d18c8889bf Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 25 Feb 2023 16:44:36 -0500 Subject: [PATCH] Fix crash when restoring state for timeline VC --- Tusker/Shortcuts/UserActivityManager.swift | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Tusker/Shortcuts/UserActivityManager.swift b/Tusker/Shortcuts/UserActivityManager.swift index 6240e837..3e3d97fa 100644 --- a/Tusker/Shortcuts/UserActivityManager.swift +++ b/Tusker/Shortcuts/UserActivityManager.swift @@ -213,25 +213,26 @@ class UserActivityManager { func handleShowTimeline(activity: NSUserActivity) { guard let (timeline, positionInfo) = Self.getTimeline(from: activity) else { return } - let timelineVC: TimelineViewController + var timelineVC: TimelineViewController? if let pinned = PinnedTimeline(timeline: timeline), mastodonController.accountPreferences.pinnedTimelines.contains(pinned) { context.select(route: .timelines) context.popToRoot() let pageController = context.topViewController as! TimelinesPageViewController pageController.selectTimeline(pinned, animated: false) - timelineVC = pageController.currentViewController as! TimelineViewController + timelineVC = pageController.currentViewController as? TimelineViewController } else if case .list(let id) = timeline { context.select(route: .list(id: id)) - timelineVC = context.topViewController! as! TimelineViewController + timelineVC = context.topViewController as? TimelineViewController } else { context.select(route: .explore) context.popToRoot() timelineVC = TimelineViewController(for: timeline, mastodonController: mastodonController) - context.push(timelineVC) + context.push(timelineVC!) } - if let positionInfo, + if let timelineVC, + let positionInfo, context.isHandoff { Task { await timelineVC.restoreStateFromHandoff(statusIDs: positionInfo.statusIDs, centerStatusID: positionInfo.centerStatusID)