From aee5ff01cbf00605e56ebfa210abe7d683729f4c Mon Sep 17 00:00:00 2001 From: Davide Baldo Date: Tue, 12 Dec 2023 19:04:18 +0100 Subject: [PATCH] fix: app - fixed a bug for ventura preventing windows from opening --- .../ockam_app/Ockam.xcodeproj/project.pbxproj | 8 ++-- .../ockam/ockam_app/Ockam/GuidedIntro.swift | 6 +++ .../ockam_app/Ockam/LocalPortalView.swift | 5 +- .../ockam/ockam_app/Ockam/MainView.swift | 13 +++-- .../ockam/ockam_app/Ockam/OckamApp.swift | 48 +++++++++++++++++-- .../ockam_app/Ockam/RemotePortalView.swift | 5 +- 6 files changed, 69 insertions(+), 16 deletions(-) diff --git a/implementations/swift/ockam/ockam_app/Ockam.xcodeproj/project.pbxproj b/implementations/swift/ockam/ockam_app/Ockam.xcodeproj/project.pbxproj index 11ea983862c..7bd85bf4911 100644 --- a/implementations/swift/ockam/ockam_app/Ockam.xcodeproj/project.pbxproj +++ b/implementations/swift/ockam/ockam_app/Ockam.xcodeproj/project.pbxproj @@ -351,7 +351,7 @@ INFOPLIST_KEY_CFBundleDisplayName = Ockam; INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities"; "LIBRARY_SEARCH_PATHS[arch=*]" = ../../../../target/debug/; - MACOSX_DEPLOYMENT_TARGET = 13.1; + MACOSX_DEPLOYMENT_TARGET = 13.5; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = YES; @@ -412,7 +412,7 @@ INFOPLIST_KEY_CFBundleDisplayName = Ockam; INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities"; "LIBRARY_SEARCH_PATHS[arch=*]" = ../../../../target/release/; - MACOSX_DEPLOYMENT_TARGET = 13.1; + MACOSX_DEPLOYMENT_TARGET = 13.5; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = YES; @@ -449,7 +449,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); - MACOSX_DEPLOYMENT_TARGET = 13.1; + MACOSX_DEPLOYMENT_TARGET = 13.5; MARKETING_VERSION = 0.1; PRODUCT_BUNDLE_IDENTIFIER = io.ockam.Ockam; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -485,7 +485,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); - MACOSX_DEPLOYMENT_TARGET = 13.1; + MACOSX_DEPLOYMENT_TARGET = 13.5; MARKETING_VERSION = 0.1; MTL_ENABLE_DEBUG_INFO = YES; PRODUCT_BUNDLE_IDENTIFIER = io.ockam.Ockam; diff --git a/implementations/swift/ockam/ockam_app/Ockam/GuidedIntro.swift b/implementations/swift/ockam/ockam_app/Ockam/GuidedIntro.swift index 1b44f30f2c0..01a6e7f0e84 100644 --- a/implementations/swift/ockam/ockam_app/Ockam/GuidedIntro.swift +++ b/implementations/swift/ockam/ockam_app/Ockam/GuidedIntro.swift @@ -113,6 +113,7 @@ For more information check out the [user guide](https://docs.ockam.io/reference/ height: VerticalSpacingUnit*4 ) } + .controlSize(.large) .keyboardShortcut(.defaultAction) .padding(.vertical, VerticalSpacingUnit) } else if status == OrchestratorStatus.Connecting || @@ -128,6 +129,7 @@ For more information check out the [user guide](https://docs.ockam.io/reference/ ) .focusable() } + .controlSize(.large) .keyboardShortcut(.defaultAction) .padding(.vertical, VerticalSpacingUnit) } @@ -147,6 +149,7 @@ For more information check out the [user guide](https://docs.ockam.io/reference/ height: VerticalSpacingUnit*4 ) } + .controlSize(.large) Button(action: { page += 1 @@ -158,6 +161,7 @@ For more information check out the [user guide](https://docs.ockam.io/reference/ height: VerticalSpacingUnit*4 ) } + .controlSize(.large) .keyboardShortcut(.defaultAction) } Spacer() @@ -173,6 +177,7 @@ For more information check out the [user guide](https://docs.ockam.io/reference/ height: VerticalSpacingUnit*4 ) } + .controlSize(.large) .keyboardShortcut(.defaultAction) Spacer() } else { @@ -189,6 +194,7 @@ For more information check out the [user guide](https://docs.ockam.io/reference/ ) .focusable() } + .controlSize(.large) .keyboardShortcut(.defaultAction) .padding(.vertical, VerticalSpacingUnit) } diff --git a/implementations/swift/ockam/ockam_app/Ockam/LocalPortalView.swift b/implementations/swift/ockam/ockam_app/Ockam/LocalPortalView.swift index c8be50b0f0b..009f996e020 100644 --- a/implementations/swift/ockam/ockam_app/Ockam/LocalPortalView.swift +++ b/implementations/swift/ockam/ockam_app/Ockam/LocalPortalView.swift @@ -76,7 +76,10 @@ struct LocalPortalView: View { ClickableMenuEntry( text: "Share…", action: { - openWindow(id: "invite-to-portal", value: localService.id) + OpenWindowWorkaround.shared.openWindow( + windowName: "invite-to-portal", + value: localService.id + ) bringInFront() self.closeWindow() }) diff --git a/implementations/swift/ockam/ockam_app/Ockam/MainView.swift b/implementations/swift/ockam/ockam_app/Ockam/MainView.swift index c090df138ca..dfc21185a97 100644 --- a/implementations/swift/ockam/ockam_app/Ockam/MainView.swift +++ b/implementations/swift/ockam/ockam_app/Ockam/MainView.swift @@ -1,7 +1,6 @@ import SwiftUI struct MainView: View { - @Environment(\.openWindow) private var openWindow @EnvironmentObject private var appDelegate: AppDelegate @Binding var state: ApplicationState @@ -73,7 +72,7 @@ struct MainView: View { ) } } - .scrollIndicators(ScrollIndicatorVisibility.hidden) + .scrollIndicators(ScrollIndicatorVisibility.never) .frame(maxHeight: 250) Divider() @@ -84,7 +83,9 @@ struct MainView: View { ClickableMenuEntry( text: "Open a portal…", action: { - openWindow(id: "open-portal") + OpenWindowWorkaround.shared.openWindow( + windowName: "open-portal" + ) bringInFront() } ) @@ -117,7 +118,7 @@ struct MainView: View { } } } - .scrollIndicators(ScrollIndicatorVisibility.hidden) + .scrollIndicators(ScrollIndicatorVisibility.never) .frame(maxHeight: selectedGroup == "" ? 175 : 500) } @@ -171,7 +172,9 @@ struct MainView: View { ClickableMenuEntry( text: "About", icon: "questionmark.circle", action: { - openWindow(id: "about") + OpenWindowWorkaround.shared.openWindow( + windowName: "about" + ) bringInFront() }) ClickableMenuEntry( diff --git a/implementations/swift/ockam/ockam_app/Ockam/OckamApp.swift b/implementations/swift/ockam/ockam_app/Ockam/OckamApp.swift index 448c5c2241a..2a3acc03a6c 100644 --- a/implementations/swift/ockam/ockam_app/Ockam/OckamApp.swift +++ b/implementations/swift/ockam/ockam_app/Ockam/OckamApp.swift @@ -182,6 +182,29 @@ class InvitationContainer: ObservableObject { } } +// On macOS ventura openWindow() doesn't work since the SwiftUI +// lifecycle is not recognized for some reason when using NSHostingView, +// this has been fixed in sonoma. +// The idea is to trigger an event to trigger an openWindow from another +// context where NSHostingView is a parent view. +// Only openWindow() used within the PopOver is affected. +class OpenWindowWorkaround: ObservableObject { + static var shared = OpenWindowWorkaround() + @Published var windowName = "" + @Published var value = "" + + func openWindow(windowName: String) { + self.windowName = windowName; + self.value = ""; + } + + func openWindow(windowName: String, value: String) { + self.windowName = windowName; + self.value = value; + } +} + + // when the application initialization fails to load we enter a broken state // where we only propose a reset to the user var broken = false @@ -217,15 +240,30 @@ struct OckamApp: App { openWindow(id: "accepting-invitation") } }) + // hack for ventura, see OpenWindowWorkaround comment + .onReceive(OpenWindowWorkaround.shared.$windowName) { _ in + if OpenWindowWorkaround.shared.value == "" { + openWindow( + id: OpenWindowWorkaround.shared.windowName + ) + } else { + openWindow( + id: OpenWindowWorkaround.shared.windowName, + value: OpenWindowWorkaround.shared.value + ) + } + } } .windowResizability(.contentSize) WindowGroup("Confirmation", id: "delete-portal-confirmation", for: Service.ID.self) { $serviceId in - DeleteIncomingPortalView( - service: StateContainer.shared.state.lookupIncomingServiceById( - serviceId.unsafelyUnwrapped - ).unsafelyUnwrapped.1 - ) + if let serviceId = serviceId { + DeleteIncomingPortalView( + service: StateContainer.shared.state.lookupIncomingServiceById( + serviceId + ).unsafelyUnwrapped.1 + ) + } } .windowResizability(.contentSize) diff --git a/implementations/swift/ockam/ockam_app/Ockam/RemotePortalView.swift b/implementations/swift/ockam/ockam_app/Ockam/RemotePortalView.swift index ccefb3a44b4..a165a1cbe68 100644 --- a/implementations/swift/ockam/ockam_app/Ockam/RemotePortalView.swift +++ b/implementations/swift/ockam/ockam_app/Ockam/RemotePortalView.swift @@ -111,7 +111,10 @@ struct RemotePortalView: View { ClickableMenuEntry( text: "Delete", action: { - openWindow(id: "delete-portal-confirmation", value: service.id) + OpenWindowWorkaround.shared.openWindow( + windowName: "delete-portal-confirmation", + value: service.id + ) }) } .padding(.leading, HorizontalSpacingUnit*2)