Add support light/dark image (#395)

This commit is contained in:
Jaeha Ahn (Aiden) 2023-12-31 00:52:42 +09:00 committed by GitHub
parent da6bf3197a
commit 10e6e8eed0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 3 deletions

View File

@ -144,7 +144,7 @@ Where:
| ------------- | ------------- |------------- |
| `dropdown` | False | Only applicable to items in `Header`. When set to False, item will not be displayed in dropdown menu, but will be cycled in the menu bar. |
| `alternate` | True | Marks a line as an alternative to the previous one for when the Option key (<kbd style="font-size:medium"></kbd>) is pressed in the dropdown.|
| `image` | Image encoded in Base64| Sets an image for item.|
| `image` | Image encoded in Base64, `light_image,dark_image` | Sets an image for item. If only one image is provided, it is used for both light and dark appearance.|
| `templateImage` | Image encoded in Base64| Same as `image`, but the image is a template image. Template images consist of black and clear colors (and an alpha channel). Template images are not intended to be used as standalone images and are usually mixed with other content to create the desired final appearance.|
| `sfimage` | SFSymbol name| Sets an image for item from [SF Symbol](https://developer.apple.com/sf-symbols/). Only available on Big Sur and above.|
| `sfconfig` | SFSymbol configuration| Configures [Rendering Mode](https://developer.apple.com/design/human-interface-guidelines/sf-symbols#Rendering-modes) for `sfimage`. Accepts a json encoded as base64, example json `{"renderingMode":"Palette", "colors":["red","blue"], "scale": "large", "weight": "bold"}`. Original issue #354 |

View File

@ -188,6 +188,11 @@ class AppShared: NSObject {
UserDefaults.standard.string(forKey: "AppleInterfaceStyle") != nil
}
public static var isDarkStatusBar: Bool {
let currentAppearance = NSStatusBar.system.statusItem(withLength: NSStatusItem.squareLength).button?.effectiveAppearance
return currentAppearance?.bestMatch(from: [.aqua, .darkAqua]) == .aqua
}
public static var isReduceTransparencyEnabled: Bool {
UserDefaults(suiteName: "com.apple.universalaccess.plist")?.bool(forKey: "reduceTransparency") ?? false
}

View File

@ -254,9 +254,19 @@ struct MenuLineParameters: Codable {
}
}
let image = NSImage.createImage(from: params["image"] ?? params["templateimage"], isTemplate: params["templateimage"] != nil)
if (params["image"] != nil) {
let images = params["image"]?.components(separatedBy: ",")
let lightImage = images?.first
let darkImage = images?.last
return resizedImageIfRequested(image)
return resizedImageIfRequested(NSImage.createImage(from: AppShared.isDarkStatusBar || darkImage == nil ? lightImage : darkImage, isTemplate: false))
}
if (params["templateimage"] != nil) {
return resizedImageIfRequested(NSImage.createImage(from: params["templateimage"], isTemplate: true))
}
return nil
}
private func resizedImageIfRequested(_ image: NSImage?) -> NSImage? {