Repository navigation
Expand file tree
/
Copy pathemoji.py
More file actions
81 lines (59 loc) · 2.06 KB
/
Copy pathemoji.py
File metadata and controls
81 lines (59 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# this what replaces emoji font
from pathlib import Path
import shutil
import sys
import paths
APK_DIR = paths.SOBER_APK_DIR
OVERLAY_FONT_DIR = paths.LUTION_OVERLAY / "content/fonts"
EMOJI_FONT_NAMES = ["RobloxEmoji.ttf", "TwemojiMozilla.ttf"]
BASE = Path(getattr(sys, "_MEIPASS", Path(__file__).parent))
PRESETS_DIR = BASE / "emoji_presets"
INSTALLED_EMOJI_DIR = paths.LUTION_ROOT / "installed_emoji"
def list_presets():
if not PRESETS_DIR.exists():
return []
return sorted([f.stem for f in PRESETS_DIR.glob("*.ttf")])
def get_preset_path(name):
path = PRESETS_DIR / f"{name}.ttf"
return str(path) if path.exists() else None
def apply_emoji(source_path):
source_path = Path(source_path)
if not source_path.exists():
raise FileNotFoundError(f"Emoji font file not found: {source_path}")
OVERLAY_FONT_DIR.mkdir(parents=True, exist_ok=True)
replaced = []
for name in EMOJI_FONT_NAMES:
dest = OVERLAY_FONT_DIR / name
shutil.copyfile(source_path, dest)
replaced.append(str(dest))
return replaced
def restore_emoji():
removed = []
for name in EMOJI_FONT_NAMES:
target = OVERLAY_FONT_DIR / name
if target.exists():
target.unlink()
removed.append(name)
if INSTALLED_EMOJI_DIR.exists():
shutil.rmtree(INSTALLED_EMOJI_DIR)
return removed
def save_installed_emoji(font_path: Path | str) -> None:
if isinstance(font_path, str):
font_path = Path(font_path)
if not INSTALLED_EMOJI_DIR.exists():
INSTALLED_EMOJI_DIR.mkdir(exist_ok=True, parents=True)
dest_file = INSTALLED_EMOJI_DIR / ("emoji" + font_path.suffix)
try:
shutil.copy(font_path, dest_file, follow_symlinks=True)
except shutil.SameFileError:
pass
def reapply_emoji():
if not INSTALLED_EMOJI_DIR.exists():
return
candidates = sorted(INSTALLED_EMOJI_DIR.glob("*"), key=lambda p: p.stat().st_ctime)
if not candidates:
return
try:
apply_emoji(str(candidates[0]))
except FileNotFoundError:
return