From: Claudio Cambra Date: Tue, 30 Jul 2024 10:51:48 +0000 (+0800) Subject: Process target item on init of lock view controller X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~6^2~22^2~14 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=72ec0d5f1f9738e30897d1bd55ac0230aa82280a;p=nextcloud-desktop.git Process target item on init of lock view controller Signed-off-by: Claudio Cambra --- diff --git a/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/Locking/LockViewController.swift b/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/Locking/LockViewController.swift index 369ac0256..4116ff7bc 100644 --- a/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/Locking/LockViewController.swift +++ b/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/Locking/LockViewController.swift @@ -29,6 +29,16 @@ class LockViewController: NSViewController { self.itemIdentifiers = itemIdentifiers self.locking = locking super.init(nibName: nil, bundle: nil) + + guard let firstItem = itemIdentifiers.first else { + Logger.shareViewController.error("called without items") + closeAction(self) + return + } + + Task { + await processItemIdentifier(firstItem) + } } required init?(coder: NSCoder) { @@ -44,6 +54,27 @@ class LockViewController: NSViewController { descriptionLabel.stringValue = "Error: \(error)" } + private func processItemIdentifier(_ itemIdentifier: NSFileProviderItemIdentifier) async { + guard let manager = NSFileProviderManager(for: actionViewController.domain) else { + fatalError("NSFileProviderManager isn't expected to fail") + } + + do { + let itemUrl = try await manager.getUserVisibleURL(for: itemIdentifier) + guard itemUrl.startAccessingSecurityScopedResource() else { + Logger.lockViewController.error("Could not access scoped resource for item url!") + return + } + await updateFileDetailsDisplay(itemUrl: itemUrl) + itemUrl.stopAccessingSecurityScopedResource() + } catch let error { + let errorString = "Error processing item: \(error)" + Logger.lockViewController.error("\(errorString, privacy: .public)") + fileNameLabel.stringValue = "Could not lock unknown item…" + descriptionLabel.stringValue = errorString + } + } + private func updateFileDetailsDisplay(itemUrl: URL) async { let lockAction = locking ? "Locking" : "Unlocking" fileNameLabel.stringValue = "\(lockAction) file \(itemUrl.lastPathComponent)…"