{"id":15717516,"url":"https://github.com/astzweig/swiftui-window-reference","last_synced_at":"2025-03-30T21:23:17.882Z","repository":{"id":247960588,"uuid":"827347445","full_name":"astzweig/swiftui-window-reference","owner":"astzweig","description":"🖼️ A SwiftUI View that gets the NSWindow of the scene and puts it into the environment.","archived":false,"fork":false,"pushed_at":"2024-07-11T15:26:29.000Z","size":10,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-07T08:49:48.040Z","etag":null,"topics":["macos-app","nswindow","swiftui","view"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"eupl-1.2","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/astzweig.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-11T13:27:14.000Z","updated_at":"2025-02-27T15:07:13.000Z","dependencies_parsed_at":"2024-07-11T15:28:08.195Z","dependency_job_id":"b873135c-1025-4e8b-ae8c-2d22ed1aa6f5","html_url":"https://github.com/astzweig/swiftui-window-reference","commit_stats":null,"previous_names":["astzweig/swiftui-window-reference"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/astzweig%2Fswiftui-window-reference","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/astzweig%2Fswiftui-window-reference/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/astzweig%2Fswiftui-window-reference/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/astzweig%2Fswiftui-window-reference/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/astzweig","download_url":"https://codeload.github.com/astzweig/swiftui-window-reference/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246380714,"owners_count":20767891,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["macos-app","nswindow","swiftui","view"],"created_at":"2024-10-03T21:50:24.378Z","updated_at":"2025-03-30T21:23:17.859Z","avatar_url":"https://github.com/astzweig.png","language":"Swift","readme":"# WindowReference\n\nWindowReference adds a new SwiftUI view that retrieves a reference to the scene\nwindow ([NSWindow]) and puts it in the environment.\n\n[NSWindow]: https://developer.apple.com/documentation/appkit/nswindow\n\n## Usage\nImport `WindowReference` and use it as a (sub)view inside your view hierarchy.\n\n```swift\nimport SwiftUI\nimport WindowReference\n\n@main\nstruct YourApp: App {\n  var body: some Scene {\n    WindowGroup(\"Some Window Title\") {\n      WindowReference(withWindowInitializer: self.initWindow(_:)) {\n        SomeOtherView()\n      }\n    }\n  }\n\n  func initWindow(window: NSWindow) {\n    window.standardWindowButton(.miniaturizeButton)?.isHidden = true\n    window.standardWindowButton(.zoomButton)?.isHidden = true\n  }\n}\n```\n\nInside any child view of `WindowReference` you can grab the window from the\nenvironment.\n\n```swift\nstruct SomeOtherView: View {\n  @Environment(\\.window) var window: NSWindow?\n\n  var body: some View {\n    if let window = self.window {\n      Text(\"This view is inside a window with title \\(window.title)\")\n    } else {\n      Text(\"No window reference found :(\")\n    }\n  }\n}\n```\n\n## Documentation\nThe library has enriched symbol documentation for [DocC].\n\n[DocC]: https://www.swift.org/documentation/docc/documenting-a-swift-framework-or-package\n\n## Testing `WindowReference`\nWindowReference includes an executable target that launches a SwiftUI app to\ntest `WindowReference`. Either execute it with\n\n```sh\n$ swift run\n```\n\nor select the `TestApp` under `Product \u003e Scheme` in Xcode.\n\n## Adding `WindowReference` as a Dependency\n\nTo use the `WindowReference` library in a SwiftUI project, add it to the\ndependencies for your package:\n\n```swift\nlet package = Package(\n  // name, platforms, products, etc.\n  dependencies: [\n    // other dependencies\n    .package(url: \"https://github.com/astzweig/swiftui-window-reference\", from: \"1.0.0\"),\n  ],\n  targets: [\n    .executableTarget(name: \"\u003ccommand-line-tool\u003e\", dependencies: [\n      // other dependencies\n      .product(name: \"WindowReference\", package: \"swiftui-window-reference\"),\n    ]),\n    // other targets\n  ]\n)\n```\n\n### Supported Versions\n\nThe minimum Swift version supported by swiftui-window-reference releases are\ndetailed below:\n\nswiftui-window-reference   | Minimum Swift Version\n---------------------------|----------------------\n`0.0.1 ...`                | 5.10\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fastzweig%2Fswiftui-window-reference","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fastzweig%2Fswiftui-window-reference","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fastzweig%2Fswiftui-window-reference/lists"}