2 * Copyright (C) 2023 by Claudio Cambra <claudio.cambra@nextcloud.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 import NCDesktopClientSocketKit
21 extension FileProviderExtension {
22 func sendFileProviderDomainIdentifier() {
23 let command = "FILE_PROVIDER_DOMAIN_IDENTIFIER_REQUEST_REPLY"
24 let argument = domain.identifier.rawValue
25 let message = command + ":" + argument + "\n"
26 socketClient?.sendMessage(message)
29 private func signalEnumeratorAfterAccountSetup() {
30 guard let fpManager = NSFileProviderManager(for: domain) else {
31 Logger.fileProviderExtension.error("Could not get file provider manager for domain \(self.domain.displayName, privacy: .public), cannot notify after account setup")
35 assert(ncAccount != nil)
37 fpManager.signalErrorResolved(NSFileProviderError(.notAuthenticated)) { error in
39 Logger.fileProviderExtension.error("Error resolving not authenticated, received error: \(error!.localizedDescription)")
43 Logger.fileProviderExtension.debug("Signalling enumerators for user \(self.ncAccount!.username) at server \(self.ncAccount!.serverUrl, privacy: .public)")
45 fpManager.signalEnumerator(for: .workingSet) { error in
47 Logger.fileProviderExtension.error("Error signalling enumerator for working set, received error: \(error!.localizedDescription, privacy: .public)")
52 func setupDomainAccount(user: String, serverUrl: String, password: String) {
53 ncAccount = NextcloudAccount(user: user, serverUrl: serverUrl, password: password)
54 ncKit.setup(user: ncAccount!.username,
55 userId: ncAccount!.username,
56 password: ncAccount!.password,
57 urlBase: ncAccount!.serverUrl,
58 userAgent: "Nextcloud-macOS/FileProviderExt",
60 delegate: nil) // TODO: add delegate methods for self
62 Logger.fileProviderExtension.info("Nextcloud account set up in File Provider extension for user: \(user, privacy: .public) at server: \(serverUrl, privacy: .public)")
64 signalEnumeratorAfterAccountSetup()
67 func removeAccountConfig() {
68 Logger.fileProviderExtension.info("Received instruction to remove account data for user \(self.ncAccount!.username, privacy: .public) at server \(self.ncAccount!.serverUrl, privacy: .public)")