2024-02-20 15:03:50 +03:00
|
|
|
//
|
|
|
|
// DocumentActionViewController.swift
|
|
|
|
// FileProviderUIExt
|
|
|
|
//
|
|
|
|
// Created by Claudio Cambra on 20/2/24.
|
|
|
|
//
|
|
|
|
|
|
|
|
import FileProviderUI
|
2024-02-21 12:20:48 +03:00
|
|
|
import OSLog
|
2024-02-20 15:03:50 +03:00
|
|
|
|
|
|
|
class DocumentActionViewController: FPUIActionExtensionViewController {
|
2024-02-21 13:48:42 +03:00
|
|
|
var domain: NSFileProviderDomain {
|
|
|
|
guard let identifier = extensionContext.domainIdentifier else {
|
|
|
|
fatalError("not expected to be called with default domain")
|
|
|
|
}
|
|
|
|
return NSFileProviderDomain(
|
|
|
|
identifier: NSFileProviderDomainIdentifier(rawValue: identifier.rawValue),
|
|
|
|
displayName: ""
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2024-02-21 12:44:49 +03:00
|
|
|
func prepare(childViewController: NSViewController) {
|
|
|
|
addChild(childViewController)
|
|
|
|
view.addSubview(childViewController.view)
|
|
|
|
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
view.leadingAnchor.constraint(equalTo: childViewController.view.leadingAnchor),
|
|
|
|
view.trailingAnchor.constraint(equalTo: childViewController.view.trailingAnchor),
|
|
|
|
view.topAnchor.constraint(equalTo: childViewController.view.topAnchor),
|
|
|
|
view.bottomAnchor.constraint(equalTo: childViewController.view.bottomAnchor)
|
|
|
|
])
|
|
|
|
}
|
|
|
|
|
2024-02-21 12:20:48 +03:00
|
|
|
override func prepare(
|
|
|
|
forAction actionIdentifier: String, itemIdentifiers: [NSFileProviderItemIdentifier]
|
|
|
|
) {
|
2024-04-17 20:58:38 +03:00
|
|
|
Logger.actionViewController.info("Preparing action: \(actionIdentifier, privacy: .public)")
|
2024-02-20 15:03:50 +03:00
|
|
|
|
2024-07-30 11:20:10 +03:00
|
|
|
switch (actionIdentifier) {
|
|
|
|
case "com.nextcloud.desktopclient.FileProviderUIExt.ShareAction":
|
2024-02-21 12:58:39 +03:00
|
|
|
prepare(childViewController: ShareViewController(itemIdentifiers))
|
2024-07-30 11:20:10 +03:00
|
|
|
case "com.nextcloud.desktopclient.FileProviderUIExt.LockFileAction":
|
2024-07-30 12:15:43 +03:00
|
|
|
prepare(childViewController: LockViewController(itemIdentifiers, locking: true))
|
2024-07-30 11:20:10 +03:00
|
|
|
case "com.nextcloud.desktopclient.FileProviderUIExt.UnlockFileAction":
|
2024-07-30 12:15:43 +03:00
|
|
|
prepare(childViewController: LockViewController(itemIdentifiers, locking: false))
|
2024-07-30 11:20:10 +03:00
|
|
|
default:
|
|
|
|
return
|
2024-02-21 12:45:20 +03:00
|
|
|
}
|
2024-02-20 15:03:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
override func prepare(forError error: Error) {
|
2024-04-17 20:58:38 +03:00
|
|
|
Logger.actionViewController.info(
|
2024-07-30 11:20:10 +03:00
|
|
|
"Preparing for error: \(error.localizedDescription, privacy: .public)"
|
2024-04-17 20:58:38 +03:00
|
|
|
)
|
2024-02-20 15:03:50 +03:00
|
|
|
}
|
|
|
|
|
2024-02-21 12:21:50 +03:00
|
|
|
override public func loadView() {
|
|
|
|
self.view = NSView()
|
|
|
|
}
|
2024-02-20 15:03:50 +03:00
|
|
|
}
|
|
|
|
|