11# -*- coding: utf-8 -*-
22
3- """Find emojis by name.
4-
5- Synopsis: <trigger> <emoji name>"""
6-
73import json
84import re
95import subprocess
139from albert import *
1410
1511md_iid = '1.0'
16- md_version = "1.2 "
12+ md_version = "1.3 "
1713md_name = "Emoji Picker"
1814md_description = "Find emojis by name"
1915md_license = "GPL-3.0"
2521EXTENSION_DIR = Path (__file__ ).parent
2622ALIASES_PATH = EXTENSION_DIR / "aliases.json"
2723EMOJI_PATH = EXTENSION_DIR / "emoji-test.txt"
28- ICON_DIR = Path (cacheLocation ()) / "emojis"
29-
30-
31- ICON_DIR .mkdir (exist_ok = True , parents = True )
32-
33-
34- def icon_path (emoji ):
35- return ICON_DIR / f"{ emoji } .png"
3624
3725
3826def convert_to_png (emoji , output_path ):
@@ -49,10 +37,10 @@ def convert_to_png(emoji, output_path):
4937 )
5038
5139
52- def schedule_create_missing_icons (emojis ):
40+ def schedule_create_missing_icons (emojis , icon_dir_path : str ):
5341 executor = ThreadPoolExecutor ()
5442 for emoji in emojis :
55- path = icon_path ( emoji [" emoji" ])
43+ path = icon_dir_path / f" { emoji [' emoji' ] } .png"
5644 if not path .exists ():
5745 executor .submit (convert_to_png , emoji ["emoji" ], path )
5846
@@ -76,6 +64,8 @@ def synopsis(self):
7664 return "<emoji name>"
7765
7866 def initialize (self ):
67+ self .icon_dir_path = Path (cacheLocation ())
68+
7969 line_re = re .compile (
8070 r"""
8171 ^
@@ -112,7 +102,7 @@ def initialize(self):
112102 e ["search_tokens" ] = search_tokens
113103 self .emojis .append (e )
114104
115- self .icon_executor = schedule_create_missing_icons (self .emojis )
105+ self .icon_executor = schedule_create_missing_icons (self .emojis , self . icon_dir_path )
116106
117107 def finalize (self ):
118108 self .icon_executor .shutdown (wait = True , cancel_futures = True )
@@ -136,7 +126,7 @@ def handleTriggerQuery(self, query):
136126 id = f"emoji_{ emoji ['emoji' ]} " ,
137127 text = f"{ emoji ['emoji' ]} { emoji ['name' ]} " ,
138128 subtext = emoji ["modifiers" ] or "" ,
139- icon = [str (icon_path ( emoji [" emoji" ]) )],
129+ icon = [str (self . icon_dir_path / f" { emoji [' emoji' ] } .png" )],
140130 actions = [
141131 Action (
142132 "copy" ,
0 commit comments