Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Deeplinking): Deeplink parsing is now migrated to Scene delegate #1279

Merged
merged 5 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ let project = Project(name: "kDrive",
sources: [
"kDriveFileProvider/**",
"kDrive/Utils/AppFactoryService.swift",
"kDrive/Utils/AppExtensionRouter.swift",
"kDrive/Utils/NavigationManager.swift"
],
resources: [
Expand Down
6 changes: 0 additions & 6 deletions kDrive/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,6 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
Log.appDelegate("Unable to register for remote notifications: \(error.localizedDescription)", level: .error)
}

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
Log.appDelegate("application app open url\(url)")

return DeeplinkParser().parse(url: url)
}

func application(_ application: UIApplication,
open url: URL,
sourceApplication: String?,
Expand Down
47 changes: 47 additions & 0 deletions kDrive/AppRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import UIKit
import VersionChecker

public struct AppRouter: AppNavigable {
@LazyInjectService private var appExtensionRouter: AppExtensionRoutable
@LazyInjectService private var appRestorationService: AppRestorationServiceable
@LazyInjectService private var driveInfosManager: DriveInfosManager
@LazyInjectService private var keychainHelper: KeychainHelper
Expand Down Expand Up @@ -64,6 +65,41 @@ public struct AppRouter: AppNavigable {
return userInfo
}

// MARK: Routable

public func navigate(to route: NavigationRoutes) {
guard let rootViewController = window?.rootViewController else {
SentryDebug.captureNoWindow()
Log.sceneDelegate("NavigationManager: Unable to navigate without a root view controller", level: .error)
return
}

// Get presented view controller
var viewController = rootViewController
while let presentedViewController = viewController.presentedViewController {
viewController = presentedViewController
}

switch route {
case .saveFile(let file):
guard let driveFileManager = accountManager.currentDriveFileManager else {
Log.sceneDelegate("NavigationManager: Unable to navigate to .saveFile without a DriveFileManager", level: .error)
return
}

showSaveFileVC(from: viewController, driveFileManager: driveFileManager, file: file)

case .store(let driveId, let userId):
guard let driveFileManager = accountManager.getDriveFileManager(for: driveId, userId: userId) else {
Log.sceneDelegate("NavigationManager: Unable to navigate to .store without a DriveFileManager", level: .error)
return
}

// Show store
showStore(from: viewController, driveFileManager: driveFileManager)
}
}

// MARK: TopmostViewControllerFetchable

@MainActor public var topMostViewController: UIViewController? {
Expand Down Expand Up @@ -402,6 +438,17 @@ public struct AppRouter: AppNavigable {
navController.pushViewController(photoSyncSettingsViewController, animated: true)
}

public func showSaveFileVC(from viewController: UIViewController, driveFileManager: DriveFileManager, file: ImportedFile) {
let vc = SaveFileViewController.instantiateInNavigationController(driveFileManager: driveFileManager, file: file)
viewController.present(vc, animated: true)
}

// MARK: AppExtensionRouter

public func showStore(from viewController: UIViewController, driveFileManager: DriveFileManager) {
appExtensionRouter.showStore(from: viewController, driveFileManager: driveFileManager)
}

// MARK: RouterActionable

public func askUserToRemovePicturesIfNecessary() async {
Expand Down
14 changes: 14 additions & 0 deletions kDrive/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,20 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate, AccountManagerDel
return true
}

// MARK: - Deeplink

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
guard let url = URLContexts.first?.url else {
Log.sceneDelegate("scene unable to navigate to url", level: .error)
return
}

Task {
let success = await DeeplinkParser().parse(url: url)
Log.sceneDelegate("scene open url\(url) success:\(success)")
}
}

// MARK: - Handoff support

func scene(_ scene: UIScene, willContinueUserActivityWithType userActivityType: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ extension FileActionsFloatingPanelViewController {
floatingPanelViewController?.actionHandler = { [weak self] _ in
driveFloatingPanelController.dismiss(animated: true) {
guard let self else { return }
self.navigationManager.showStore(from: self, driveFileManager: self.driveFileManager)
self.router.showStore(from: self, driveFileManager: self.driveFileManager)
}
}
present(driveFloatingPanelController, animated: true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public class FloatingPanelAction: Equatable {

final class FileActionsFloatingPanelViewController: UICollectionViewController {
@LazyInjectService var accountManager: AccountManageable
@LazyInjectService var navigationManager: NavigationManageable
@LazyInjectService var router: AppNavigable

var driveFileManager: DriveFileManager!
var file: File!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ import kDriveResources
import UIKit

class ShareLinkSettingsViewController: UIViewController {
@LazyInjectService private var router: AppNavigable

@IBOutlet var tableView: UITableView!

@LazyInjectService var accountManager: AccountManageable
@LazyInjectService private var navigationManager: NavigationManageable

var driveFileManager: DriveFileManager!

Expand Down Expand Up @@ -258,7 +259,7 @@ extension ShareLinkSettingsViewController: UITableViewDelegate, UITableViewDataS
floatingPanelViewController?.rightButton.isEnabled = driveFileManager.drive.accountAdmin
floatingPanelViewController?.actionHandler = { _ in
driveFloatingPanelController.dismiss(animated: true) {
self.navigationManager.showStore(from: self, driveFileManager: self.driveFileManager)
self.router.showStore(from: self, driveFileManager: self.driveFileManager)
}
}
present(driveFloatingPanelController, animated: true)
Expand Down
4 changes: 2 additions & 2 deletions kDrive/UI/Controller/Home/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class HomeViewController: CustomLargeTitleCollectionViewController, UpdateAccoun
private static let loadingCellCount = 12

@LazyInjectService var accountManager: AccountManageable
@LazyInjectService var navigationManager: NavigationManageable
@LazyInjectService var router: AppNavigable

struct HomeViewModel {
let topRows: [HomeTopRow]
Expand Down Expand Up @@ -363,7 +363,7 @@ extension HomeViewController {
cell.configureCell(with: driveFileManager.drive)
cell.actionHandler = { [weak self] _ in
guard let self else { return }
navigationManager.showStore(from: self, driveFileManager: driveFileManager)
router.showStore(from: self, driveFileManager: driveFileManager)
}
cell.closeHandler = { [weak self] _ in
guard let self else { return }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import kDriveResources
import UIKit

class NewFolderTypeTableViewController: UITableViewController {
@LazyInjectService private var navigationManager: NavigationManageable
@LazyInjectService private var router: AppNavigable

var driveFileManager: DriveFileManager!
var currentDirectory: File!
Expand Down Expand Up @@ -116,7 +116,7 @@ class NewFolderTypeTableViewController: UITableViewController {
floatingPanelViewController?.actionHandler = { _ in
driveFloatingPanelController.dismiss(animated: true) { [weak self] in
guard let self else { return }
navigationManager.showStore(from: self, driveFileManager: driveFileManager)
router.showStore(from: self, driveFileManager: driveFileManager)
}
}
present(driveFloatingPanelController, animated: true)
Expand Down
36 changes: 36 additions & 0 deletions kDrive/Utils/AppExtensionRouter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Infomaniak kDrive - iOS App
Copyright (C) 2024 Infomaniak Network SA

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import CocoaLumberjackSwift
import Foundation
import kDriveCore

/// Routing methods available from both the AppExtension mode and App
public struct AppExtensionRouter: AppExtensionRoutable {
public func showStore(from viewController: UIViewController, driveFileManager: DriveFileManager) {
#if ISEXTENSION
UIConstants.openUrl(
"kdrive:store?userId=\(driveFileManager.apiFetcher.currentToken!.userId)&driveId=\(driveFileManager.drive.id)",
from: viewController
)
#else
let storeViewController = StoreViewController.instantiateInNavigationController(driveFileManager: driveFileManager)
viewController.present(storeViewController, animated: true)
#endif
}
}
6 changes: 3 additions & 3 deletions kDrive/Utils/AppFactoryService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public struct EarlyDIHook {
os_log("EarlyDIHook")

var extraDependencies = [
Factory(type: NavigationManageable.self) { _, _ in
NavigationManager()
},
Factory(type: AppContextServiceable.self) { _, _ in
AppContextService(context: context)
},
Factory(type: AppExtensionRoutable.self) { _, _ in
AppExtensionRouter()
}
]

Expand Down
4 changes: 2 additions & 2 deletions kDrive/Utils/FileActionsHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,8 @@ public final class FileActionsHelper {
floatingPanelViewController?.rightButton.isEnabled = driveFileManager.drive.accountAdmin
floatingPanelViewController?.actionHandler = { _ in
driveFloatingPanelController.dismiss(animated: true) {
@InjectService var navigationManager: NavigationManageable
navigationManager.showStore(from: viewController, driveFileManager: driveFileManager)
@InjectService var router: AppNavigable
router.showStore(from: viewController, driveFileManager: driveFileManager)
}
}
viewController.present(driveFloatingPanelController, animated: true)
Expand Down
84 changes: 0 additions & 84 deletions kDrive/Utils/NavigationManager.swift

This file was deleted.

12 changes: 11 additions & 1 deletion kDriveCore/Utils/AppNavigable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ public protocol RouterAppNavigable {
@MainActor func showUpdateRequired()

@MainActor func showPhotoSyncSettings()

@MainActor func showSaveFileVC(from viewController: UIViewController, driveFileManager: DriveFileManager, file: ImportedFile)
}

/// Routing methods available from both the AppExtension mode and App
public protocol AppExtensionRoutable {
/// Show native appstore inapp upsale in context
@MainActor func showStore(from viewController: UIViewController, driveFileManager: DriveFileManager)
}

/// Something that can present a File within the app
Expand Down Expand Up @@ -155,7 +163,9 @@ public protocol RouterActionable {
}

/// Something that can navigate within the kDrive app
public typealias AppNavigable = RouterActionable
public typealias AppNavigable = AppExtensionRoutable
& Routable
& RouterActionable
& RouterAppNavigable
& RouterFileNavigable
& RouterRootNavigable
Expand Down
Loading
Loading