Skip to content

Commit bd4ff4a

Browse files
committed
Updated README
1 parent 2a5b151 commit bd4ff4a

File tree

1 file changed

+9
-103
lines changed

1 file changed

+9
-103
lines changed

README.md

Lines changed: 9 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,24 @@
22

33
[![Platforms - macOS 13.0](https://img.shields.io/badge/platforms-macOS%2013.0-blue.svg?style=flat)](https://developer.apple.com/swift) [![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Forchetect%2FMenuBarExtraAccess%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/orchetect/MenuBarExtraAccess) [![Xcode 14](https://img.shields.io/badge/Xcode-14-blue.svg?style=flat)](https://developer.apple.com/swift) [![License: MIT](http://img.shields.io/badge/license-MIT-lightgrey.svg?style=flat)](https://github.com/orchetect/MenuBarExtraAccess/blob/main/LICENSE)
44

5-
> [!WARNING]
6-
>
7-
> This package is not yet compatible with macOS 26 beta. See [this issue](https://github.com/orchetect/MenuBarExtraAccess/issues/20) for details and development progress.
8-
95
#### **Gives you *Extra* access to SwiftUI `MenuBarExtra`.**
106

11-
- Programmatically hide, show, or toggle the menu (by way of a Bool binding)
7+
- Programmatically hide, show, or toggle the menu (by way of a `Bool` binding)
8+
- Programmatically enable or disable the menubar extra (by way of a `Bool` binding)
129
- Access to the underlying `NSStatusItem`
1310
- Access to the underlying `NSWindow` (when using the `.window` style)
1411
- Works with one or [multiple](#Multiple-MenuBarExtra) `MenuBarExtra`
1512
- Works with both [`menu`](#Standard-Menu-Style) and [`window`](#Window-Style) based styles (see [Known Issues](#Known-Issues))
1613

17-
#### Why?
14+
## Why?
1815

19-
There is no 1st-party MenuBarExtra API to get or set the menu presentation state, access the status item, or access the popup's NSWindow. (Still as of Xcode 26 beta 3)
16+
There is no 1st-party `MenuBarExtra` API to get or set the menu presentation state, disable the menubar extra, access the `NSStatusItem`, or access the popup's `NSWindow`. (Still as of macOS 26 beta 4)
2017

21-
#### Library Features
18+
## Library Features
2219

23-
- A new `.menuBarExtraAccess(isPresented:) { statusItem in }` scene modifier with
24-
- a binding to hide/show/toggle the menu, and
20+
- A new `.menuBarExtraAccess(isPresented:, isEnabled:) { statusItem in }` scene modifier with
21+
- a binding to hide/show/toggle the menu
22+
- a binding to enabled/disable the menubar extra
2523
- direct access to the `NSStatusItem` if needed
2624
- A new `.introspectMenuBarExtraWindow { window in }` view modifier passing in the `NSWindow` reference
2725
- Window-based menu extra status items now remain highlighted while the window is open so it feels more like a native menu
@@ -33,99 +31,7 @@ The library is available as a Swift Package Manager (SPM) package.
3331

3432
Use the URL `https://github.com/orchetect/MenuBarExtraAccess` when adding the library to a project or Swift package.
3533

36-
Then import the library:
37-
38-
```swift
39-
import SwiftUI
40-
import MenuBarExtraAccess
41-
```
42-
43-
### Standard Menu Style
44-
45-
An example of showing the menu extra menu by clicking a button in a window:
46-
47-
```swift
48-
@main struct MyApp: App {
49-
@State private var isMenuPresented: Bool = false
50-
51-
var body: some Scene {
52-
WindowGroup {
53-
Button("Show Menu") { isMenuPresented = true }
54-
}
55-
56-
MenuBarExtra("MyApp Menu", systemImage: "folder") {
57-
Button("Menu Item 1") { print("Menu Item 1") }
58-
Button("Menu Item 2") { print("Menu Item 2") }
59-
}
60-
.menuBarExtraStyle(.menu)
61-
.menuBarExtraAccess(isPresented: $isMenuPresented) { statusItem in // <-- the magic ✨
62-
// access status item or store it in a @State var
63-
}
64-
}
65-
}
66-
```
67-
68-
### Window Style
69-
70-
An example of a button in the popup window dismissing the popup and performing an action:
71-
72-
```swift
73-
@main struct MyApp: App {
74-
@State private var isMenuPresented: Bool = false
75-
76-
var body: some Scene {
77-
MenuBarExtra("MyApp Menu", systemImage: "folder") {
78-
MyMenu(isMenuPresented: $isMenuPresented)
79-
.introspectMenuBarExtraWindow { window in // <-- the magic ✨
80-
window.animationBehavior = .alertPanel
81-
}
82-
}
83-
.menuBarExtraStyle(.window)
84-
.menuBarExtraAccess(isPresented: $isMenuPresented) { statusItem in // <-- the magic ✨
85-
// access status item or store it in a @State var
86-
}
87-
}
88-
}
89-
90-
struct MyMenu: View {
91-
@Binding var isMenuPresented: Bool
92-
93-
var body: some View {
94-
Button("Perform Action") {
95-
isMenuPresented = false
96-
performSomeAction()
97-
}
98-
}
99-
}
100-
```
101-
102-
### Multiple MenuBarExtra
103-
104-
MenuBarExtraAccess is fully compatible with one or multiple MenuBarExtra in an app.
105-
106-
Just add an index number parameter to `.menuBarExtraAccess()` and `.introspectMenuBarExtraWindow()` that reflects the order of `MenuBarExtra` declarations.
107-
108-
```swift
109-
var body: some Scene {
110-
MenuBarExtra("MyApp Menu A", systemImage: "folder") {
111-
MyMenu(isMenuPresented: $isMenuPresented)
112-
.introspectMenuBarExtraWindow(index: 0) { window in // <-- add index 0
113-
// ...
114-
}
115-
}
116-
.menuBarExtraStyle(.window)
117-
.menuBarExtraAccess(index: 0, isPresented: $isMenuPresented) // <-- add index 0
118-
119-
MenuBarExtra("MyApp Menu B", systemImage: "folder") {
120-
MyMenu(isMenuPresented: $isMenuPresented)
121-
.introspectMenuBarExtraWindow(index: 1) { window in // <-- add index 1
122-
// ...
123-
}
124-
}
125-
.menuBarExtraStyle(.window)
126-
.menuBarExtraAccess(index: 1, isPresented: $isMenuPresented) // <-- add index 1
127-
}
128-
```
34+
Check out the [Examples](Examples) folder for a demonstration of the package's usage.
12935

13036
## Future
13137

0 commit comments

Comments
 (0)