mirror of
https://gitee.com/sui-feng-cb/AzurLaneAutoScript1
synced 2026-03-26 13:57:53 +08:00
Opt: Less pre-loads in gui.py by not importing config_updater
This commit is contained in:
@@ -2,8 +2,41 @@ import multiprocessing
|
|||||||
import threading
|
import threading
|
||||||
from multiprocessing.managers import SyncManager
|
from multiprocessing.managers import SyncManager
|
||||||
|
|
||||||
from module.config.config_updater import ConfigUpdater
|
|
||||||
from module.webui.config import DeployConfig
|
class cached_class_property:
|
||||||
|
"""
|
||||||
|
Code from https://github.com/dssg/dickens
|
||||||
|
|
||||||
|
Descriptor decorator implementing a class-level, read-only
|
||||||
|
property, which caches its results on the class(es) on which it
|
||||||
|
operates.
|
||||||
|
Inheritance is supported, insofar as the descriptor is never hidden
|
||||||
|
by its cache; rather, it stores values under its access name with
|
||||||
|
added underscores. For example, when wrapping getters named
|
||||||
|
"choices", "choices_" or "_choices", each class's result is stored
|
||||||
|
on the class at "_choices_"; decoration of a getter named
|
||||||
|
"_choices_" would raise an exception.
|
||||||
|
"""
|
||||||
|
|
||||||
|
class AliasConflict(ValueError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def __init__(self, func):
|
||||||
|
self.__func__ = func
|
||||||
|
self.__cache_name__ = '_{}_'.format(func.__name__.strip('_'))
|
||||||
|
if self.__cache_name__ == func.__name__:
|
||||||
|
raise self.AliasConflict(self.__cache_name__)
|
||||||
|
|
||||||
|
def __get__(self, instance, cls=None):
|
||||||
|
if cls is None:
|
||||||
|
cls = type(instance)
|
||||||
|
|
||||||
|
try:
|
||||||
|
return vars(cls)[self.__cache_name__]
|
||||||
|
except KeyError:
|
||||||
|
result = self.__func__(cls)
|
||||||
|
setattr(cls, self.__cache_name__, result)
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
class State:
|
class State:
|
||||||
@@ -14,8 +47,6 @@ class State:
|
|||||||
_init = False
|
_init = False
|
||||||
_clearup = False
|
_clearup = False
|
||||||
|
|
||||||
deploy_config = DeployConfig()
|
|
||||||
config_updater = ConfigUpdater()
|
|
||||||
restart_event: threading.Event = None
|
restart_event: threading.Event = None
|
||||||
manager: SyncManager = None
|
manager: SyncManager = None
|
||||||
electron: bool = False
|
electron: bool = False
|
||||||
@@ -30,3 +61,21 @@ class State:
|
|||||||
def clearup(cls):
|
def clearup(cls):
|
||||||
cls.manager.shutdown()
|
cls.manager.shutdown()
|
||||||
cls._clearup = True
|
cls._clearup = True
|
||||||
|
|
||||||
|
@cached_class_property
|
||||||
|
def deploy_config(self):
|
||||||
|
"""
|
||||||
|
Returns:
|
||||||
|
DeployConfig:
|
||||||
|
"""
|
||||||
|
from module.webui.config import DeployConfig
|
||||||
|
return DeployConfig()
|
||||||
|
|
||||||
|
@cached_class_property
|
||||||
|
def config_updater(self):
|
||||||
|
"""
|
||||||
|
Returns:
|
||||||
|
ConfigUpdater:
|
||||||
|
"""
|
||||||
|
from module.config.config_updater import ConfigUpdater
|
||||||
|
return ConfigUpdater()
|
||||||
|
|||||||
Reference in New Issue
Block a user