SwiftBar icon indicating copy to clipboard operation
SwiftBar copied to clipboard

Light/dark images parameter in dropdown menu

Open eu81273 opened this issue 6 months ago • 0 comments

I submitted PR #395 and it's been merged. However, I overlooked the fact that the image parameter can also be used in the dropdown menu.

Currently, the selection of the light/dark image in the image parameter depends on the appearance of the macOS menu bar (related to wallpaper color tone). However, in the dropdown menu, it should be determined by the macOS appearance (dark mode/light mode).

Here's an example of the issue: 스크린샷 2024-01-02 오전 1 55 00 macOS menu bar appearance: dark macOS appearance: light

As you can see, the image parameter of the header works as expected; it selected the light image because the macOS menu bar appearance is dark. However, the image parameter of the dropdown menu is not working correctly. It should select the dark image instead of the light image.

The solution I have in mind is as follows: To MenuLineParameters, pass the information about whether it is a header. If it's not a header, modify the logic to select the image based on AppShared.isDarkTheme instead. Alternatively, provide the OS_MENU_BAR_APPEARANCE environment variable (though I'm unsure about the implementation details for this).

To address this issue, I attempted to add the OS_MENU_BAR_APPEARANCE environment variable related to the macOS menu bar appearance. If there is an OS_MENU_BAR_APPEARANCE environment variable, I thought it would be a better approach as it allows us to reference this variable without relying on the light/dark image feature. This way, we can appropriately display the desired image based on the value of this environment variable.

However, the logic below that retrieves the macOS menu bar appearance had to run on the main thread, making it a bit challenging.

public static var isDarkStatusBar: Bool {
    let currentAppearance = NSStatusBar.system.statusItem(withLength: NSStatusItem.squareLength).button?.effectiveAppearance
    return currentAppearance?.bestMatch(from: [.aqua, .darkAqua]) == .aqua
}

If you tell me the solution, I will try to create a PR.

eu81273 avatar Jan 02 '24 14:01 eu81273