diff --git a/README.md b/README.md index d65ebd2..2845295 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,9 @@ If you wish to use another language, open a GitHub issue [here](https://github.c 3. `📖 Emoji Dictionary` : Select your online emoji dictionary. -4. `🎷 Notification sound` : personalize the sound of the workflow notification. +4. `🌈 Skin Tone` : Select your preferred skin tone. + +5. `🎷 Notification sound` : Personalize the sound of the workflow notification. ### Search an emoji diff --git a/src/api.py b/src/api.py index 7a0f02d..7b21cd0 100644 --- a/src/api.py +++ b/src/api.py @@ -58,6 +58,33 @@ def convert_emoji_to_png(emoji, name): draw.text(draw_position, emoji, font=font, embedded_color=True) image.save(f"{icons_folder_path}/{name.replace(':', '')}.png", "PNG") +def remove_skin_tones(emoji): + skin_tone_range = range(0x1F3FB, 0x1F3FF + 1) + clean_emoji = ''.join([char for char in emoji if ord(char) not in skin_tone_range]) + return clean_emoji + +def get_skin_tones(emoji): + skin_tones = [] + if emoji in cleaned_emojis: + skin_tones.append('none') + else: + skin_tone_dict = { + 0x1F3FB: "light skin tone", + 0x1F3FC: "medium-light skin tone", + 0x1F3FD: "medium skin tone", + 0x1F3FE: "medium-dark skin tone", + 0x1F3FF: "dark skin tone" + } + for char in emoji: + value_skin_tone = skin_tone_dict.get(ord(char)) + if value_skin_tone: + skin_tones.append(value_skin_tone) + if not skin_tones: + skin_tones.append('base') + return list(set(skin_tones)) + +skin_tones = ["light skin tone", "medium-light skin tone", "medium skin tone", "medium-dark skin tone", "dark skin tone"] + try: api_url = 'https://unicode.org/Public/emoji/latest/emoji-test.txt' api_response = request.urlopen(api_url).read().decode('utf-8') @@ -72,9 +99,19 @@ def convert_emoji_to_png(emoji, name): root.extend(ET.fromstring(lang_response_2)) items = [] + cleaned_emojis = [] + full_emojis = [] + for line in lines: array = re.split(r'\bfully-qualified\b|\bcomponent\b', line)[1].strip().split(' ', 3) emoji, name = array[1], array[-1] + full_emojis.append({"emoji": emoji, "name": name}) + clean_emoji = remove_skin_tones(emoji) + if emoji != clean_emoji: + cleaned_emojis.append(clean_emoji) + + for obj in full_emojis: + emoji, name = obj['emoji'], obj['name'] trim_emoji = re.sub('\uFE0F', '', emoji) for elem in root: tags_list = elem.find(f"./annotation[@cp='{trim_emoji}']") @@ -101,7 +138,8 @@ def convert_emoji_to_png(emoji, name): 'emoji': emoji, 'title': title, 'tags': tags, - 'image': image + 'image': image, + 'skin_tones': get_skin_tones(emoji) }) for item in langs: diff --git a/src/info.plist b/src/info.plist index 899f6f6..2eb439e 100644 --- a/src/info.plist +++ b/src/info.plist @@ -1156,6 +1156,52 @@ note: not all emojis are available in all languages. variable emoji_dictionary + + config + + default + all + pairs + + + 🎨 All + all + + + 👋 None + none + + + 👋🏻 Light + light skin tone + + + 👋🏼 Medium-Light + medium-light skin tone + + + 👋🏽 Medium + medium skin tone + + + 👋🏾 Medium-Dark + medium-dark skin tone + + + 👋🏿 Dark + dark skin tone + + + + description + preferred skin tone. + label + 🌈 Skin Tone + type + popupbutton + variable + skin_tone + config @@ -1239,8 +1285,10 @@ note: not all emojis are available in all languages. sound + variablesdontexport + version - 1.4.0 + 1.5.0 webaddress https://github.com/BenjaminOddou/alfred-emoji-wine diff --git a/src/notificator b/src/notificator index d6d5a8f..b3d06a3 100755 --- a/src/notificator +++ b/src/notificator @@ -22,7 +22,8 @@ function make_icns { /bin/mkdir "${iconset}" # Create iconset - for size in {16,32,64,128,256,512}; do + for size in {16,32,64,128,256,512} + do /usr/bin/sips --resampleHeightWidth "${size}" "${size}" "${file}" --out "${iconset}/icon_${size}x${size}.png" &> /dev/null /usr/bin/sips --resampleHeightWidth "$((size * 2))" "$((size * 2))" "${file}" --out "${iconset}/icon_${size}x${size}@2x.png" &> /dev/null done @@ -53,7 +54,8 @@ function usage { # Options args=() -while [[ "${1}" ]]; do +while [[ "${1}" ]] +do case "${1}" in -h | --help) usage @@ -93,49 +95,47 @@ done set -- "${args[@]}" # Check for required arguments -if [[ -z "${notificator_message}" ]]; then +if [[ -z "${notificator_message}" ]] +then echo 'A message is mandatory! Aborting…' >&2 exit 1 fi -readonly bundle_id="$(tr -cd '[:alnum:]._-' <<< "${alfred_workflow_bundleid}")" -readonly name="$(tr -cd '[:alnum:]._- ' <<< "${alfred_workflow_name}")" +readonly bundle_id="$(/usr/bin/tr -cd '[:alnum:]._-' <<< "${alfred_workflow_bundleid}")" +readonly name="$(/usr/bin/tr -cd '[:alnum:]._- ' <<< "${alfred_workflow_name}")" readonly icon="${alfred_preferences}/workflows/${alfred_workflow_uid}/icon.png" readonly app="${alfred_workflow_cache}/Notificator for ${name}.app" readonly plist="${app}/Contents/Info.plist" # Exit early if Notificator exists and was modified fewer than 30 days ago -if [[ -e "${app}" && -n "$(find "${app}" -depth 0 -mtime -30)" ]]; then +if [[ -d "${app}" && "$(/bin/date -r "${app}" +%s)" -gt "$(/bin/date -v -30d +%s)" ]] +then show_notification exit 0 fi # Pre-build checks -if [[ -z "${bundle_id}" ]]; then +if [[ -z "${bundle_id}" ]] +then echo "Workflow is missing the bundle identifier! Aborting…" >&2 exit 1 fi -if [[ -z "${name}" ]]; then +if [[ -z "${name}" ]] +then echo "Workflow is missing the name! Aborting…" >&2 exit 1 fi -if [[ ! -f "${icon}" ]]; then +if [[ ! -f "${icon}" ]] +then echo "Workflow is missing the icon! Aborting…" >&2 exit 1 fi # Build Notificator readonly jxa_script=' - // Build argv/argc in a way that can be used from the applet inside the app bundle - ObjC.import("Foundation") - const args = $.NSProcessInfo.processInfo.arguments - const argv = [] - const argc = args.count - for (let i = 0; i < argc; i++) { argv.push(ObjC.unwrap(args.objectAtIndex(i))) } - - // Notification script + const argv = $.NSProcessInfo.processInfo.arguments.js.map(arg => arg.js) const app = Application.currentApplication() app.includeStandardAdditions = true @@ -160,17 +160,17 @@ readonly jxa_script=' app.displayNotification(message, options) ' -[[ -d "${app}" ]] && rm -r "${app}" +[[ -d "${app}" ]] && /bin/rm -r "${app}" /bin/mkdir -p "${alfred_workflow_cache}" /usr/bin/osacompile -l JavaScript -o "${app}" -e "${jxa_script}" 2> /dev/null # Modify Notificator /usr/libexec/PlistBuddy -c "add :CFBundleIdentifier string ${bundle_id}.notificator" "${plist}" /usr/libexec/PlistBuddy -c 'add :LSUIElement string 1' "${plist}" -mv "$(make_icns "${icon}")" "${app}/Contents/Resources/applet.icns" +/bin/mv "$(make_icns "${icon}")" "${app}/Contents/Resources/applet.icns" # Redo signature -codesign --remove-signature "${app}" -codesign --sign - "${app}" +/usr/bin/codesign --remove-signature "${app}" +/usr/bin/codesign --sign - "${app}" show_notification \ No newline at end of file diff --git a/src/utils.py b/src/utils.py index 41cdb49..4dc36df 100644 --- a/src/utils.py +++ b/src/utils.py @@ -19,6 +19,7 @@ def langs_dict(xml_file): sound = os.environ['sound'] language = os.environ['language'] +skin_tone = os.environ['skin_tone'] try: padding = int(os.environ['padding']) except: diff --git a/src/wine.py b/src/wine.py index 20e88a7..811cd66 100644 --- a/src/wine.py +++ b/src/wine.py @@ -1,6 +1,6 @@ import re import json -from utils import config, api_file_path, tags_file_path, icons_folder_path, language, emoji_dictionary, langs, workflow_version +from utils import config, api_file_path, tags_file_path, icons_folder_path, language, emoji_dictionary, langs, workflow_version, skin_tone api_data = config(api_file_path) tags_data = config(tags_file_path) @@ -23,7 +23,7 @@ }) else: for item in api_data['items']: - name, emoji, title, tags, image = item['name'], item['emoji'], item['title'], item['tags'], item['image'] + name, emoji, title, tags, image, skin_tones = item['name'], item['emoji'], item['title'], item['tags'], item['image'], item['skin_tones'] match = " ".join(tags) if tags is not None else name if tags_data is not None: for tag in tags_data: @@ -67,7 +67,8 @@ }, } }) - items.append(elem) + if skin_tone in skin_tones or 'base' in skin_tones or skin_tone == 'all': + items.append(elem) else: items.append({ 'title': 'No API detected',