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+
18from pyflowlauncher import Plugin , Result , send_results
29from pyflowlauncher .result import ResultResponse
3- from pathlib import Path
410import json
511import subprocess
612import webbrowser
@@ -54,8 +60,15 @@ def is_valid_url(url: str) -> bool:
5460def 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:
525538if __name__ == "__main__" :
526539 # 确保 dictionary 文件夹存在
527540 DICTIONARY_DIR .mkdir (exist_ok = True )
528- plugin .run ()
541+ plugin .run ()
0 commit comments