swiftDialog icon indicating copy to clipboard operation
swiftDialog copied to clipboard

Support for dark mode with Icon

Open joncrain opened this issue 2 years ago • 5 comments

I would love to be able to specify a specific icon for dark mode. We've found that our icon/logo does not look great on either one or the other.

Either specify in config or to use the right icon based on the names of the file.

joncrain avatar Apr 01 '22 14:04 joncrain

Good suggestion. I currently handle this when using most dialoging tools, whether swiftDialog or others, by having 2 icons in place and detecting the "color mode" for the OS of the current user and then assigning the appropriate icon as the variable.

Example:

#!/bin/zsh

logged_in_user=$(/usr/sbin/scutil <<< "show State:/Users/ConsoleUser" | /usr/bin/awk '/Name :/ && ! /loginwindow/ {print $3}')

icon_base64_dark="<base64 string of icon data goes here>"
icon_base64_lite="<base64 string of icon data goes here>"

/bin/echo "$icon_base64_dark" | /usr/bin/base64 --decode > /path/to/icondark.png
/bin/echo "$icon_base64_lite" | /usr/bin/base64 --decode > /path/to/iconlite.png

os_color_mode=$(/usr/bin/defaults read /Users/$logged_in_user/Library/Preferences/.GlobalPreferences.plist AppleInterfaceStyle)

if [ "$os_color_mode" = "Dark" ]; then
	icon_path="/path/to/icondark.png"
else
	icon_path="/path/to/iconlite.png"
fi

Then in the rest of the script you just use $icon_path as the variable for the --icon flag.

That said, having a built in way to have it use the appropriate icon would be cool.

mm2270 avatar Apr 25 '22 04:04 mm2270

I've had a think about how this would be implemented and have settled on one of two options:

  1. have --icon accept a dark and light path such as --icon dark=/path/to/image_dark.png,light=/path/to/image_light.png. --icon /path/to/image.png would also continue to work as it does currently.

  2. have dialog auto pick. e.g. --icon /path/to/image.png would look for image.png image_light.png and image_dark.png and use whichever exists and is appropriate. (would also work in reverse, so passing in image_light.png would make it also look for image_dark.png and image.png)

option 1 is less development effort but I like the simplicity for the admin with option 2.

@mm2270 that method is pretty cool and if you don't mind I might mention that in the wiki for the time being.

bartreardon avatar Apr 25 '22 04:04 bartreardon

@bartreardon Yes of course you can use that in the wiki.

mm2270 avatar Apr 25 '22 13:04 mm2270

Nice call! Looks like this works in python:

from Foundation import NSBundle

def is_dark_mode():
    appearanceBundle = NSBundle.bundleWithPath_(
        "/System/Library/PreferencePanes/Appearance.prefPane"
    )
    appearanceShared = appearanceBundle.classNamed_("AppearanceShared")
    app = appearanceShared.sharedAppearanceAccess()
    if app.theme() == 1:
        return False
    else:
        return True

if is_dark_mode():
    content["icon"] = "dark_icon.png"
else:
    content["icon"] = "light_icon.png"

That can work for now.

joncrain avatar Apr 26 '22 01:04 joncrain

Updated the wiki for the time being

bartreardon avatar Apr 28 '22 04:04 bartreardon

closing this as wontfix.

if dark/light icons are important then the admin can supply the logic to handle it.

bartreardon avatar Aug 24 '23 00:08 bartreardon