Skip to content

Commit 9832021

Browse files
[emoji:1.3] Adjust to cache/config/data changes
1 parent 6fe50e9 commit 9832021

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

emoji/__init__.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
# -*- coding: utf-8 -*-
22

3-
"""Find emojis by name.
4-
5-
Synopsis: <trigger> <emoji name>"""
6-
73
import json
84
import re
95
import subprocess
@@ -13,7 +9,7 @@
139
from albert import *
1410

1511
md_iid = '1.0'
16-
md_version = "1.2"
12+
md_version = "1.3"
1713
md_name = "Emoji Picker"
1814
md_description = "Find emojis by name"
1915
md_license = "GPL-3.0"
@@ -25,14 +21,6 @@
2521
EXTENSION_DIR = Path(__file__).parent
2622
ALIASES_PATH = EXTENSION_DIR / "aliases.json"
2723
EMOJI_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

3826
def 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

Comments
 (0)