build: include android runtime helpers
This commit is contained in:
1 parent
f257c4e3fc
commit
63c726ddea
12 files changed
+129
-29
No files matched your search
@@ -15,6 +15,7 @@
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [V3.3.5] — 2026-06-27
|
||||
## [V3.3.4] — 2026-06-26
|
||||
### Added
|
||||
|
||||
|
||||
@@ -110,6 +110,12 @@ from douyin.license.license_manager import require_online_license_or_exit
|
||||
|
||||
|
||||
def ensure_adb_in_path() -> None:
|
||||
bundled_adb = path_config.find_bundled_adb()
|
||||
if bundled_adb:
|
||||
adb_dir = os.path.dirname(bundled_adb)
|
||||
os.environ["PATH"] = adb_dir + os.pathsep + os.environ.get("PATH", "")
|
||||
os.environ.setdefault("ADB_EXECUTABLE", bundled_adb)
|
||||
return
|
||||
if shutil.which("adb"):
|
||||
return
|
||||
localapp = os.environ.get("LOCALAPPDATA") or ""
|
||||
|
||||
@@ -289,6 +289,16 @@ def find_bundled_adb() -> Optional[str]:
|
||||
return None
|
||||
|
||||
|
||||
def get_bundled_android_tools_dir() -> str:
|
||||
"""返回随包 Android 辅助工具目录。"""
|
||||
return os.path.join(PROJECT_ROOT, "android-tools")
|
||||
|
||||
|
||||
def get_bundled_adbkeyboard_apk_path() -> str:
|
||||
"""返回随包 ADBKeyboard APK 路径。"""
|
||||
return os.path.join(get_bundled_android_tools_dir(), "ADBKeyboard.apk")
|
||||
|
||||
|
||||
def ensure_dir(path: str) -> None:
|
||||
"""确保目录存在,不存在则创建"""
|
||||
dir_path = os.path.dirname(path) if os.path.isfile(path) else path
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import base64
|
||||
import os
|
||||
import shlex
|
||||
import subprocess
|
||||
import time as time_module
|
||||
@@ -116,6 +117,20 @@ def ensure_adbkeyboard_ime(
|
||||
return True, prev, prev
|
||||
|
||||
imes = self.list_imes(device_id)
|
||||
if not self._pick_adbkeyboard_ime(imes):
|
||||
apk_path = path_config.get_bundled_adbkeyboard_apk_path()
|
||||
if os.path.exists(apk_path):
|
||||
try:
|
||||
subprocess.run(
|
||||
[self._adb_path(), "-s", str(device_id), "install", "-r", apk_path],
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
timeout=20.0,
|
||||
check=False,
|
||||
)
|
||||
imes = self.list_imes(device_id)
|
||||
except Exception:
|
||||
pass
|
||||
adb_ime = ""
|
||||
|
||||
pref = str(preferred_ime or "").strip()
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
from typing import Optional
|
||||
|
||||
APP_NAME = "douyin_guaji"
|
||||
APP_VERSION = "V3.3.4"
|
||||
APP_BUILD_DATE = "2026-06-26"
|
||||
APP_VERSION = "V3.3.5"
|
||||
APP_BUILD_DATE = "2026-06-27"
|
||||
|
||||
# 兼容旧代码与测试:提供 VERSION / RELEASE_DATE 别名
|
||||
# tests 期望: from version import VERSION, RELEASE_DATE, print_version_banner
|
||||
|
||||
+3
-2
@@ -70,6 +70,7 @@ dist\DouyinGuaji-<version>\
|
||||
- `run_cli.exe`:后台运行入口,桌面 GUI / Web GUI 会调用它
|
||||
- `assets/`、`webui/`、`config/`:运行所需资源
|
||||
- `platform-tools/`:随包 ADB 运行组件,至少包含 `adb.exe`、`AdbWinApi.dll`、`AdbWinUsbApi.dll`
|
||||
- `android-tools/`:随包手机侧辅助组件,当前包含 `ADBKeyboard.apk`
|
||||
- `logs/`、`pic/`、`state/`:运行时输出目录
|
||||
- `license.dat`:默认不随包分发;仅本地测试包需要时才使用 `-IncludeLicense` 显式复制
|
||||
|
||||
@@ -96,8 +97,8 @@ dist\installer\DouyinGuaji-3.3.3-Setup.exe
|
||||
## 发给别人前检查
|
||||
|
||||
- 打包脚本会自动运行 `python -m tools.distribution_manifest dist\DouyinGuaji-<version>`,防止源码、调试产物、个人配置和旧日志混入分发目录。
|
||||
- 最终分发目录只应保留根目录三个 exe、一个 `_internal/`、运行时白名单 `assets/`、运行时白名单 `webui/`、`platform-tools/` 中的 ADB 白名单文件、`config/README.md`、`logs/.keep`、`pic/.keep`、`state/.keep`。正式分发不要包含 `license.dat`、`README.md`、`artifacts/`、`tests/`、源码目录、调试截图、临时模板或 debug/README 页面。
|
||||
- 正式包会自带 ADB,不要求目标电脑额外安装 Android platform-tools 或配置 PATH。新电脑仍需要在手机上开启开发者选项/USB 调试并允许本机 RSA 授权;部分品牌手机首次 USB 识别还需要 Windows 能正确安装对应 USB 驱动。
|
||||
- 最终分发目录只应保留根目录三个 exe、一个 `_internal/`、运行时白名单 `assets/`、运行时白名单 `webui/`、`platform-tools/` 中的 ADB 白名单文件、`android-tools/ADBKeyboard.apk`、`config/README.md`、`logs/.keep`、`pic/.keep`、`state/.keep`。正式分发不要包含 `license.dat`、`README.md`、`artifacts/`、`tests/`、源码目录、调试截图、临时模板或 debug/README 页面。
|
||||
- 正式包会自带 ADB,不要求目标电脑额外安装 Android platform-tools 或配置 PATH。程序在需要中文输入且设备未安装 ADBKeyboard 时,会尝试从随包 `android-tools/ADBKeyboard.apk` 自动安装到手机。新电脑仍需要在手机上开启开发者选项/USB 调试并允许本机 RSA 授权;部分品牌手机首次 USB 识别还需要 Windows 能正确安装对应 USB 驱动。
|
||||
- 首次启动 PaddleOCR 相关组件可能较慢,杀毒软件也可能扫描 exe。
|
||||
- `config/config.json` 是本地运行配置,默认不随安装包带个人配置;让使用者首次打开后在 GUI 中保存配置。
|
||||
- 默认 Cython 编译后仍要以 `python -m tools.distribution_manifest dist\DouyinGuaji-<version>` 的结果为准;PASS 才能发给别人。使用 `-NoCythonForDevOnly` 生成的明文包禁止分发。
|
||||
@@ -132,30 +132,19 @@ foreach ($name in @("DouyinGuajiGUI", "web_gui", "run_cli")) {
|
||||
Remove-Item -LiteralPath $srcDir -Recurse -Force
|
||||
}
|
||||
|
||||
$RuntimeAssets = @(
|
||||
"coupon.png",
|
||||
"fav.png",
|
||||
"fudai.png",
|
||||
"fudai_icon_countdown_v20260618.png",
|
||||
"fudai_icon_pending_v20260618.png",
|
||||
"fudai_icon_purple_left_v20260618.png",
|
||||
"fudai_icon_red_left_v20260618.png",
|
||||
"fudai_task_status_dacheng_shape.png",
|
||||
"like.png",
|
||||
"x.png",
|
||||
"xin.png"
|
||||
)
|
||||
$AssetsTarget = Join-Path $DistRoot "assets"
|
||||
if (Test-Path $AssetsTarget) {
|
||||
Remove-Item -LiteralPath $AssetsTarget -Recurse -Force
|
||||
}
|
||||
New-Item -ItemType Directory -Force $AssetsTarget | Out-Null
|
||||
foreach ($name in $RuntimeAssets) {
|
||||
$src = Join-Path $Root "assets\$name"
|
||||
if (-not (Test-Path $src)) {
|
||||
throw "Missing runtime asset: assets\$name"
|
||||
}
|
||||
Copy-Item -LiteralPath $src -Destination (Join-Path $AssetsTarget $name) -Force
|
||||
$RuntimeAssetFiles = Get-ChildItem -LiteralPath (Join-Path $Root "assets") -File | Where-Object {
|
||||
$_.Extension -ieq ".png"
|
||||
}
|
||||
if (-not $RuntimeAssetFiles) {
|
||||
throw "Missing runtime assets: assets\*.png"
|
||||
}
|
||||
foreach ($asset in $RuntimeAssetFiles) {
|
||||
Copy-Item -LiteralPath $asset.FullName -Destination (Join-Path $AssetsTarget $asset.Name) -Force
|
||||
}
|
||||
|
||||
$WebuiTarget = Join-Path $DistRoot "webui"
|
||||
@@ -242,6 +231,17 @@ foreach ($name in $PlatformToolFiles) {
|
||||
}
|
||||
}
|
||||
|
||||
$AndroidToolsTarget = Join-Path $DistRoot "android-tools"
|
||||
if (Test-Path $AndroidToolsTarget) {
|
||||
Remove-Item -LiteralPath $AndroidToolsTarget -Recurse -Force
|
||||
}
|
||||
New-Item -ItemType Directory -Force $AndroidToolsTarget | Out-Null
|
||||
$AdbKeyboardApk = Join-Path $Root "tools\adb\ADBKeyboard.apk"
|
||||
if (-not (Test-Path $AdbKeyboardApk)) {
|
||||
throw "Missing Android helper: tools\adb\ADBKeyboard.apk"
|
||||
}
|
||||
Copy-Item -LiteralPath $AdbKeyboardApk -Destination (Join-Path $AndroidToolsTarget "ADBKeyboard.apk") -Force
|
||||
|
||||
$licensePath = Join-Path $Root "license.dat"
|
||||
if ($IncludeLicense -and (Test-Path $licensePath)) {
|
||||
Copy-Item -LiteralPath $licensePath -Destination (Join-Path $DistRoot "license.dat") -Force
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
# 这里的 version 由 tools/dev/bump_version.py 与 version.py 同步维护。
|
||||
# 注意:为兼容 PEP 440,这里去掉 "V" 前缀,仅保留数字部分(如 V3.3.3 → 3.3.3)。
|
||||
name = "douyin_guaji"
|
||||
version = "3.3.4"
|
||||
version = "3.3.5"
|
||||
description = "基于 ADB + OCR + 像素检测 + 模板匹配的抖音直播间福袋自动挂机工具"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.10"
|
||||
|
||||
@@ -11,6 +11,7 @@ def test_distribution_manifest_blocks_source_and_debug_artifacts():
|
||||
"DouyinGuajiGUI.exe",
|
||||
"_internal/python310.dll",
|
||||
"assets/fudai_task_count_v2_one_task.png",
|
||||
"assets/README.txt",
|
||||
"README.md",
|
||||
"douyin/core/douyin_fudai.py",
|
||||
"artifacts/debug.png",
|
||||
@@ -18,7 +19,6 @@ def test_distribution_manifest_blocks_source_and_debug_artifacts():
|
||||
"logs/unified.log",
|
||||
"pic/debug_captures/a.png",
|
||||
"license.dat",
|
||||
"assets/README.txt",
|
||||
"webui/debug.html",
|
||||
"webui/js/README.md",
|
||||
"DouyinGuajiGUI/_internal/base_library.zip",
|
||||
@@ -37,7 +37,7 @@ def test_distribution_manifest_blocks_source_and_debug_artifacts():
|
||||
assert "license.dat" in blocked
|
||||
assert "README.md" in blocked
|
||||
assert "assets/README.txt" in blocked
|
||||
assert "assets/fudai_task_count_v2_one_task.png" in blocked
|
||||
assert "assets/fudai_task_count_v2_one_task.png" not in blocked
|
||||
assert "webui/debug.html" in blocked
|
||||
assert "webui/js/README.md" in blocked
|
||||
assert "DouyinGuajiGUI/_internal/base_library.zip" in blocked
|
||||
@@ -63,6 +63,7 @@ def test_distribution_manifest_blocks_project_native_binaries_outside_core_allow
|
||||
"platform-tools/adb.exe",
|
||||
"platform-tools/AdbWinApi.dll",
|
||||
"platform-tools/AdbWinUsbApi.dll",
|
||||
"android-tools/ADBKeyboard.apk",
|
||||
"config/README.md",
|
||||
"logs/.keep",
|
||||
"pic/.keep",
|
||||
@@ -87,6 +88,8 @@ def test_distribution_manifest_allows_expected_runtime_shape():
|
||||
"_internal/base_library.zip",
|
||||
"_internal/python312.dll",
|
||||
"assets/fudai.png",
|
||||
"assets/desktop.png",
|
||||
"assets/fudai_task_count_v2_one_task.png",
|
||||
"assets/fudai_task_status_dacheng_shape.png",
|
||||
"assets/fudai_icon_red_left_v20260618.png",
|
||||
"webui/index.html",
|
||||
@@ -97,6 +100,7 @@ def test_distribution_manifest_allows_expected_runtime_shape():
|
||||
"platform-tools/AdbWinUsbApi.dll",
|
||||
"platform-tools/NOTICE.txt",
|
||||
"platform-tools/source.properties",
|
||||
"android-tools/ADBKeyboard.apk",
|
||||
"config/README.md",
|
||||
"logs/.keep",
|
||||
"pic/.keep",
|
||||
@@ -136,6 +140,7 @@ def test_distribution_manifest_can_allow_license_for_local_test_package():
|
||||
"platform-tools/adb.exe",
|
||||
"platform-tools/AdbWinApi.dll",
|
||||
"platform-tools/AdbWinUsbApi.dll",
|
||||
"android-tools/ADBKeyboard.apk",
|
||||
"config/README.md",
|
||||
"logs/.keep",
|
||||
"pic/.keep",
|
||||
@@ -160,6 +165,7 @@ def test_distribution_manifest_requires_python_runtime_dll():
|
||||
"platform-tools/adb.exe",
|
||||
"platform-tools/AdbWinApi.dll",
|
||||
"platform-tools/AdbWinUsbApi.dll",
|
||||
"android-tools/ADBKeyboard.apk",
|
||||
"config/README.md",
|
||||
"logs/.keep",
|
||||
"pic/.keep",
|
||||
@@ -171,7 +177,7 @@ def test_distribution_manifest_requires_python_runtime_dll():
|
||||
assert "_internal/python*.dll" in issues
|
||||
|
||||
|
||||
def test_distribution_manifest_requires_bundled_adb_runtime():
|
||||
def test_distribution_manifest_requires_bundled_android_runtime():
|
||||
from tools.distribution_manifest import find_distribution_issues
|
||||
|
||||
entries = [
|
||||
@@ -193,6 +199,7 @@ def test_distribution_manifest_requires_bundled_adb_runtime():
|
||||
assert "platform-tools/adb.exe" in issues
|
||||
assert "platform-tools/AdbWinApi.dll" in issues
|
||||
assert "platform-tools/AdbWinUsbApi.dll" in issues
|
||||
assert "android-tools/ADBKeyboard.apk" in issues
|
||||
|
||||
|
||||
def test_distribution_manifest_cli_passes_clean_tree(tmp_path):
|
||||
@@ -211,6 +218,7 @@ def test_distribution_manifest_cli_passes_clean_tree(tmp_path):
|
||||
"platform-tools/adb.exe",
|
||||
"platform-tools/AdbWinApi.dll",
|
||||
"platform-tools/AdbWinUsbApi.dll",
|
||||
"android-tools/ADBKeyboard.apk",
|
||||
"config/README.md",
|
||||
"logs/.keep",
|
||||
"pic/.keep",
|
||||
|
||||
@@ -259,8 +259,9 @@ def test_windows_packaging_script_protects_core_modules_by_default():
|
||||
assert "[switch]$IncludeLicense" in script
|
||||
assert '"--add-data", "assets;assets"' not in script
|
||||
assert '"--add-data", "webui;webui"' not in script
|
||||
assert "$RuntimeAssets = @(" in script
|
||||
assert 'assets\$name' in script
|
||||
assert "$RuntimeAssetFiles = Get-ChildItem" in script
|
||||
assert 'assets\*.png' in script
|
||||
assert "tools\\adb\\ADBKeyboard.apk" in script
|
||||
assert "$IncludeLicense -and" in script
|
||||
assert '$ManifestArgs += "--allow-license"' in script
|
||||
assert "Get-ChildItem -LiteralPath $srcInternal -Force | Copy-Item" in script
|
||||
|
||||
@@ -86,6 +86,50 @@ class TestPickAdbKeyboardIme:
|
||||
assert result in ("", None)
|
||||
|
||||
|
||||
def test_ensure_adbkeyboard_installs_bundled_apk_when_missing(monkeypatch, tmp_path):
|
||||
from douyin.core.underlying_operations_pkg import text_input
|
||||
|
||||
apk = tmp_path / "ADBKeyboard.apk"
|
||||
apk.write_bytes(b"apk")
|
||||
calls = []
|
||||
|
||||
class Ops:
|
||||
def __init__(self):
|
||||
self.list_count = 0
|
||||
|
||||
def get_current_ime(self, _device_id):
|
||||
return "com.example/.Ime"
|
||||
|
||||
def list_imes(self, _device_id):
|
||||
self.list_count += 1
|
||||
if self.list_count == 1:
|
||||
return ["com.example/.Ime"]
|
||||
return ["com.android.adbkeyboard/.AdbIME"]
|
||||
|
||||
def _pick_adbkeyboard_ime(self, imes):
|
||||
return _pick_adbkeyboard_ime(imes)
|
||||
|
||||
def _adb_path(self):
|
||||
return "adb"
|
||||
|
||||
def try_set_ime(self, _device_id, ime_id):
|
||||
return ime_id == "com.android.adbkeyboard/.AdbIME"
|
||||
|
||||
def fake_run(cmd, **_kwargs):
|
||||
calls.append(cmd)
|
||||
return type("Proc", (), {"returncode": 0})()
|
||||
|
||||
monkeypatch.setattr(text_input.path_config, "get_bundled_adbkeyboard_apk_path", lambda: str(apk))
|
||||
monkeypatch.setattr(text_input.subprocess, "run", fake_run)
|
||||
|
||||
ok, prev, ime = text_input.ensure_adbkeyboard_ime(Ops(), "device1")
|
||||
|
||||
assert ok is True
|
||||
assert prev == "com.example/.Ime"
|
||||
assert ime == "com.android.adbkeyboard/.AdbIME"
|
||||
assert calls and calls[0][-2:] == ["-r", str(apk)]
|
||||
|
||||
|
||||
# ============================================================
|
||||
# bounds.py — _parse_bounds
|
||||
# ============================================================
|
||||
|
||||
@@ -46,15 +46,22 @@ FORBIDDEN_EXACT = {
|
||||
|
||||
ALLOWED_ASSET_FILES = {
|
||||
"assets/coupon.png",
|
||||
"assets/desktop.png",
|
||||
"assets/fav.png",
|
||||
"assets/fudai.png",
|
||||
"assets/fudai_icon_countdown_v20260618.png",
|
||||
"assets/fudai_icon_pending_v20260618.png",
|
||||
"assets/fudai_icon_purple_left_v20260618.png",
|
||||
"assets/fudai_icon_red_left_v20260618.png",
|
||||
"assets/fudai_task_count_digit_1.png",
|
||||
"assets/fudai_task_count_digit_2.png",
|
||||
"assets/fudai_task_count_v2_one_task.png",
|
||||
"assets/fudai_task_count_v2_two_task.png",
|
||||
"assets/fudai_task_status_dacheng_shape.png",
|
||||
"assets/like.png",
|
||||
"assets/quan.png",
|
||||
"assets/x.png",
|
||||
"assets/xiangqing.png",
|
||||
"assets/xin.png",
|
||||
}
|
||||
|
||||
@@ -84,6 +91,10 @@ ALLOWED_PLATFORM_TOOLS_FILES = {
|
||||
"platform-tools/source.properties",
|
||||
}
|
||||
|
||||
ALLOWED_ANDROID_TOOLS_FILES = {
|
||||
"android-tools/adbkeyboard.apk",
|
||||
}
|
||||
|
||||
FORBIDDEN_SUFFIXES = (
|
||||
".py",
|
||||
".pyc",
|
||||
@@ -160,6 +171,8 @@ def is_forbidden_distribution_entry(entry: str, *, allow_license: bool = False)
|
||||
return Path(lower).suffix not in ALLOWED_WEBUI_SUFFIXES
|
||||
if lower.startswith("platform-tools/"):
|
||||
return lower not in ALLOWED_PLATFORM_TOOLS_FILES
|
||||
if lower.startswith("android-tools/"):
|
||||
return lower not in ALLOWED_ANDROID_TOOLS_FILES
|
||||
if any(lower.startswith(prefix.lower()) for prefix in FORBIDDEN_PREFIXES):
|
||||
return True
|
||||
return any(lower.endswith(suffix) for suffix in FORBIDDEN_SUFFIXES)
|
||||
@@ -187,6 +200,7 @@ def find_missing_required_runtime_entries(entries: list[str]) -> list[str]:
|
||||
"platform-tools/adb.exe",
|
||||
"platform-tools/AdbWinApi.dll",
|
||||
"platform-tools/AdbWinUsbApi.dll",
|
||||
"android-tools/ADBKeyboard.apk",
|
||||
):
|
||||
if required.lower() not in normalized:
|
||||
missing.append(required)
|
||||
|
||||
Reference in new issue
Block a user