From a894eeeb4fac5e58ed7384bfad96370a25671531 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20H=C3=BChne?= Date: Tue, 19 Oct 2021 14:31:42 +0200 Subject: [PATCH 1/3] #4801 Skip "Manage" screen / automatically open "Files" screen after login via MDM parameter account.auto-connect --- ownCloud/SceneDelegate.swift | 20 +++++++---- .../ServerListTableViewController.swift | 34 +++++++++++++++++++ 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/ownCloud/SceneDelegate.swift b/ownCloud/SceneDelegate.swift index a2bcb6750..1717d15ae 100644 --- a/ownCloud/SceneDelegate.swift +++ b/ownCloud/SceneDelegate.swift @@ -60,6 +60,8 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { } else { configure(window: window, with: userActivity) } + } else if ServerListTableViewController.classSetting(forOCClassSettingsKey: .accountAutoConnect) as? Bool ?? false, let bookmark = OCBookmarkManager.shared.bookmark(at: 0) { + connect(to: bookmark) } } @@ -88,12 +90,9 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { @discardableResult func configure(window: ThemeWindow?, with activity: NSUserActivity) -> Bool { if let bookmarkUUIDString = activity.userInfo?[OCBookmark.ownCloudOpenAccountAccountUuidKey] as? String, let bookmarkUUID = UUID(uuidString: bookmarkUUIDString), - let bookmark = OCBookmarkManager.shared.bookmark(for: bookmarkUUID), - let navigationController = window?.rootViewController as? ThemeNavigationController, - let serverListController = navigationController.topViewController as? StateRestorationConnectProtocol { + let bookmark = OCBookmarkManager.shared.bookmark(for: bookmarkUUID) { if activity.title == OCBookmark.ownCloudOpenAccountPath { - serverListController.connect(to: bookmark, lastVisibleItemId: nil, animated: false, present: nil) - window?.windowScene?.userActivity = bookmark.openAccountUserActivity + connect(to: bookmark) return true } else if activity.title == OpenItemUserActivity.ownCloudOpenItemPath { @@ -102,8 +101,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { } // At first connect to the bookmark for the item - serverListController.connect(to: bookmark, lastVisibleItemId: itemLocalID, animated: false, present: nil) - window?.windowScene?.userActivity = activity + connect(to: bookmark, lastVisibleItemId: itemLocalID, activity: activity) return true } @@ -117,6 +115,14 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { return false } + func connect(to bookmark: OCBookmark, lastVisibleItemId: String? = nil, activity: NSUserActivity? = nil) { + if let navigationController = window?.rootViewController as? ThemeNavigationController, + let serverListController = navigationController.topViewController as? StateRestorationConnectProtocol { + serverListController.connect(to: bookmark, lastVisibleItemId: lastVisibleItemId, animated: false, present: nil) + window?.windowScene?.userActivity = activity ?? bookmark.openAccountUserActivity + } + } + func scene(_ scene: UIScene, openURLContexts URLContexts: Set) { if let firstURL = URLContexts.first?.url { // Ensure the set isn't empty if !OCAuthenticationBrowserSessionCustomScheme.handleOpen(firstURL), // No custom scheme URL handling for this URL diff --git a/ownCloud/Server List/ServerListTableViewController.swift b/ownCloud/Server List/ServerListTableViewController.swift index 101f30f1a..d73341c7a 100644 --- a/ownCloud/Server List/ServerListTableViewController.swift +++ b/ownCloud/Server List/ServerListTableViewController.swift @@ -991,3 +991,37 @@ extension ServerListTableViewController: UITableViewDragDelegate { extension NSNotification.Name { static let BookmarkMessageCountChanged = NSNotification.Name("boomark.message-count.changed") } + +// MARK: - OCClassSettings support +extension OCClassSettingsIdentifier { + static let account = OCClassSettingsIdentifier("account") +} + +extension OCClassSettingsKey { + static let accountAutoConnect = OCClassSettingsKey("auto-connect") +} + +extension ServerListTableViewController : OCClassSettingsSupport { + static let classSettingsIdentifier : OCClassSettingsIdentifier = .account + + static func defaultSettings(forIdentifier identifier: OCClassSettingsIdentifier) -> [OCClassSettingsKey : Any]? { + if identifier == .account { + return [ + .accountAutoConnect : false + ] + } + + return nil + } + + static func classSettingsMetadata() -> [OCClassSettingsKey : [OCClassSettingsMetadataKey : Any]]? { + return [ + .accountAutoConnect : [ + .type : OCClassSettingsMetadataType.boolean, + .description : "Skip \"Account\" screen / automatically open \"Files\" screen after login", + .category : "Account", + .status : OCClassSettingsKeyStatus.supported + ] + ] + } +} From a1764d20b52f3c626d1fd1a15511c81cc0a36afd Mon Sep 17 00:00:00 2001 From: Felix Schwarz Date: Wed, 20 Oct 2021 09:06:39 +0200 Subject: [PATCH 2/3] - SceneDelegate: use .first (which returns nil in case there are no bookmarks) instead of bookmark(at: 0) (which crashes in case there are no bookmarks because the array is empty and the method tries to access an item at index 0) --- ownCloud/SceneDelegate.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ownCloud/SceneDelegate.swift b/ownCloud/SceneDelegate.swift index 1717d15ae..c514272b5 100644 --- a/ownCloud/SceneDelegate.swift +++ b/ownCloud/SceneDelegate.swift @@ -60,7 +60,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { } else { configure(window: window, with: userActivity) } - } else if ServerListTableViewController.classSetting(forOCClassSettingsKey: .accountAutoConnect) as? Bool ?? false, let bookmark = OCBookmarkManager.shared.bookmark(at: 0) { + } else if ServerListTableViewController.classSetting(forOCClassSettingsKey: .accountAutoConnect) as? Bool ?? false, let bookmark = OCBookmarkManager.shared.bookmarks.first { connect(to: bookmark) } } From 0925c025902e5d14812b8d37d08475a147f9a6a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20H=C3=BChne?= Date: Wed, 20 Oct 2021 14:25:56 +0200 Subject: [PATCH 3/3] added auto-connect after every setup, not only the first setup --- .../Interface/StaticLoginSetupViewController.swift | 4 +++- .../Static Login/Interface/StaticLoginViewController.swift | 4 ---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/ownCloud/Static Login/Interface/StaticLoginSetupViewController.swift b/ownCloud/Static Login/Interface/StaticLoginSetupViewController.swift index 5f41d8531..4e28d553d 100644 --- a/ownCloud/Static Login/Interface/StaticLoginSetupViewController.swift +++ b/ownCloud/Static Login/Interface/StaticLoginSetupViewController.swift @@ -361,7 +361,9 @@ class StaticLoginSetupViewController : StaticLoginStepViewController { OCBookmarkManager.shared.addBookmark(bookmark) self.loginViewController?.showFirstScreen() - //self.pushSuccessViewController() + if ServerListTableViewController.classSetting(forOCClassSettingsKey: .accountAutoConnect) as? Bool ?? false { + self.loginViewController?.openBookmark(bookmark) + } } else { var issue : OCIssue? let nsError = error as NSError? diff --git a/ownCloud/Static Login/Interface/StaticLoginViewController.swift b/ownCloud/Static Login/Interface/StaticLoginViewController.swift index 9390ab7d7..922539ba1 100644 --- a/ownCloud/Static Login/Interface/StaticLoginViewController.swift +++ b/ownCloud/Static Login/Interface/StaticLoginViewController.swift @@ -332,10 +332,6 @@ class StaticLoginViewController: UIViewController, Themeable, StateRestorationCo // PushTransition correctly restores the view serverList?.pushFromViewController = self - if let bookmark = bookmark { - serverList?.connect(to: bookmark, lastVisibleItemId: lastVisibleItemId, animated: false) - } - return serverList! }