Skip to content

Commit

Permalink
feat: skin tone selection
Browse files Browse the repository at this point in the history
- Filter emoji result with a skin tone parameter
- Update notificator
  • Loading branch information
BenjaminOddou committed May 25, 2024
1 parent 670f040 commit eb4d093
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 27 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
40 changes: 39 additions & 1 deletion src/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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}']")
Expand All @@ -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:
Expand Down
50 changes: 49 additions & 1 deletion src/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,52 @@ note: not all emojis are available in all languages.</string>
<key>variable</key>
<string>emoji_dictionary</string>
</dict>
<dict>
<key>config</key>
<dict>
<key>default</key>
<string>all</string>
<key>pairs</key>
<array>
<array>
<string>🎨 All</string>
<string>all</string>
</array>
<array>
<string>👋 None</string>
<string>none</string>
</array>
<array>
<string>👋🏻 Light</string>
<string>light skin tone</string>
</array>
<array>
<string>👋🏼 Medium-Light</string>
<string>medium-light skin tone</string>
</array>
<array>
<string>👋🏽 Medium</string>
<string>medium skin tone</string>
</array>
<array>
<string>👋🏾 Medium-Dark</string>
<string>medium-dark skin tone</string>
</array>
<array>
<string>👋🏿 Dark</string>
<string>dark skin tone</string>
</array>
</array>
</dict>
<key>description</key>
<string>preferred skin tone.</string>
<key>label</key>
<string>🌈 Skin Tone</string>
<key>type</key>
<string>popupbutton</string>
<key>variable</key>
<string>skin_tone</string>
</dict>
<dict>
<key>config</key>
<dict>
Expand Down Expand Up @@ -1239,8 +1285,10 @@ note: not all emojis are available in all languages.</string>
<string>sound</string>
</dict>
</array>
<key>variablesdontexport</key>
<array/>
<key>version</key>
<string>1.4.0</string>
<string>1.5.0</string>
<key>webaddress</key>
<string>https://github.com/BenjaminOddou/alfred-emoji-wine</string>
</dict>
Expand Down
42 changes: 21 additions & 21 deletions src/notificator
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -53,7 +54,8 @@ function usage {

# Options
args=()
while [[ "${1}" ]]; do
while [[ "${1}" ]]
do
case "${1}" in
-h | --help)
usage
Expand Down Expand Up @@ -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
Expand All @@ -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
1 change: 1 addition & 0 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 4 additions & 3 deletions src/wine.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit eb4d093

Please sign in to comment.