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

[feature/mdm-auto-connect] Skip Account Screen via MDM #1056

Merged
merged 3 commits into from
Nov 8, 2021
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
20 changes: 13 additions & 7 deletions ownCloud/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.bookmarks.first {
connect(to: bookmark)
}
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -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<UIOpenURLContext>) {
if let firstURL = URLContexts.first?.url { // Ensure the set isn't empty
if !OCAuthenticationBrowserSessionCustomScheme.handleOpen(firstURL), // No custom scheme URL handling for this URL
Expand Down
34 changes: 34 additions & 0 deletions ownCloud/Server List/ServerListTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!
}

Expand Down