From 29262345cd3d20eeae133ea2f25f2f068a2e4f62 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Mon, 4 Mar 2024 20:41:01 +0800 Subject: [PATCH] Add functionality to share controller to save changes Signed-off-by: Claudio Cambra --- .../Extensions/Logger+Extensions.swift | 1 + .../FileProviderUIExt/ShareController.swift | 29 +++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/Extensions/Logger+Extensions.swift b/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/Extensions/Logger+Extensions.swift index 63ff845a69..c668e3a8dd 100644 --- a/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/Extensions/Logger+Extensions.swift +++ b/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/Extensions/Logger+Extensions.swift @@ -11,6 +11,7 @@ extension Logger { private static var subsystem = Bundle.main.bundleIdentifier! static let actionViewController = Logger(subsystem: subsystem, category: "actionViewController") + static let shareController = Logger(subsystem: subsystem, category: "shareController") static let sharesDataSource = Logger(subsystem: subsystem, category: "sharesDataSource") static let shareViewController = Logger(subsystem: subsystem, category: "shareViewController") } diff --git a/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareController.swift b/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareController.swift index fdd4b5a8a2..4a51d609a7 100644 --- a/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareController.swift +++ b/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareController.swift @@ -5,15 +5,40 @@ // Created by Claudio Cambra on 4/3/24. // +import Combine import Foundation import NextcloudKit +import OSLog -class ShareController { - let share: NKShare +class ShareController: ObservableObject { + @Published private(set) var share: NKShare private let kit: NextcloudKit init(share: NKShare, kit: NextcloudKit) { self.share = share self.kit = kit } + + func save() async -> NKError? { + return await withCheckedContinuation { continuation in + kit.updateShare( + idShare: share.idShare, + password: share.password, + expireDate: share.expirationDateString ?? "", + permissions: share.permissions, + note: share.note, + label: share.label, + hideDownload: share.hideDownload, + attributes: share.attributes + ) { account, share, data, error in + Logger.shareController.info("Received update response: \(share?.url ?? "")") + defer { continuation.resume(returning: error) } + guard error == .success, let share = share else { + Logger.shareController.error("Error updating save: \(error.errorDescription)") + return + } + self.share = share + } + } + } }