Skip to content

Commit 7e97f97

Browse files
authored
Update main.py
1 parent 8517d7a commit 7e97f97

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

main.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
import sys
2+
from pathlib import Path
3+
4+
plugindir = Path.absolute(Path(__file__).parent)
5+
paths = (".", "lib", "plugin")
6+
sys.path = [str(plugindir / p) for p in paths] + sys.path
7+
18
from pyflowlauncher import Plugin, Result, send_results
29
from pyflowlauncher.result import ResultResponse
3-
from pathlib import Path
410
import json
511
import subprocess
612
import webbrowser
@@ -54,8 +60,15 @@ def is_valid_url(url: str) -> bool:
5460
def load_sites() -> Dict[str, str]:
5561
"""加载 sites.json"""
5662
if not SITE_FILE.exists():
57-
logging.info("sites.json does not exist, returning empty dict")
58-
return {}
63+
logging.info("sites.json does not exist, creating default file")
64+
try:
65+
default_data = {"language": "zh"}
66+
with open(SITE_FILE, "w", encoding="utf-8") as f:
67+
json.dump(default_data, f, ensure_ascii=False, indent=2)
68+
return default_data
69+
except Exception as e:
70+
logging.error(f"Error creating default sites.json: {str(e)}")
71+
return {}
5972
try:
6073
with open(SITE_FILE, "r", encoding="utf-8-sig") as f:
6174
data = json.load(f)
@@ -525,4 +538,4 @@ def remove_site(name: str) -> ResultResponse:
525538
if __name__ == "__main__":
526539
# 确保 dictionary 文件夹存在
527540
DICTIONARY_DIR.mkdir(exist_ok=True)
528-
plugin.run()
541+
plugin.run()

0 commit comments

Comments
 (0)