Files
cat-shark d3db80c27b SideQuest 简体中文汉化工具包
把官方 SideQuest 桌面版(基线 1.4.1)汉化为简体中文,并产出可覆盖安装的 deb。

不修改任何上游源码:所有改动集中在 build.js 的补丁层,作用于已编译产物
(dist-electron 与 dist/sidequest-desktop),因此本工具包可独立于上游代码工作。

主要内容:
- 运行时汉化引擎 engine.js + 主进程统一注入 hook tail.js
  (应用有 7 个 data:text/html overlay 页且带严格 CSP,故用主进程 hook 一次覆盖全部窗口)
- 词典 1806 条(dict-a…i.json)+ 动态规则 137 条(rules.json)
- 纯 Node 实现的 asar 打包/解包 asar.js,零外部依赖
- 构建/试运行/安装/校验脚本

覆盖范围:主页、侧载、文件、应用、串流、设备设置、调试(Logcat)、无线、
全部弹窗、命令面板、日期与相对时间。内嵌商店为远程服务端渲染,不在范围内。
2026-10-11 18:09:36 +08:00

118 lines
4.5 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# ============================================================================
# SideQuest 简体中文汉化 —— 隔离试运行(asar 模式,最接近真实安装形态)
#
# 用法: bash ./test-run.sh [端口] # 默认 9223
#
# 特点:
# - 用「隔离的 userData 目录」运行,完全不碰 ~/.config/SideQuestDesktop
# - 与正在运行的官方 SideQuest 互不干扰(单实例锁位于各自 userData 内)
# - 首次会把真实配置复制一份过去,因此能直观看到登录态/设备绑定是否保留
# - 走 resources/app.asar 加载,验证的就是最终会被安装的那份 asar
#
# 结束后用 stop-test.sh 清理。
# ============================================================================
set -euo pipefail
TOOL_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
WORK="${SQ_ZH_HOME:-$HOME/.sidequest-zh}"
APP_ZH="$WORK/app-zh"
PORT="${1:-9223}"
RUNTIME="$WORK/test-run"
DATA_LIVE="$HOME/.config/SideQuestDesktop"
DATA_TEST="$HOME/.config/SideQuestDesktop-zhtest"
INSTALL_DIR="/opt/SideQuest"
GLIBC_MARK="$(mktemp -d)"
ok() { printf ' \033[32m✓\033[0m %s\n' "$*"; }
bad() { printf ' \033[31m✗\033[0m %s\n' "$*"; }
die() { bad "$*"; exit 1; }
say() { printf '\n\033[1m== %s ==\033[0m\n' "$*"; }
command -v node >/dev/null || die "需要 node"
[ -d "$APP_ZH" ] || die "缺少 $APP_ZH —— 请先执行: node $TOOL_DIR/build.js all"
[ -d "$INSTALL_DIR" ] || die "未找到已安装的 SideQuest: $INSTALL_DIR"
say "1/5 生成隔离版 app(userData -> SideQuestDesktop-zhtest)"
rm -rf "$WORK/app-zh-test"
cp -a "$APP_ZH" "$WORK/app-zh-test"
node -e '
const fs = require("fs");
const p = process.argv[1];
let s = fs.readFileSync(p, "utf8");
const from = "const MAIN_USER_DATA_DIR = \x27SideQuestDesktop\x27;";
const to = "const MAIN_USER_DATA_DIR = \x27SideQuestDesktop-zhtest\x27;";
if (s.indexOf(from) !== -1) {
fs.writeFileSync(p, s.replace(from, to), "utf8");
console.log(" 已隔离 userData");
} else if (s.indexOf(to) !== -1) {
console.log(" 已隔离,跳过");
} else {
console.error(" 未找到 MAIN_USER_DATA_DIR,上游结构可能已变");
process.exit(1);
}
' "$WORK/app-zh-test/dist-electron/main.js"
ok "app 就绪: $WORK/app-zh-test"
say "2/5 打包隔离版 asar"
node "$TOOL_DIR/asar.js" pack "$WORK/app-zh-test" "$WORK/app.test.asar" >/dev/null
ok "asar 就绪($(stat -c%s "$WORK/app.test.asar") 字节)"
say "3/5 准备隔离配置"
if [ ! -d "$DATA_TEST" ]; then
if [ -d "$DATA_LIVE" ]; then
cp -a "$DATA_LIVE" "$DATA_TEST"
ok "已复制真实配置 -> $DATA_TEST"
else
mkdir -p "$DATA_TEST"
ok "真实配置不存在,使用空配置"
fi
else
ok "沿用已有的隔离配置: $DATA_TEST"
fi
say "4/5 组装运行时 $RUNTIME"
rm -rf "$RUNTIME"
mkdir -p "$RUNTIME/resources"
# 主二进制必须真实复制:Node 会解析符号链接,process.execPath 决定 Electron 去哪里找 resources
cp --reflink=auto "$INSTALL_DIR/sidequest" "$RUNTIME/sidequest"
for f in "$INSTALL_DIR"/*; do
name="$(basename "$f")"
[ "$name" = "sidequest" ] && continue
[ "$name" = "resources" ] && continue
ln -s "$f" "$RUNTIME/$name"
done
for f in "$INSTALL_DIR"/resources/*; do
name="$(basename "$f")"
[ "$name" = "app.asar" ] && continue
ln -s "$f" "$RUNTIME/resources/$name"
done
# asar 不走符号链接(Electron 会加载失败),必须是实体文件
cp --reflink=auto "$WORK/app.test.asar" "$RUNTIME/resources/app.asar"
ok "运行时就绪: $RUNTIME"
say "5/5 启动(远程调试端口 $PORT)"
rm -f "$DATA_TEST"/Singleton* 2>/dev/null || true
find "$DATA_TEST" -name LOCK -delete 2>/dev/null || true
LOG="$WORK/test-run.log"
mkdir -p "$WORK"
setsid nohup "$RUNTIME/sidequest" --remote-debugging-port="$PORT" >"$LOG" 2>&1 </dev/null &
disown
sleep 10
if curl -s --max-time 6 "http://127.0.0.1:$PORT/json/list" >/dev/null 2>&1; then
ok "启动成功"
curl -s --max-time 6 "http://127.0.0.1:$PORT/json/list" | node -e '
let d = ""; process.stdin.on("data", c => d += c).on("end", () => {
try { JSON.parse(d).filter(t => t.type === "page").forEach(t => console.log(" " + String(t.title || "").slice(0, 34) + " | " + String(t.url || "").slice(0, 60))); } catch (e) {}
});'
else
bad "启动失败,日志尾部:"
tail -25 "$LOG"
rm -rf "$GLIBC_MARK"
exit 1
fi
grep -q "l10n-zh" "$LOG" && ok "汉化注入已生效" || bad "未见汉化注入日志"
rm -rf "$GLIBC_MARK"
echo
echo "结束请执行: bash $TOOL_DIR/stop-test.sh"