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/fp-no-account] Show message in File Provider if no account has been set up #1306

Merged
merged 2 commits into from
Dec 1, 2023
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
2 changes: 1 addition & 1 deletion ios-sdk
8 changes: 5 additions & 3 deletions ownCloud File Provider UI/CancelLabelViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ class CancelLabelViewController: UIViewController {
@IBOutlet var label : UILabel!
@IBOutlet var button : ThemeButton!

var cancelAction: (() -> Void)?
typealias CancelAction = (() -> Void)

func updateCancelLabels(with message: String) {
var cancelAction: CancelAction?

func updateCancelLabels(with message: String, buttonLabel: String? = nil) {
let collection = Theme.shared.activeCollection

view.cssSelector = .toolbar
Expand All @@ -38,7 +40,7 @@ class CancelLabelViewController: UIViewController {
label.apply(css: collection.css, properties: [.stroke])

self.label.text = message
self.button.setTitle("Cancel".localized, for: .normal)
self.button.setTitle(buttonLabel ?? "Cancel".localized, for: .normal)
}

@IBAction func cancelScreen() {
Expand Down
44 changes: 32 additions & 12 deletions ownCloud File Provider UI/DocumentActionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class DocumentActionViewController: FPUIActionExtensionViewController {

prepareNavigationController()

showCancelLabel(with: "Connecting…".localized)
showMessage(with: "Connecting…".localized)

var actionTypeLabel = ""
var actionExtensionType : ActionExtensionType = .undefined
Expand Down Expand Up @@ -139,7 +139,7 @@ class DocumentActionViewController: FPUIActionExtensionViewController {

OnMainThread {
if actionExtensionType == .sharing, core.connection.capabilities?.sharingAPIEnabled == false || item.isShareable == false {
self.showCancelLabel(with: String(format: "%@ is not available for this item.".localized, actionTypeLabel))
self.showMessage(with: String(format: "%@ is not available for this item.".localized, actionTypeLabel))
} else if core.connectionStatus == .online {
self.coreConnectionStatusObservation?.invalidate()
self.coreConnectionStatusObservation = nil
Expand All @@ -157,18 +157,18 @@ class DocumentActionViewController: FPUIActionExtensionViewController {
}
} else if core.connectionStatus == .connecting {
triedConnecting = true
self.showCancelLabel(with: "Connecting…".localized)
self.showMessage(with: "Connecting…".localized)
} else if core.connectionStatus == .offline || core.connectionStatus == .unavailable {
// Display error if `.connecting` isn't reached within 2 seconds
OnMainThread(after: 2) {
if !triedConnecting {
self.showCancelLabel(with: String(format: "%@ is not available, when this account is offline. Please open the app and log into your account before you can do this action.".localized, actionTypeLabel))
self.showMessage(with: String(format: "%@ is not available, when this account is offline. Please open the app and log into your account before you can do this action.".localized, actionTypeLabel))
}
}

// Display error if `.connecting` has already been reached
if triedConnecting {
self.showCancelLabel(with: String(format: "%@ is not available, when this account is offline. Please open the app and log into your account before you can do this action.".localized, actionTypeLabel))
self.showMessage(with: String(format: "%@ is not available, when this account is offline. Please open the app and log into your account before you can do this action.".localized, actionTypeLabel))
}
}
}
Expand All @@ -180,7 +180,18 @@ class DocumentActionViewController: FPUIActionExtensionViewController {
override func prepare(forError error: Error) {
if !OCFileProviderSettings.browseable {
prepareNavigationController()
showCancelLabel(with: "File Provider access has been disabled by the administrator.\n\nPlease use the app to access your files.".localized)
showMessage(with: "File Provider access has been disabled by the administrator.\n\nPlease use the app to access your files.".localized)
return
}

if OCBookmarkManager.shared.bookmarks.count == 0 {
prepareNavigationController()
showMessage(with: "No account has been set up in the {{app.name}} app yet.".localized, buttonLabel: "Open app".localized, action: { [weak self] in
if let appURLScheme = OCAppIdentity.shared.appURLSchemes?.first {
self?.extensionContext.open(URL(string: "\(appURLScheme)://fp-no-account")!)
}
self?.complete()
})
return
}

Expand All @@ -197,20 +208,29 @@ class DocumentActionViewController: FPUIActionExtensionViewController {
AppLockManager.shared.showLockscreenIfNeeded()
} else {
prepareNavigationController()
showCancelLabel(with: "Passcode protection is not supported on this device.\nPlease disable passcode lock in the app settings.".localized)
showMessage(with: "Passcode protection is not supported on this device.\nPlease disable passcode lock in the app settings.".localized)
}
}

func showCancelLabel(with message: String) {
func showMessage(with message: String, buttonLabel: String? = nil, action: CancelLabelViewController.CancelAction? = nil) {
OnMainThread {
var messageController: CancelLabelViewController?

if let currentController = self.themeNavigationController?.viewControllers.first as? CancelLabelViewController {
currentController.updateCancelLabels(with: message)
messageController = currentController
} else if let cancelLabelViewController = UIStoryboard.init(name: "MainInterface", bundle: nil).instantiateViewController(withIdentifier: "CancelLabelViewController") as? CancelLabelViewController {
cancelLabelViewController.updateCancelLabels(with: message)
cancelLabelViewController.cancelAction = { [weak self] in
messageController = cancelLabelViewController
}

if let messageController {
messageController.updateCancelLabels(with: message, buttonLabel: buttonLabel)
messageController.cancelAction = action ?? { [weak self] in
self?.complete(cancelWith: NSError(domain: FPUIErrorDomain, code: Int(FPUIExtensionErrorCode.userCancelled.rawValue), userInfo: nil))
}
self.themeNavigationController?.viewControllers = [ cancelLabelViewController ]

if self.themeNavigationController?.viewControllers.first != messageController {
self.themeNavigationController?.viewControllers = [ messageController ]
}
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions ownCloud/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,10 @@
"File Provider access has been disabled by the administrator. Please use the app to create new folders." = "File Provider access has been disabled by the administrator. Please use the app to create new folders.";
"File Provider access has been disabled by the administrator. Please use the share extension to import files." = "File Provider access has been disabled by the administrator. Please use the share extension to import files.";

/* - No account */
"No account has been set up in the {{app.name}} app yet." = "No account has been set up in the {{app.name}} app yet.";
"Open app" = "Open app";

/* Disallowed Import Methods */
/* - Share Extension */
"Share Extension disabled" = "Share Extension disabled";
Expand Down
Loading