{"id":103,"date":"2024-11-06T22:57:42","date_gmt":"2024-11-06T22:57:42","guid":{"rendered":"https:\/\/www.visitnyc.store\/blog\/?p=103"},"modified":"2024-11-06T22:58:17","modified_gmt":"2024-11-06T22:58:17","slug":"window-management-workaround","status":"publish","type":"post","link":"https:\/\/www.visitnyc.store\/blog\/window-management-workaround\/","title":{"rendered":"Window Management workaround"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Was trying to work out a new feature called &#8220;Windows&#8221; and ran into this issue.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Open up a secondary window in an app (e.g. a new window that you programmatically open)<\/li>\n\n\n\n<li>Close the main window that your app operates in first<\/li>\n\n\n\n<li>Close the secondary window that your app programmatically opened<\/li>\n\n\n\n<li>Note that the app &#8220;exits&#8221; and you are brought back to the Home Screen<\/li>\n\n\n\n<li>Re-open the app<\/li>\n\n\n\n<li>Notice that the secondary window opens and not the main window for your app.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Looked at MacOS window behaviors and found that these APIs are not enabled for Vision OS.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/developer.apple.com\/documentation\/swiftui\/scene\/defaultlaunchbehavior(_:)\">https:\/\/developer.apple.com\/documentation\/swiftui\/scene\/defaultlaunchbehavior(_:)<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/developer.apple.com\/documentation\/swiftui\/scene\/defaultlaunchbehavior(_:)\">https:\/\/developer.apple.com\/documentation\/swiftui\/scene\/defaultlaunchbehavior(_:)<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Instead found this stackoverflow<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/stackoverflow.com\/questions\/77996275\/how-to-specify-which-windowgroup-should-appear-on-visionos-app-launch\">https:\/\/stackoverflow.com\/questions\/77996275\/how-to-specify-which-windowgroup-should-appear-on-visionos-app-launch<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Which has a comment from an Apple employee<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/developer.apple.com\/forums\/thread\/756327\">https:\/\/developer.apple.com\/forums\/thread\/756327<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">to add this workaround<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var body: some Scene {\n        WindowGroup(id: \"main\") {\n            ContentView()\n        }\n        \n        WindowGroup(id: \"Secondary\") {\n            SecondaryView()\n                .handlesExternalEvents(preferring: &#91;], allowing: &#91;])\n        }\n    }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>.handlesExternalEvents(preferring: [], allowing: [])<\/code> does the work of forcing the secondary to not be only one open when the app launches.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">From June 2024.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Was trying to work out a new feature called &#8220;Windows&#8221; and ran into this issue. Looked at MacOS window behaviors and found that these APIs are not enabled for Vision OS. https:\/\/developer.apple.com\/documentation\/swiftui\/scene\/defaultlaunchbehavior(_:) https:\/\/developer.apple.com\/documentation\/swiftui\/scene\/defaultlaunchbehavior(_:) Instead found this stackoverflow https:\/\/stackoverflow.com\/questions\/77996275\/how-to-specify-which-windowgroup-should-appear-on-visionos-app-launch Which has a comment from an Apple employee https:\/\/developer.apple.com\/forums\/thread\/756327 to add this workaround The .handlesExternalEvents(preferring: [], allowing: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-103","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.visitnyc.store\/blog\/wp-json\/wp\/v2\/posts\/103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.visitnyc.store\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.visitnyc.store\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.visitnyc.store\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.visitnyc.store\/blog\/wp-json\/wp\/v2\/comments?post=103"}],"version-history":[{"count":2,"href":"https:\/\/www.visitnyc.store\/blog\/wp-json\/wp\/v2\/posts\/103\/revisions"}],"predecessor-version":[{"id":105,"href":"https:\/\/www.visitnyc.store\/blog\/wp-json\/wp\/v2\/posts\/103\/revisions\/105"}],"wp:attachment":[{"href":"https:\/\/www.visitnyc.store\/blog\/wp-json\/wp\/v2\/media?parent=103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.visitnyc.store\/blog\/wp-json\/wp\/v2\/categories?post=103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.visitnyc.store\/blog\/wp-json\/wp\/v2\/tags?post=103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}