Skip to content

Commit c29993f

Browse files
authored
Dismiss presented vcs when subscribe route is detected (#3745)
2 parents 6efc66b + 8950f99 commit c29993f

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

podcasts/AppDelegate+UrlHandling.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,13 @@ extension AppDelegate {
169169

170170
// Support for subscribing to a feed URL
171171
JLRoutes.global().addRoute("/subscribe/*") { [weak self] parameters -> Bool in
172-
guard let strongSelf = self, let controller = SceneHelper.rootViewController(), let subscribeUrl = (parameters[JLRouteURLKey] as? URL)?.absoluteString else { return false }
172+
guard
173+
let strongSelf = self,
174+
let rootController = SceneHelper.rootViewController(includeTopMost: false), //I don't want to consider the top most presented but the main root instead
175+
let subscribeUrl = (parameters[JLRouteURLKey] as? URL)?.absoluteString
176+
else {
177+
return false
178+
}
173179

174180
let prefix = "pktc://subscribe/"
175181
if prefix.count >= subscribeUrl.count { return true } // this request is missing a URL
@@ -179,8 +185,8 @@ extension AppDelegate {
179185
let searchTerm = !feedUrl.hasPrefix("http://") && !feedUrl.hasPrefix("https://") ? "http://\(feedUrl)" : feedUrl
180186

181187
strongSelf.progressDialog = ShiftyLoadingAlert(title: L10n.podcastLoading)
182-
controller.dismiss(animated: false, completion: nil)
183-
strongSelf.progressDialog?.showAlert(controller, hasProgress: false, completion: {
188+
rootController.dismiss(animated: false, completion: nil)
189+
strongSelf.progressDialog?.showAlert(rootController, hasProgress: false, completion: {
184190
MainServerHandler.shared.podcastSearch(searchTerm: searchTerm) { response in
185191
guard let uuid = response?.result?.podcast?.uuid else {
186192
DispatchQueue.main.async {

podcasts/SceneHelper.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@ class SceneHelper {
2323
return UIWindow(frame: UIScreen.main.bounds)
2424
}
2525

26-
class func rootViewController() -> UIViewController? {
26+
class func rootViewController(includeTopMost: Bool = true) -> UIViewController? {
2727
let appScene = connectedScene()?.windows.first(where: { $0.rootViewController is MainTabBarController })
2828
let rootVC = appScene?.rootViewController
29-
return rootVC?.topMostPresentedViewController ?? rootVC
29+
if includeTopMost {
30+
return rootVC?.topMostPresentedViewController ?? rootVC
31+
}
32+
return rootVC
3033
}
3134

3235
/// Returns the main window for the app from the AppDelegate

0 commit comments

Comments
 (0)