feat(interface): 组件自动聚焦与键盘操作改进
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
# Attic 服务
|
||||
import pickle as pkl
|
||||
from heurams.services.logger import get_logger
|
||||
from heurams.context import config_var
|
||||
from pathlib import Path
|
||||
from heurams.services.hasher import get_md5
|
||||
import atexit
|
||||
from heurams.services import timer
|
||||
from heurams.services.exceptions import WTFException
|
||||
logger = get_logger(__name__)
|
||||
|
||||
def singleton(cls):
|
||||
instances = {}
|
||||
def get_instance(ident, default):
|
||||
key = ident
|
||||
if key not in instances:
|
||||
instances[key] = cls(ident)
|
||||
instances[key].patch_dict(default)
|
||||
return instances[key]
|
||||
return get_instance
|
||||
|
||||
atticdir = Path(config_var.get()['global']['paths']['misc']) / 'attics'
|
||||
atticdir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
@singleton
|
||||
class Attic:
|
||||
def __init__(self, ident, default:dict={}):
|
||||
self.ident = ident
|
||||
self.ident = self.ident.replace('<DAYSTAMP>', str(timer.get_daystamp()))
|
||||
self.ident = self.ident.replace('<TIMESTAMP>', str(timer.get_timestamp()))
|
||||
if '<' in ident or '>' in ident:
|
||||
raise WTFException
|
||||
#self.ident = get_md5(self.ident)
|
||||
self.pklpath = atticdir / f'{self.ident}.pkl'
|
||||
atexit.register(self.save)
|
||||
self.data = default
|
||||
if self.pklpath.exists():
|
||||
try:
|
||||
self.load()
|
||||
return
|
||||
except:
|
||||
self.pklpath.unlink(missing_ok=True)
|
||||
self.pklpath.touch(exist_ok=True)
|
||||
|
||||
def patch_dict(self, dct):
|
||||
self.data.update({k: v for k, v in dct.items() if k not in self.data})
|
||||
|
||||
def save(self):
|
||||
with open(atticdir / f'{self.ident}.pkl', 'wb') as f:
|
||||
pkl.dump(self.data, f)
|
||||
|
||||
def load(self):
|
||||
with open(atticdir / f'{self.ident}.pkl', 'rb') as f:
|
||||
self.data.update(dict(pkl.load(f)))
|
||||
@@ -62,8 +62,7 @@ class FavoriteManager:
|
||||
|
||||
def _get_file_path(self) -> Path:
|
||||
"""获取收藏文件路径"""
|
||||
config_path = Path(config_var.get()["global"]["paths"]["data"])
|
||||
fav_path = config_path / "global" / "favorites.json"
|
||||
fav_path = Path(config_var.get()["global"]["paths"]["misc"]) / "favorites.json5"
|
||||
fav_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
return fav_path
|
||||
|
||||
|
||||
@@ -14,7 +14,8 @@ def get_md5(text):
|
||||
|
||||
|
||||
def hash(text):
|
||||
logger.debug(f"计算MD5-时间复合哈希, 输入`{text}`")
|
||||
result = hashlib.md5(f"{text}{random.randint(0,1000)}".encode("utf-8")).hexdigest()
|
||||
logger.debug("哈希结果: %s...", result[:8])
|
||||
return result
|
||||
#logger.debug(f"计算MD5-时间复合哈希, 输入`{text}`")
|
||||
#result = hashlib.md5(f"{text}{random.randint(0,1000)}".encode("utf-8")).hexdigest()
|
||||
#logger.debug("哈希结果: %s...", result[:8])
|
||||
#return result
|
||||
return get_md5(text)
|
||||
Reference in New Issue
Block a user