RevealFileAction.swift 901 B

123456789101112131415161718192021222324252627282930313233
  1. import Foundation
  2. /// Reveals a file in the system's file manager.
  3. @MainActor
  4. public struct RevealFileAction {
  5. let backend: any BackendFeatures.RevealFiles
  6. init?<Backend: BaseAppBackend>(backend: Backend) {
  7. guard let backend = backend as? any BackendFeatures.RevealFiles else {
  8. return nil
  9. }
  10. self.backend = backend
  11. }
  12. /// Reveals a file in the system's file manager.
  13. ///
  14. /// This opens the file's enclosing directory and highlights the file.
  15. ///
  16. /// - Parameter file: The file to reveal.
  17. public func callAsFunction(_ file: URL) {
  18. do {
  19. try backend.revealFile(file)
  20. } catch {
  21. logger.warning(
  22. "failed to reveal file",
  23. metadata: [
  24. "url": "\(file)",
  25. "error": "\(error)",
  26. ]
  27. )
  28. }
  29. }
  30. }