Skip to content

Commit 7d2d07a

Browse files
committed
Disabled debug logging by default
1 parent ada1c2d commit 7d2d07a

File tree

5 files changed

+27
-24
lines changed

5 files changed

+27
-24
lines changed

Package.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ let package = Package(
1111
targets: [
1212
.target(
1313
name: "MenuBarExtraAccess",
14-
swiftSettings: [.define("DEBUG", .when(configuration: .debug))]
14+
swiftSettings: [
15+
// un-comment to enable debug logging
16+
// .define("MENUBAREXTRAACCESS_DEBUG_LOGGING=1")
17+
]
1518
),
1619
.testTarget(name: "MenuBarExtraAccessTests", dependencies: ["MenuBarExtraAccess"]),
1720
]

Sources/MenuBarExtraAccess/MenuBarExtra Window Introspection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extension View {
1919
self
2020
.onAppear {
2121
guard let window = MenuBarExtraUtils.window(for: .index(index)) else {
22-
#if DEBUG
22+
#if MENUBAREXTRAACCESS_DEBUG_LOGGING
2323
print("Cannot call introspection block for status item because its window could not be found.")
2424
#endif
2525

Sources/MenuBarExtraAccess/MenuBarExtraAccess.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ struct MenuBarExtraAccess<Content: Scene>: Scene {
9292
// for example.
9393
observerContainer.setupStatusItemButtonStateObserver {
9494
MenuBarExtraUtils.newStatusItemButtonStateObserver(index: index) { change in
95-
#if DEBUG
95+
#if MENUBAREXTRAACCESS_DEBUG_LOGGING
9696
print("Status item button state observer: called with change: \(change.newValue?.description ?? "nil")")
9797
#endif
9898

@@ -105,7 +105,7 @@ struct MenuBarExtraAccess<Content: Scene>: Scene {
105105
guard let newVal = change.newValue else { return }
106106
let newBool = newVal != .off
107107
if isMenuPresented != newBool {
108-
#if DEBUG
108+
#if MENUBAREXTRAACCESS_DEBUG_LOGGING
109109
print("Status item button state observer: Setting isMenuPresented to \(newBool)")
110110
#endif
111111

@@ -119,15 +119,15 @@ struct MenuBarExtraAccess<Content: Scene>: Scene {
119119
// observerContainer.setupGlobalMouseDownMonitor {
120120
// // note that this won't fire when mouse events within the app cause the window to dismiss
121121
// MenuBarExtraUtils.newGlobalMouseDownEventsMonitor { event in
122-
// #if DEBUG
122+
// #if MENUBAREXTRAACCESS_DEBUG_LOGGING
123123
// print("Global mouse-down events monitor: called with event: \(event.type)")
124124
// #endif
125125
//
126126
// // close window when user clicks outside of it
127127
//
128128
// MenuBarExtraUtils.setPresented(for: .index(index), state: false)
129129
//
130-
// #if DEBUG
130+
// #if MENUBAREXTRAACCESS_DEBUG_LOGGING
131131
// print("Global mouse-down events monitor: Setting isMenuPresented to false")
132132
// #endif
133133
//
@@ -138,22 +138,22 @@ struct MenuBarExtraAccess<Content: Scene>: Scene {
138138
observerContainer.setupWindowObservers(
139139
index: index,
140140
didBecomeKey: { window in
141-
#if DEBUG
141+
#if MENUBAREXTRAACCESS_DEBUG_LOGGING
142142
print("MenuBarExtra index \(index) drop-down window did become key.")
143143
#endif
144144

145145
MenuBarExtraUtils.setKnownPresented(for: .index(index), state: true)
146146
isMenuPresented = true
147147
},
148148
didResignKey: { window in
149-
#if DEBUG
149+
#if MENUBAREXTRAACCESS_DEBUG_LOGGING
150150
print("MenuBarExtra index \(index) drop-down window did resign as key.")
151151
#endif
152152

153153
// it's possible for a window to resign key without actually closing, so let's
154154
// close it as a failsafe.
155155
if window.isVisible {
156-
#if DEBUG
156+
#if MENUBAREXTRAACCESS_DEBUG_LOGGING
157157
print("Closing MenuBarExtra index \(index) drop-down window as a result of it resigning as key.")
158158
#endif
159159

Sources/MenuBarExtraAccess/MenuBarExtraUtils/MenuBarExtraUtils.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ enum MenuBarExtraUtils {
1616

1717
/// Toggle MenuBarExtra menu/window presentation state.
1818
static func togglePresented(for ident: StatusItemIdentity? = nil) {
19-
#if DEBUG
19+
#if MENUBAREXTRAACCESS_DEBUG_LOGGING
2020
print("MenuBarExtraUtils.\(#function) called for status item \(ident?.description ?? "nil")")
2121
#endif
2222

@@ -25,7 +25,7 @@ enum MenuBarExtraUtils {
2525

2626
/// Set MenuBarExtra menu/window presentation state.
2727
static func setPresented(for ident: StatusItemIdentity? = nil, state: Bool) {
28-
#if DEBUG
28+
#if MENUBAREXTRAACCESS_DEBUG_LOGGING
2929
print("MenuBarExtraUtils.\(#function) called for status item \(ident?.description ?? "nil") with state \(state)")
3030
#endif
3131

@@ -35,7 +35,7 @@ enum MenuBarExtraUtils {
3535

3636
/// Set MenuBarExtra menu/window presentation state only when its state is reliably known.
3737
static func setKnownPresented(for ident: StatusItemIdentity? = nil, state: Bool) {
38-
#if DEBUG
38+
#if MENUBAREXTRAACCESS_DEBUG_LOGGING
3939
print("MenuBarExtraUtils.\(#function) called for status item \(ident?.description ?? "nil") with state \(state)")
4040
#endif
4141

@@ -111,7 +111,7 @@ extension MenuBarExtraUtils {
111111
switch ident {
112112
case .id(let menuBarExtraID):
113113
guard let match = menuBarWindows.first(where: { $0.menuBarExtraID == menuBarExtraID }) else {
114-
#if DEBUG
114+
#if MENUBAREXTRAACCESS_DEBUG_LOGGING
115115
print("MenuBarExtraUtils.\(#function): Window could not be found for status item with ID \"\(menuBarExtraID).")
116116
#endif
117117

@@ -138,7 +138,7 @@ extension MenuBarExtraUtils {
138138
_ handler: @escaping (_ change: NSKeyValueObservedChange<NSControl.StateValue>) -> Void
139139
) -> NSStatusItem.ButtonStateObserver? {
140140
guard let statusItem = MenuBarExtraUtils.statusItem(for: .index(index)) else {
141-
#if DEBUG
141+
#if MENUBAREXTRAACCESS_DEBUG_LOGGING
142142
print("Can't register menu bar extra state observer: Can't find status item. It may not yet exist.")
143143
#endif
144144

@@ -147,7 +147,7 @@ extension MenuBarExtraUtils {
147147

148148
guard let observer = statusItem.stateObserverMenuBased(handler)
149149
else {
150-
#if DEBUG
150+
#if MENUBAREXTRAACCESS_DEBUG_LOGGING
151151
print("Can't register menu bar extra state observer: Can't generate observer.")
152152
#endif
153153

@@ -189,7 +189,7 @@ extension MenuBarExtraUtils {
189189
index: Int
190190
) -> NSStatusItem.ButtonStatePublisher? {
191191
guard let statusItem = MenuBarExtraUtils.statusItem(for: .index(index)) else {
192-
#if DEBUG
192+
#if MENUBAREXTRAACCESS_DEBUG_LOGGING
193193
print("Can't register menu bar extra state observer: Can't find status item. It may not yet exist.")
194194
#endif
195195

@@ -198,7 +198,7 @@ extension MenuBarExtraUtils {
198198

199199
guard let publisher = statusItem.buttonStatePublisher()
200200
else {
201-
#if DEBUG
201+
#if MENUBAREXTRAACCESS_DEBUG_LOGGING
202202
print("Can't register menu bar extra state observer: Can't generate publisher.")
203203
#endif
204204

@@ -279,7 +279,7 @@ extension NSStatusItem {
279279
guard let behavior = button?.target, // SwiftUI.WindowMenuBarExtraBehavior <- internal
280280
let mirror = Mirror(reflecting: behavior).superclassMirror
281281
else {
282-
#if DEBUG
282+
#if MENUBAREXTRAACCESS_DEBUG_LOGGING
283283
print("Could not find status item's target.")
284284
#endif
285285

@@ -301,7 +301,7 @@ extension NSStatusItem {
301301
// however, WindowMenuBarExtraBehavior does contain an explicit `isMenuBased` Bool we can read
302302
guard let mirror = Mirror(reflecting: behavior).superclassMirror
303303
else {
304-
#if DEBUG
304+
#if MENUBAREXTRAACCESS_DEBUG_LOGGING
305305
print("Could not find status item's target.")
306306
#endif
307307

@@ -362,7 +362,7 @@ extension Mirror {
362362
return hashed
363363
}
364364

365-
#if DEBUG
365+
#if MENUBAREXTRAACCESS_DEBUG_LOGGING
366366
print("Could not determine MenuBarExtra ID")
367367
#endif
368368

Sources/MenuBarExtraAccess/NSStatusItem Extensions.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ extension NSStatusItem {
1313
/// Toggles the menu/window state by mimicking a menu item button press.
1414
@_disfavoredOverload
1515
public func togglePresented() {
16-
#if DEBUG
16+
#if MENUBAREXTRAACCESS_DEBUG_LOGGING
1717
print("NSStatusItem.\(#function) called")
1818
#endif
1919

@@ -31,7 +31,7 @@ extension NSStatusItem {
3131
/// Toggles the menu/window state by mimicking a menu item button press.
3232
@_disfavoredOverload
3333
internal func setPresented(state: Bool) {
34-
#if DEBUG
34+
#if MENUBAREXTRAACCESS_DEBUG_LOGGING
3535
print("NSStatusItem.\(#function) called with state: \(state)")
3636
#endif
3737

@@ -46,13 +46,13 @@ extension NSStatusItem {
4646

4747
@_disfavoredOverload
4848
internal func updateHighlight() {
49-
#if DEBUG
49+
#if MENUBAREXTRAACCESS_DEBUG_LOGGING
5050
print("NSStatusItem.\(#function) called")
5151
#endif
5252

5353
let s = button?.state != .off
5454

55-
#if DEBUG
55+
#if MENUBAREXTRAACCESS_DEBUG_LOGGING
5656
print("NSStatusItem.\(#function): State detected as \(s)")
5757
#endif
5858

0 commit comments

Comments
 (0)