mirror of
https://gitee.com/xmz7891/ykxmz.git
synced 2026-10-18 20:40:43 +00:00
用户这一轮报了两个问题,都修了。
== 一、Win7 上语音播报不能用 ==
用户原话:"我 win7 上的语音播报好像不能用,你再试一下别的版本能不能用"
**原来只有一条路**:
powershell -NoProfile -WindowStyle Hidden -Command
"Add-Type -AssemblyName System.Speech; $s = New-Object ...; $s.Speak('...')"
这在 Win7 上有三个坑,任何一个都能让它彻底不出声:
1. **`powershell` 只按名字找**
Win7 的 powershell.exe 在 `%SystemRoot%\System32\WindowsPowerShell\v1.0\`。
精简版系统、或从服务/计划任务拉起时 PATH 里可能没有 ——
CreateProcess 按名字找不到时是**静默失败**的。
2. **Win7 默认 PowerShell 2.0,它按 ANSI 代码页解析 `-Command`**
PS 3.0 起才按 UTF-16 处理。中文经 `-Command` 传进去容易乱码 ——
表现是念出来是乱码,或者干脆不念。
3. **`System.Speech` 需要 .NET Framework 3.0+**
而系统自带的 **SAPI5** 从 Windows XP 就有,**根本不需要 .NET**。
**改成多方案降级**,按"依赖越少越优先"排:
1. cscript + VBScript + SAPI5 <- Win98 起就有,不用装任何东西
2. wscript + VBScript + SAPI5 <- 上一条被安全软件拦时的备选
3. powershell + SAPI5 (COM) <- 绕开 .NET
4. powershell + System.Speech <- 原来的做法,改用绝对路径
5. powershell(PATH) + System.Speech <- 最原始的,兜底
一条通了**记住它**,以后直接用(不用每次从头试)。
**顺带修掉一个"骗人"的行为**:原来 `say()` 用 `Popen` 不等进程结束,
失败了也返回"已播报" —— 明明没出声却报成功。
现在等退出码,**全失败会明确报错并列出试过哪几条**。
代价是同步等待(念多久等多久),但"报成功其实没出声"比"慢一点"糟糕得多。
还加了 `_build/diag_tts.py`:在一台机器上把 5 条方案全试一遍并报告
哪条能用 —— 下次再有"某台机器上不行",跑一下就知道。
VBScript 的细节:**必须用 ANSI(mbcs) 写**,写成 UTF-8 的话
cscript 读出来中文是乱码(VBScript 的老规矩,很隐蔽)。
长文本还要分句 —— VBScript 单行有长度上限。
== 二、快捷栏按钮太小 + 4 格都要能换 ==
用户原话:"屏幕最上面这个按钮有些按不到,按钮太小了,做大一点,
然后呢,这个每每个四格算换一下吧,第一个第二个第三个
第四个都能换东西"
* **按钮做大**:30dp -> 46dp(接近 Android 建议的最小可点区域 48),
字号 11 -> 14。30dp 在表盘上手指按上去一半在栏外。
**栏高做成常量 QUICK_BAR_DP,栏高 / 面板 topMargin / addView
三处用同一个值** —— 分三处写的话改一个忘一个,
表现是"内容被盖住"或"上面空一条"。
* **4 格全部可自定义**。用户最早说"其中有一个按钮不能改,
功能就是一键返回桌面",第一版就按"第 4 格写死 desktop"做的。
现在他改主意了 —— 所以 desktop 变成**普通可选动作**,
默认仍放第 4 格(习惯不用改),但想换也能换。
可选动作从 7 个变成 8 个。
**教训(写进测试注释了)**:别把"用户当时的一句话"当成永久约束
焊进结构里;真是约束的话,注释里要写清是什么时候的要求,
下次他改主意时才知道该动哪儿。
== 三、修一个"测试自己没擦干净"造成的假 bug ==
全量回归报:
[FAIL] 配对码正确写入 实际 '(旧的残留值)'
而 `(旧的残留值)` 是**上一次测试遗留**的配对码 —— 数据目录
`C:\ProgramData\ykxmz\data` 在卸载时**故意不删**(那里存着用户的
中转地址、配对码等,卸载不该删),所以机器上会留着上一轮的
settings.json。测试装的时候虽然传了 `/CODE=517284`,但环境没擦干净时
就可能读到旧值 —— 表现成"安装包有 bug"。
**修法**:`test_installer_cycle.py` 加一步"装前先清残留"
(正规卸载 -> 杀进程 -> 删安装目录 -> **删数据目录**)。
数据目录那一步是关键 —— 卸载器不删它。
== 四、其他 ==
* `docs/项目规矩.md` 第一节改成**按预案执行**:
预案一 = 做完测试没问题就上传;预案二 = 做完测试但不上传,直接给用户。
用户没说预案几时默认按预案一,并在交付时说明。
* 顺手把那份文档里的老域名 `relay.xxmxxs.top` 改成现在的
`yk.xxmxxs.top`(老服务器早就退役了)。
* 修掉自己造的重复定义:往 actions.py 插降级链时,
`list_voices` / `say` 各插了两份(pyflakes 报 redefinition)。
* 一次危险的误操作:`Path.write_text(..., newline='\n')` 会**先截断文件
再校验参数**,参数非法时文件已经空了 —— 我用它把
`_tests/test_quickbar.py` 清空了。已重写。
**以后不给 write_text 传 newline。**
== 验证 ==
全量回归(21 关)全部 PASS
新增关卡:3a13 手表快捷栏 / 3a14 语音播报降级
安装包周期 23 项全过(装 -> 验 -> 卸 -> 再验)
Java 编译通过(android-34, --release 8)
本机实测语音播报:cscript 那条通了(2.4 秒)
全部产物重建,Win7 兼容校验通过
231 lines
9.7 KiB
Python
231 lines
9.7 KiB
Python
# -*- coding: utf-8 -*-
|
||
r'''快捷栏:按钮做大 + **4 格全部可自定义**。
|
||
|
||
== 用户这次的反馈(原话)==
|
||
|
||
"屏幕最上面这个按钮有些按不到,按钮太小了,做大一点,
|
||
然后呢,这个每每个四格算换一下吧,第一个第二个第三个第四个都能换东西"
|
||
|
||
== 两个改动 ==
|
||
|
||
1. **按钮做大**:30dp -> 46dp,字号 11 -> 14。
|
||
30dp 在手表上确实太小了 —— 表盘本来就小,手指按上去一半在栏外。
|
||
46dp 接近 Android 建议的最小可点区域(48dp)。
|
||
|
||
⚠ 栏高和面板 topMargin 必须**用同一个常量**。分开写的话
|
||
改一个忘一个,表现是"内容要么被栏盖住,要么上面空一条"。
|
||
|
||
2. **第 4 格也变成可自定义**。
|
||
|
||
用户最早说"其中有一个按钮不能改,功能就是一键返回桌面",
|
||
现在改主意了:"第一个第二个第三个第四个都能换东西"。
|
||
|
||
所以「显示桌面」从"固定的那一格"变成**普通可选动作**,
|
||
而且默认就放在第 4 格 —— 这样默认行为跟以前一样
|
||
(最后一个还是显示桌面),但用户想换也能换。
|
||
|
||
实现上就是把 QUICK_CUSTOM_SLOTS 从 3 改成 4,
|
||
再把 {"desktop","显示桌面"} 加进 QUICK_ACTIONS,
|
||
然后去掉所有"第 4 格特殊"的分支。
|
||
'''
|
||
from __future__ import annotations
|
||
|
||
import sys
|
||
from pathlib import Path
|
||
|
||
ROOT = Path(__file__).resolve().parent.parent
|
||
MAIN = ROOT / "android" / "src" / "com" / "lanremote" / "watch" / "MainActivity.java"
|
||
|
||
PAIRS = [
|
||
# ---- 1. 格子数 3 -> 4 ----
|
||
(' private static final int QUICK_CUSTOM_SLOTS = 3; // 固定那个不算在内',
|
||
''' /** 快捷栏一共几格。用户最初要求"最多 4 个",
|
||
* 后来又改成"第一二三四格都能换东西",所以 4 格都可自定义。 */
|
||
private static final int QUICK_SLOTS = 4;
|
||
/** 快捷栏高度(dp)。46 接近 Android 建议的最小可点区域 48。
|
||
* ⚠ 面板的 topMargin 也用这个值 —— 分两处写的话改一个忘一个,
|
||
* 表现是"内容被栏盖住"或"上面空一条"。 */
|
||
private static final int QUICK_BAR_DP = 46;'''),
|
||
|
||
# ---- 2. 加 desktop 到可选动作 ----
|
||
(''' {"image", "投图到电脑"},
|
||
};''',
|
||
''' {"image", "投图到电脑"},
|
||
// 用户最早说这一格"不能改",后来又改成四格都能换 ——
|
||
// 所以它现在是**普通可选动作**,只是默认放在第 4 格。
|
||
{"desktop", "显示桌面"},
|
||
};'''),
|
||
|
||
# ---- 3. 默认值 3 -> 4 格 ----
|
||
(''' private String[] quickSlots = new String[]{"file", "mirror", "sfx"};''',
|
||
''' private String[] quickSlots =
|
||
new String[]{"file", "mirror", "sfx", "desktop"};'''),
|
||
|
||
# ---- 4. buildQuickBar:格数、高度、字号 ----
|
||
(''' for (int i = 0; i < QUICK_CUSTOM_SLOTS + 1; i++) {
|
||
final int slot = i;
|
||
Button b = new Button(this);
|
||
b.setTextSize(11f);''',
|
||
''' for (int i = 0; i < QUICK_SLOTS; i++) {
|
||
final int slot = i;
|
||
Button b = new Button(this);
|
||
b.setTextSize(14f); // 11 太小,用户说"按不到"'''),
|
||
|
||
(''' FrameLayout.LayoutParams barLp = new FrameLayout.LayoutParams(
|
||
ViewGroup.LayoutParams.MATCH_PARENT, dp(30));''',
|
||
''' FrameLayout.LayoutParams barLp = new FrameLayout.LayoutParams(
|
||
ViewGroup.LayoutParams.MATCH_PARENT, dp(QUICK_BAR_DP));'''),
|
||
|
||
# ---- 5. refreshQuickBar:不再有"固定那一格" ----
|
||
(''' boolean connected = isConnected();
|
||
for (int i = 0; i < quickButtons.size(); i++) {
|
||
Button b = quickButtons.get(i);
|
||
String id = (i < QUICK_CUSTOM_SLOTS) ? quickSlots[i] : "desktop";''',
|
||
''' boolean connected = isConnected();
|
||
for (int i = 0; i < quickButtons.size(); i++) {
|
||
Button b = quickButtons.get(i);
|
||
String id = quickSlots[i];'''),
|
||
|
||
# ---- 6. onQuickClick:不再有"固定那一格" ----
|
||
(''' /** 点第 slot 个按钮。0..2 是自定义,3 是那个固定的显示桌面。 */
|
||
private void onQuickClick(int slot) {
|
||
String id = (slot < QUICK_CUSTOM_SLOTS) ? quickSlots[slot] : "desktop";
|
||
if (id == null || id.isEmpty()) {
|
||
return;
|
||
}
|
||
runQuickAction(id);
|
||
}''',
|
||
''' /** 点第 slot 个按钮。四格完全平等,都从 quickSlots 里取。 */
|
||
private void onQuickClick(int slot) {
|
||
if (slot < 0 || slot >= quickSlots.length) {
|
||
return;
|
||
}
|
||
String id = quickSlots[slot];
|
||
if (id == null || id.isEmpty()) {
|
||
return;
|
||
}
|
||
runQuickAction(id);
|
||
}'''),
|
||
|
||
# ---- 7. loadQuickSlots:4 格 + 允许 desktop ----
|
||
(''' String[] want = (raw == null || raw.isEmpty())
|
||
? new String[]{"file", "mirror", "sfx"}
|
||
: raw.split(",", -1);''',
|
||
''' String[] want = (raw == null || raw.isEmpty())
|
||
? new String[]{"file", "mirror", "sfx", "desktop"}
|
||
: raw.split(",", -1);'''),
|
||
|
||
(''' String[] out = new String[QUICK_CUSTOM_SLOTS];
|
||
int n = 0;
|
||
for (String id : want) {
|
||
if (n >= QUICK_CUSTOM_SLOTS) {
|
||
break;
|
||
}
|
||
if (id != null && !id.isEmpty() && !"desktop".equals(id)
|
||
&& isKnownQuickAction(id)) {
|
||
out[n++] = id;
|
||
}
|
||
}
|
||
String[] fallback = {"file", "mirror", "sfx"};
|
||
for (int i = 0; i < QUICK_CUSTOM_SLOTS; i++) {''',
|
||
''' String[] out = new String[QUICK_SLOTS];
|
||
int n = 0;
|
||
for (String id : want) {
|
||
if (n >= QUICK_SLOTS) {
|
||
break;
|
||
}
|
||
// ⚠ 这里**不再排除 desktop** —— 用户改成四格都能换了
|
||
if (id != null && !id.isEmpty() && isKnownQuickAction(id)) {
|
||
out[n++] = id;
|
||
}
|
||
}
|
||
String[] fallback = {"file", "mirror", "sfx", "desktop"};
|
||
for (int i = 0; i < QUICK_SLOTS; i++) {'''),
|
||
|
||
# ---- 8. applyPanelTopMargin:用同一个常量 ----
|
||
(''' flp.topMargin = dp(30); // 跟 quickBar 的高度一致''',
|
||
''' // 用同一个常量 —— 栏高改了这里自动跟着改
|
||
flp.topMargin = dp(QUICK_BAR_DP);'''),
|
||
|
||
# ---- 9. onCreate 里 addView 的高度 ----
|
||
(''' root.addView(quickBar, new FrameLayout.LayoutParams(
|
||
ViewGroup.LayoutParams.MATCH_PARENT, dp(30)));''',
|
||
''' root.addView(quickBar, new FrameLayout.LayoutParams(
|
||
ViewGroup.LayoutParams.MATCH_PARENT, dp(QUICK_BAR_DP)));'''),
|
||
|
||
# ---- 10. 设置页:4 格 + 去掉"固定改不了"的说法 ----
|
||
(''' settingsExtraBox.addView(hintText("顶部那条栏,最多 4 个按钮。"
|
||
+ "最后一个「显示桌面」是固定的、改不了;"
|
||
+ "前三个点下面自己选。(还没连上电脑时它们是灰的)"));
|
||
for (int slot = 0; slot < QUICK_CUSTOM_SLOTS; slot++) {''',
|
||
''' settingsExtraBox.addView(hintText("顶部那条栏,4 个格子"
|
||
+ "**每一个都能换**,点下面自己选。"
|
||
+ "(还没连上电脑时它们是灰的)"));
|
||
for (int slot = 0; slot < QUICK_SLOTS; slot++) {'''),
|
||
|
||
(''' settingsExtraBox.addView(smallButton(
|
||
"恢复默认(传文件 / 屏幕镜像 / 音效)", C_CARD,
|
||
new Runnable() {
|
||
public void run() {
|
||
quickSlots = new String[]{"file", "mirror", "sfx"};''',
|
||
''' settingsExtraBox.addView(smallButton(
|
||
"恢复默认(传文件 / 屏幕镜像 / 音效 / 显示桌面)", C_CARD,
|
||
new Runnable() {
|
||
public void run() {
|
||
quickSlots = new String[]{"file", "mirror", "sfx", "desktop"};'''),
|
||
|
||
# ---- 11. 设置页标题也说明 4 格都能换 ----
|
||
(''' private void pickQuickSlot(final int slot) {
|
||
final java.util.List<String> labels = new java.util.ArrayList<String>();
|
||
final java.util.List<String> ids = new java.util.ArrayList<String>();
|
||
labels.add("留空(这一格不显示)");''',
|
||
''' private void pickQuickSlot(final int slot) {
|
||
final java.util.List<String> labels = new java.util.ArrayList<String>();
|
||
final java.util.List<String> ids = new java.util.ArrayList<String>();
|
||
labels.add("留空(这一格不显示)");'''),
|
||
]
|
||
|
||
|
||
def main() -> int:
|
||
print("=" * 58)
|
||
print(" 快捷栏:按钮做大 + 4 格全部可自定义")
|
||
print("=" * 58)
|
||
print()
|
||
|
||
raw = MAIN.read_bytes()
|
||
bom = raw.startswith(b"\xef\xbb\xbf")
|
||
t = raw.decode("utf-8-sig")
|
||
|
||
if "QUICK_SLOTS = 4" in t:
|
||
print(" 已经改过了")
|
||
return 0
|
||
|
||
# 先全部校验,避免改一半
|
||
missing = []
|
||
for i, (old, _new) in enumerate(PAIRS, 1):
|
||
if old not in t:
|
||
missing.append((i, old.strip().splitlines()[0][:66]))
|
||
if missing:
|
||
print(" ✗ 这些锚点找不到:")
|
||
for i, s in missing:
|
||
print(" #%d %s" % (i, s))
|
||
return 1
|
||
print(" ✓ %d 个锚点全部就位" % len(PAIRS))
|
||
|
||
for i, (old, new) in enumerate(PAIRS, 1):
|
||
t = t.replace(old, new, 1)
|
||
|
||
# 收尾:把残留的 QUICK_CUSTOM_SLOTS 全换掉(应该已经没有了)
|
||
left = t.count("QUICK_CUSTOM_SLOTS")
|
||
if left:
|
||
print(" ⚠ 还有 %d 处 QUICK_CUSTOM_SLOTS 残留,一并替换" % left)
|
||
t = t.replace("QUICK_CUSTOM_SLOTS", "QUICK_SLOTS")
|
||
|
||
MAIN.write_bytes((b"\xef\xbb\xbf" if bom else b"") + t.encode("utf-8"))
|
||
print(" ✓ 改完了")
|
||
return 0
|
||
|
||
|
||
if __name__ == "__main__":
|
||
sys.exit(main())
|