Merge branch 'dev'

This commit is contained in:
XcantloadX 2025-07-13 12:10:50 +08:00
commit a4d3b322e0
7 changed files with 32 additions and 11 deletions

View File

@ -49,7 +49,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
}
// 构建命令行
std::wstring cmd = pythonPath + L" " + bootstrapPath;
std::wstring cmd = L"\"" + pythonPath + L"\" \"" + bootstrapPath + L"\"";
// 如果有命令行参数,将其传递给 bootstrap
if (lpCmdLine && wcslen(lpCmdLine) > 0) {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 264 KiB

After

Width:  |  Height:  |  Size: 160 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 264 KiB

After

Width:  |  Height:  |  Size: 160 KiB

View File

@ -50,7 +50,7 @@ from kotonebot.backend.ocr import (
from kotonebot.config.manager import load_config, save_config
from kotonebot.config.base_config import UserConfig
from kotonebot.backend.core import Image, HintBox
from kotonebot.errors import KotonebotWarning
from kotonebot.errors import ContextNotInitializedError, KotonebotWarning
from kotonebot.backend.preprocessor import PreprocessorProtocol
from kotonebot.primitives import Rect
@ -719,14 +719,14 @@ class Forwarded:
if name.startswith('_FORWARD_'):
return object.__getattribute__(self, name)
if self._FORWARD_getter is None:
raise ValueError(f"Forwarded object {self._FORWARD_name} called before initialization.")
raise ContextNotInitializedError(f"Forwarded object {self._FORWARD_name} called before initialization.")
return getattr(self._FORWARD_getter(), name)
def __setattr__(self, name: str, value: Any):
if name.startswith('_FORWARD_'):
return object.__setattr__(self, name, value)
if self._FORWARD_getter is None:
raise ValueError(f"Forwarded object {self._FORWARD_name} called before initialization.")
raise ContextNotInitializedError(f"Forwarded object {self._FORWARD_name} called before initialization.")
setattr(self._FORWARD_getter(), name, value)
@ -974,7 +974,7 @@ def inject_context(
):
global _c
if _c is None:
raise RuntimeError('Context not initialized')
raise ContextNotInitializedError('Context not initialized')
_c.inject(device=device, ocr=ocr, image=image, color=color, vars=vars, debug=debug, config=config)
class ManualContextManager:

View File

@ -30,4 +30,8 @@ class UnscalableResolutionError(KotonebotError):
self.target_resolution = target_resolution
self.screen_size = screen_size
super().__init__(f'Cannot scale to target resolution {target_resolution}. '
f'Screen size: {screen_size}')
f'Screen size: {screen_size}')
class ContextNotInitializedError(KotonebotError):
def __init__(self, msg: str = 'Context not initialized'):
super().__init__(msg)

View File

@ -16,11 +16,12 @@ import gradio as gr
from kotonebot.kaa.main import Kaa
from kotonebot.kaa.db import IdolCard
from kotonebot.backend.context.context import vars
from kotonebot.errors import ContextNotInitializedError
from kotonebot.client.host import Mumu12Host, LeidianHost
from kotonebot.config.manager import load_config, save_config
from kotonebot.config.base_config import UserConfig, BackendConfig
from kotonebot.backend.context import task_registry, ContextStackVars
from kotonebot.backend.context.context import vars
from kotonebot.client.host import Mumu12Host, LeidianHost
from kotonebot.kaa.config import (
BaseConfig, APShopItems, CapsuleToysConfig, ClubRewardConfig, PurchaseConfig, ActivityFundsConfig,
PresentsConfig, AssignmentConfig, ContestConfig, ProduceConfig,
@ -180,6 +181,15 @@ def _save_bug_report(
zipf.write(file_path, arcname)
yield f"### 打包 log 文件:{arcname}"
# 打包 conf 文件夹
if os.path.exists('conf'):
for root, dirs, files in os.walk('conf'):
for file in files:
file_path = os.path.join(root, file)
arcname = os.path.join('conf', os.path.relpath(file_path, 'conf'))
zipf.write(file_path, arcname)
yield f"### 打包配置文件:{arcname}"
# 写出版本号
zipf.writestr('version.txt', version)
@ -381,8 +391,8 @@ class KotoneBotUI:
"""获取暂停按钮的状态和交互性"""
try:
text = "恢复" if vars.flow.is_paused else "暂停"
except ValueError:
# ValueError: Forwarded object vars called before initialization.
except ContextNotInitializedError:
# ContextNotInitializedError: Forwarded object vars called before initialization.
# TODO: vars.flow.is_paused 应该要可以在脚本正式启动前就能访问
text = '未启动'
# 如果正在停止过程中,禁用暂停按钮
@ -408,7 +418,10 @@ class KotoneBotUI:
# 重新加载 Context 中的配置数据
from kotonebot.backend.context.context import config
config.load()
try:
config.load()
except ContextNotInitializedError:
pass
logger.info("配置已成功重新加载")
return True

View File

@ -1,5 +1,6 @@
import io
import os
import sys
from typing import Any, Literal, cast
import zipfile
import logging
@ -60,6 +61,8 @@ class Kaa(KotoneBot):
self.upgrade_msg = upgrade_msg
self.version = importlib.metadata.version('ksaa')
logger.info('Version: %s', self.version)
logger.info('Python Version: %s', sys.version)
logger.info('Python Executable: %s', sys.executable)
def add_file_logger(self, log_path: str):
log_dir = os.path.abspath(os.path.dirname(log_path))
@ -143,6 +146,7 @@ class Kaa(KotoneBot):
raise ValueError('Backend instance is not set.')
_set_instance(self.backend_instance)
from kotonebot import device
logger.info('Device resolution: %s', device.screen_size)
logger.info('Set target resolution to 720x1280.')
device.orientation = 'portrait'
device.target_resolution = (720, 1280)