OpenWindowAction.swift 898 B

123456789101112131415161718192021222324252627282930
  1. /// An action that opens a window with the specified ID.
  2. @MainActor
  3. public struct OpenWindowAction {
  4. let environment: EnvironmentValues
  5. /// Opens the window with the specified ID.
  6. public func callAsFunction(id: String) {
  7. guard environment.backend.supportsMultipleWindows else {
  8. logger.warning(
  9. """
  10. openWindow(id:) called but the backend doesn't support \
  11. multi-window, ignoring
  12. """
  13. )
  14. return
  15. }
  16. guard let openWindow = environment.openWindowFunctionsByID.value[id] else {
  17. logger.warning(
  18. """
  19. openWindow(id:) called with an ID that does not have an \
  20. associated window
  21. """,
  22. metadata: ["id": "\(id)"]
  23. )
  24. return
  25. }
  26. openWindow()
  27. }
  28. }