Skip to content

Commit

Permalink
- Shortcuts:
Browse files Browse the repository at this point in the history
	- improved error reporting for when the target of a shortcut can't be accessed / found
	- simplified and generalized prompt for opening the URL a shortcut points to
  • Loading branch information
felix-schwarz committed Apr 18, 2024
1 parent 37421d5 commit a3cd1ad
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ class CreateShortcutFileViewController: CollectionViewController {
core.retrievePrivateLink(for: item, completionHandler: { [weak self] error, privateLinkURL in
if let error {
OnMainThread {
let alertController = ThemedAlertController(with: "An error occurred".localized, message: error.localizedDescription, okLabel: "OK".localized, action: nil)
let alertController = ThemedAlertController(with: "Error".localized, message: error.localizedDescription, okLabel: "OK".localized, action: nil)
self?.clientContext?.present(alertController, animated: true)
}
return
Expand Down Expand Up @@ -293,7 +293,7 @@ class CreateShortcutFileViewController: CollectionViewController {
func completed(with error: Error? = nil) {
OnMainThread(inline: true) {
if let error {
let alertController = ThemedAlertController(with: "An error occurred".localized, message: error.localizedDescription, okLabel: "OK".localized, action: nil)
let alertController = ThemedAlertController(with: "Error".localized, message: error.localizedDescription, okLabel: "OK".localized, action: nil)
self.clientContext?.present(alertController, animated: true)
} else if self.presentingViewController != nil {
self.dismiss(animated: true, completion: nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ class OpenShortcutFileAction: Action {

func open(error: Error? = nil, url: URL? = nil, item: OCItem? = nil) {
if let error {
let alertController = ThemedAlertController(with: "An error occurred".localized, message: error.localizedDescription, okLabel: "OK".localized, action: nil)
let alertController = ThemedAlertController(with: "Error".localized, message: error.localizedDescription, okLabel: "OK".localized, action: nil)
self.context.viewController?.present(alertController, animated: true)
} else if let item {
_ = item.openItem(from: context.viewController, with: context.clientContext, animated: true, pushViewController: true, completion: nil)
} else if let url {
let alert = ThemedAlertController(title: "Shortcut to '{{hostname}}'".localized(["hostname" : url.host ?? "URL"]), message: "This shortcut points to:\n\n{{url}}\n\nShould it be opened in the default browser?".localized(["url" : url.absoluteString]), preferredStyle: .alert)
let alert = ThemedAlertController(title: "Shortcut to '{{hostname}}'".localized(["hostname" : url.host ?? "URL"]), message: "This shortcut points to:\n{{url}}".localized(["url" : url.absoluteString]), preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Open link".localized, style: .default, handler: { _ in
UIApplication.shared.open(url) { success in
if !success {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ShortcutFileDisplayViewController: DisplayViewController {
INIFile.resolveShortcutFile(at: itemDirectURL, core: core, result: { [weak self] error, url, item in
OnMainThread {
if let error {
let alertController = ThemedAlertController(with: "An error occurred".localized, message: error.localizedDescription, okLabel: "OK".localized, action: nil)
let alertController = ThemedAlertController(with: "Error".localized, message: error.localizedDescription, okLabel: "OK".localized, action: nil)
self?.present(alertController, animated: true)
} else if item != nil {
self?.presentShortcutWith(item: item)
Expand Down
3 changes: 2 additions & 1 deletion ownCloud/Resources/de.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,8 @@
"Opening link failed" = "Öffnen des Links fehlgeschlagen";
"Open shortcut" = "Verknüpfung öffnen";
"Shortcut to '{{hostname}}'" = "Verknüpfung zu '{{hostname}}'";
"This shortcut points to:\n\n{{url}}\n\nShould it be opened in the default browser?" = "Diese Verknüpfung zeigt auf:\n\n{{url}}\n\nIm Standardbrowser öffnen?";
"This shortcut points to:\n{{url}}" = "Diese Verknüpfung verweist auf:\n{{url}}";
"The destination this shortcut points to could not be found. It may have been deleted or you may not have access to it." = "Das Ziel, auf das diese Verknüpfung verweist, konnte nicht gefunden werden. Möglicherweise wurde es gelöscht oder Sie haben keinen Zugriff darauf.";

"Create shortcut" = "Verknüpfung erstellen";
"URL of webpage or item" = "URL der Webseite oder Datei";
Expand Down
3 changes: 2 additions & 1 deletion ownCloud/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,8 @@
"Opening link failed" = "Opening link failed";
"Open shortcut" = "Open shortcut";
"Shortcut to '{{hostname}}'" = "Shortcut to '{{hostname}}'";
"This shortcut points to:\n\n{{url}}\n\nShould it be opened in the default browser?" = "This shortcut points to:\n\n{{url}}\n\nShould it be opened in the default browser?";
"This shortcut points to:\n{{url}}" = "This shortcut points to:\n{{url}}";
"The destination this shortcut points to could not be found. It may have been deleted or you may not have access to it." = "The destination this shortcut points to could not be found. It may have been deleted or you may not have access to it.";

"Create shortcut" = "Create shortcut";
"URL of webpage or item" = "URL of webpage or item";
Expand Down
8 changes: 7 additions & 1 deletion ownCloud/Shortcut Files/INIFile+ShortcutResolution.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@ public extension INIFile {
if let url = INIFile(with: data).url {
if url.privateLinkItemID != nil {
core.retrieveItem(forPrivateLink: url, completionHandler: { error, item in
var effectiveError = error

if let nsError = error as? NSError, nsError.isOCError(withCode: .itemDestinationNotFound) {
effectiveError = NSError(domain: OCErrorDomain, code: Int(OCError.itemDestinationNotFound.rawValue), userInfo: [NSLocalizedDescriptionKey : "The destination this shortcut points to could not be found. It may have been deleted or you may not have access to it.".localized])
}

OnMainThread {
handler(error, (item != nil) ? nil : url, item)
handler(effectiveError, (item != nil) ? nil : url, item)
}
})
} else {
Expand Down

0 comments on commit a3cd1ad

Please sign in to comment.