-
Notifications
You must be signed in to change notification settings - Fork 27
feat(demo): 添加演示模式支持,禁用实时预览和控制功能 #402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -180,6 +180,8 @@ def state(self) -> int: | |
| if update_tail_hit: | ||
| return 4 | ||
| return 2 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (bug_risk): 与特定日志消息字符串的紧密耦合可能会比较脆弱。 这个条件依赖日志中的字面子串 "此版本为演示用途",将行为绑定到一个面向用户的本地化文案上,而这些文案可能会发生变化(文案修改、国际化、重写等)。相较于匹配具体的消息文本,更推荐使用结构化且稳定的信号(例如专门的非本地化标签/前缀或日志中的机器可读标记)。 建议实现方式: elif DEMO_LOG_MARKER in s:
return 2 set_func_logger(func=q.put)
DEMO_LOG_MARKER = "[DEMO_MODE]"
if os.environ.get("DEMO") == "1":`) 要求所有产生与演示相关日志的代码都包含这个标记。 以下是具体修改: <file_operations>
|
||
| elif "此版本为演示用途" in s: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里存在一个潜在的竞争条件(Race Condition)。在 |
||
| return 2 | ||
| elif update_tail_hit: | ||
| return 4 | ||
| else: | ||
|
|
@@ -230,6 +232,16 @@ def run_process( | |
| logger.removeHandler(console_hdlr) | ||
| set_func_logger(func=q.put) | ||
|
|
||
| if os.environ.get("DEMO") == "1": | ||
| logger.info("Log3") | ||
| time.sleep(1) | ||
| logger.info("Log2") | ||
| time.sleep(1) | ||
| logger.info("Log1") | ||
| time.sleep(1) | ||
| logger.info("此版本为演示用途") | ||
|
Comment on lines
+235
to
+242
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: 演示模式检测是临时实现的,而不是通过共享的辅助函数来完成。 其他模块使用 建议实现方式: set_func_logger(func=q.put)
if is_demo_mode():
logger.info("Log3")
time.sleep(1)
logger.info("Log2")
time.sleep(1)
logger.info("Log1")
time.sleep(1)
logger.info("此版本为演示用途")
return
Original comment in Englishsuggestion: Demo-mode detection is implemented ad hoc instead of using a shared helper. Other modules use an Suggested implementation: set_func_logger(func=q.put)
if is_demo_mode():
logger.info("Log3")
time.sleep(1)
logger.info("Log2")
time.sleep(1)
logger.info("Log1")
time.sleep(1)
logger.info("此版本为演示用途")
return
|
||
| return | ||
|
|
||
| from module.config.config import AzurLaneConfig | ||
|
|
||
| # 移除伪造的 PIL 模块,子进程需要使用真正的 PIL | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在
module/webui/api.py和module/webui/app.py中都重复定义了is_demo_mode()函数。此外,在process_manager.py、app.py(如第 5095 行)以及config.py中仍然直接使用了os.environ.get("DEMO") == "1"。\n\n为了提高代码的可维护性和一致性,建议将is_demo_mode()统一移动到公共工具模块(例如module/config/utils.py,该模块已被这些文件广泛导入),并在所有相关地方统一调用。