Skip to content

Windows 上的安卓应用运行器:双击 APK 即装,应用以独立窗口与桌面图标运行,自持 QEMU 运行时

fix: 更新助手改用普通子进程(分离进程会被部分安全软件静默拦掉)

RoutineMiku0fa5e9011c76
diff --git a/src/core/updater.js b/src/core/updater.js
index 1c44a4c..2f30919 100644
--- a/src/core/updater.js
+++ b/src/core/updater.js
@@ -279,10 +279,14 @@ class Updater {
// -EncodedCommand 走 UTF-16LE base64:脚本里出现中文路径也不会被 GBK 解码搞坏
const b64 = Buffer.from(script, 'utf16le').toString('base64');
const ps = path.join(process.env.SystemRoot || 'C:\\Windows', 'System32', 'WindowsPowerShell', 'v1.0', 'powershell.exe');
+ // 这里**不能**用 detached:某些安全软件 / 沙箱策略会直接拦掉「分离的控制台进程」,
+ // 表现为脚本一声不响地根本没跑(更新界面卡在「正在替换程序并重启」)。
+ // Windows 上父进程退出并不会杀掉普通子进程,所以用「普通子进程 + unref」同样能在
+ // 我们退出之后继续干活,兼容性还更好。
const child = spawn(ps, [
'-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass',
'-WindowStyle', 'Hidden', '-EncodedCommand', b64,
- ], { detached: true, stdio: 'ignore', windowsHide: true });
+ ], { stdio: 'ignore', windowsHide: true });
child.unref();
return true;
}
diff --git a/tools/check-update.js b/tools/check-update.js
index c8772c7..ea2c3ef 100644
--- a/tools/check-update.js
+++ b/tools/check-update.js
@@ -91,7 +91,35 @@ const ok = (c, m) => console.log(`${c ? '✓' : '✗'} ${m}`);
check(newExe === 'new-exe', '安装目录里的 ApkStart.exe 已被替换');
check(newMain === 'new-main', '子目录里的文件也替换成功');
+ // ---- 4. apply() 真的起一个进程去替换(异步链路,不走网络)----
+ const install2 = path.join(sandbox, 'install2');
+ const payload2 = path.join(sandbox, 'payload2');
+ fs.mkdirSync(install2, { recursive: true });
+ fs.mkdirSync(payload2, { recursive: true });
+ fs.writeFileSync(path.join(install2, 'ApkStart.exe'), 'old-exe');
+ fs.writeFileSync(path.join(install2, 'marker.txt'), 'old');
+ fs.writeFileSync(path.join(payload2, 'ApkStart.exe'), 'new-exe');
+ fs.writeFileSync(path.join(payload2, 'marker.txt'), 'new');
+
+ const u3 = new Updater({
+ currentVersion: '0.0.0',
+ exePath: path.join(install2, 'ApkStart.exe'),
+ isPackaged: true,
+ dataDir: sandbox,
+ });
+ const decoy2 = spawn(process.execPath, ['-e', 'setTimeout(()=>{},600)'], { stdio: 'ignore' });
+ u3.apply({ mode: 'zip', payload: payload2, version: '9.9.8' }, { waitPid: decoy2.pid });
+ let asyncOk = false;
+ for (let i = 0; i < 40; i += 1) {
+ await sleep(500);
+ try {
+ if (fs.readFileSync(path.join(install2, 'marker.txt'), 'utf8') === 'new') { asyncOk = true; break; }
+ } catch (_) { /* 还在替换 */ }
+ }
+ check(asyncOk, 'apply() 在后台进程里完成了替换(异步链路可用)');
+
try { decoy.kill(); } catch (_) { /* ignore */ }
+ try { decoy2.kill(); } catch (_) { /* ignore */ }
fs.rmSync(sandbox, { recursive: true, force: true });
console.log('');