chore: 代码优化

This commit is contained in:
ikun
2024-09-15 22:22:33 +08:00
parent 53b76aea64
commit ecc454de61
3 changed files with 20 additions and 8 deletions

View File

@@ -7,16 +7,23 @@ import aiofiles
from .stack_error import stack_error
from .log import log
async def gen_config_file():
qa1 = "温馨提示Github_Personal_Token可在Github设置的最底下开发者选项找到详情看教程"
tutorial = "https://ikunshare.com/Onekey_tutorial"
default_config ={
"Github_Personal_Token": "",
"Custom_Steam_Path": "",
"QA1": "温馨提示Github_Personal_Token可在Github设置的最底下开发者选项找到详情看教程",
"教程": "https://lyvx-my.sharepoint.com/:w:/g/personal/ikun_ikunshare_com/EWqIqyCElLNLo_CKfLbqix0BWU_O03HLzEHQKHdJYrUz-Q?e=79MZjw"
"QA1": qa1,
"教程": tutorial
}
async with aiofiles.open("./config.json", mode="w", encoding="utf-8") as f:
await f.write(json.dumps(default_config, indent=2, ensure_ascii=False,
escape_forward_slashes=False))
async with aiofiles.open("./config.json",
mode="w",
encoding="utf-8") as f:
await f.write(json.dumps(default_config,
indent=2,
ensure_ascii=False,
escape_forward_slashes=False))
await f.close()
log.info(' 🖱️ 程序可能为第一次启动,请填写配置文件后重新启动程序')
@@ -28,7 +35,9 @@ async def load_config():
sys.exit()
else:
try:
async with aiofiles.open("./config.json", mode="r", encoding="utf-8") as f:
async with aiofiles.open("./config.json",
mode="r",
encoding="utf-8") as f:
config = json.loads(await f.read())
return config
except Exception as e:
@@ -37,4 +46,4 @@ async def load_config():
os.system('pause')
config = asyncio.run(load_config())
config = asyncio.run(load_config())

View File

@@ -6,6 +6,7 @@ from .log import log
lock = asyncio.Lock()
async def depotkey_merge(config_path, depots_config):
if not config_path.exists():
async with lock:

View File

@@ -1,6 +1,7 @@
import logging
import colorlog
def init_log():
logger = logging.getLogger('Onekey')
logger.setLevel(logging.DEBUG)
@@ -18,4 +19,5 @@ def init_log():
logger.addHandler(stream_handler)
return logger
log = init_log()
log = init_log()