From 7ba8f2c943ae858791302bcda7a8afb91fd713b0 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 27 Feb 2024 20:28:27 +0800 Subject: [PATCH] Move serviceConnection method to table view data source Signed-off-by: Claudio Cambra --- .../ShareTableViewDataSource.swift | 19 +++++++++++++++++++ .../ShareViewController.swift | 19 ------------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareTableViewDataSource.swift b/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareTableViewDataSource.swift index 4ab42ac4d..77fc2e42f 100644 --- a/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareTableViewDataSource.swift +++ b/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareTableViewDataSource.swift @@ -20,4 +20,23 @@ class ShareTableViewDataSource: NSObject, NSTableViewDataSource { private var shares: [NKShare] = [] { didSet { sharesTableView?.reloadData() } } + + private func serviceConnection(url: URL) async throws -> FPUIExtensionService { + let services = try await FileManager().fileProviderServicesForItem(at: url) + guard let service = services[fpUiExtensionServiceName] else { + Logger.sharesDataSource.error("Couldn't get service, required service not present") + throw NSFileProviderError(.providerNotFound) + } + let connection: NSXPCConnection + connection = try await service.fileProviderConnection() + connection.remoteObjectInterface = NSXPCInterface(with: FPUIExtensionService.self) + connection.interruptionHandler = { + Logger.sharesDataSource.error("Service connection interrupted") + } + connection.resume() + guard let proxy = connection.remoteObjectProxy as? FPUIExtensionService else { + throw NSFileProviderError(.serverUnreachable) + } + return proxy + } } diff --git a/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareViewController.swift b/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareViewController.swift index bd7d48fa1..fb5058ec9 100644 --- a/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareViewController.swift +++ b/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareViewController.swift @@ -87,23 +87,4 @@ class ShareViewController: NSViewController { } fileNameIcon.image = fileThumbnail?.nsImage } - - private func serviceConnection(url: URL) async throws -> FPUIExtensionService { - let services = try await FileManager().fileProviderServicesForItem(at: url) - guard let service = services[fpUiExtensionServiceName] else { - Logger.shareViewController.error("Couldn't get service, required service not present") - throw NSFileProviderError(.providerNotFound) - } - let connection: NSXPCConnection - connection = try await service.fileProviderConnection() - connection.remoteObjectInterface = NSXPCInterface(with: FPUIExtensionService.self) - connection.interruptionHandler = { - Logger.shareViewController.error("Service connection interrupted") - } - connection.resume() - guard let proxy = connection.remoteObjectProxy as? FPUIExtensionService else { - throw NSFileProviderError(.serverUnreachable) - } - return proxy - } } -- 2.30.2