You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> 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
-
9
5
#### **Gives you *Extra* access to SwiftUI `MenuBarExtra`.**
10
6
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)
12
9
- Access to the underlying `NSStatusItem`
13
10
- Access to the underlying `NSWindow` (when using the `.window` style)
14
11
- Works with one or [multiple](#Multiple-MenuBarExtra)`MenuBarExtra`
15
12
- Works with both [`menu`](#Standard-Menu-Style) and [`window`](#Window-Style) based styles (see [Known Issues](#Known-Issues))
16
13
17
-
####Why?
14
+
## Why?
18
15
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)
20
17
21
-
####Library Features
18
+
## Library Features
22
19
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
25
23
- direct access to the `NSStatusItem` if needed
26
24
- A new `.introspectMenuBarExtraWindow { window in }` view modifier passing in the `NSWindow` reference
27
25
- 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.
33
31
34
32
Use the URL `https://github.com/orchetect/MenuBarExtraAccess` when adding the library to a project or Swift package.
35
33
36
-
Then import the library:
37
-
38
-
```swift
39
-
importSwiftUI
40
-
importMenuBarExtraAccess
41
-
```
42
-
43
-
### Standard Menu Style
44
-
45
-
An example of showing the menu extra menu by clicking a button in a window:
.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
-
structMyMenu: View {
91
-
@Bindingvar 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.
0 commit comments