Windows 上的安卓应用运行器:双击 APK 即装,应用以独立窗口与桌面图标运行,自持 QEMU 运行时
feat: 声音、可选安装位置、卸载清理进程、VC++ 兼容与发布修复
RoutineMikua558afc8958a
diff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex e5988d6..bbbacf5 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -95,8 +95,25 @@ jobs:XZ_PRESET: '6'XZ_TIMEOUT_MS: '3600000'+ # 内置微软 VC++ 2015-2022 x64 运行库:安卓模拟器(Qt6)与 qemu 都依赖它,+ # 缺了在「其他电脑」上会直接起不来(0xc0000135 / MSVCP140 缺失)。+ # 放到 build/runtime 内,随 extraResources 一起打进安装包;离线也能一键安装。+ - name: 下载 VC++ 运行库(离线内置)+ shell: pwsh+ run: |+ $dir = "build\runtime"+ if (-not (Test-Path $dir)) { New-Item -ItemType Directory -Force -Path $dir | Out-Null }+ $out = "$dir\vc_redist.x64.exe"+ Write-Output "下载 VC++ 2015-2022 x64 运行库…"+ curl.exe -L -o $out "https://aka.ms/vs/17/release/vc_redist.x64.exe"+ if (-not (Test-Path $out) -or (Get-Item $out).Length -lt 1MB) { Write-Error "vc_redist 下载失败" }+ Get-Item $out | Select-Object Name, Length++ # 不打 git tag 时 electron-builder 不会隐式发布;打了 tag 也会因为本 job 没有+ # GH_TOKEN 而报 "GitHub Personal Access Token is not set" 后退出 1(之前完整版一直失败的根因)。+ # 这里显式 --publish never,安装包由后面「上传完整版到 Release」步骤用 gh release upload 上传。- name: 构建完整版安装包- run: npx electron-builder --win nsis+ run: npx electron-builder --win nsis --publish neverenv:CSC_IDENTITY_AUTO_DISCOVERY: 'false'diff --git a/build/installer.nsh b/build/installer.nshnew file mode 100644index 0000000..f1956bd--- /dev/null+++ b/build/installer.nsh@@ -0,0 +1,20 @@+; ApkStart 自定义 NSIS 脚本+; 作用:卸载开始前,先结束可能仍在后台驻留的运行时进程,+; 否则它们会锁住安装目录里的文件,导致卸载不干净、第三方粉碎工具也删不掉。+;+; ApkStart 退出后仍可能留下 detached 的 qemu(为了下次秒开),+; 所以卸载环节必须自己兜底清一遍。++!macro customUnInstall+ DetailPrint "正在结束 ApkStart 残留进程…"+ ; /F 强杀 /T 连带子进程。进程不存在时 taskkill 返回 128,忽略即可。+ nsExec::Exec 'taskkill.exe /F /T /IM ApkStart.exe'+ nsExec::Exec 'taskkill.exe /F /T /IM qemu-system-x86_64.exe'+ nsExec::Exec 'taskkill.exe /F /T /IM qemu-system-i386.exe'+ nsExec::Exec 'taskkill.exe /F /T /IM emulator.exe'+ nsExec::Exec 'taskkill.exe /F /T /IM emulator-check.exe'+ nsExec::Exec 'taskkill.exe /F /T /IM adb.exe'+ nsExec::Exec 'taskkill.exe /F /T /IM netsimd.exe'+ ; 给一点时间让进程真正退出、释放文件句柄+ Sleep 1500+!macroenddiff --git a/electron-builder.yml b/electron-builder.ymlindex 5814d74..c986031 100644--- a/electron-builder.yml+++ b/electron-builder.yml@@ -46,10 +46,17 @@ win:requestedExecutionLevel: asInvokernsis:- oneClick: true+ # 不再是「一键装到 C 盘默认目录」:改为标准向导,允许用户选择安装位置+ # (装到非系统盘可减轻 C 盘压力;运行时数据目录另在设置里单独指定)。+ oneClick: falseperMachine: false+ allowToChangeInstallationDirectory: true+ displayLanguageSelector: falsecreateDesktopShortcut: trueartifactName: ApkStart-${version}-Setup.exe+ # 卸载前先结束仍在运行的运行时进程,避免文件被锁导致无法删除+ # (火绒等粉碎工具删不掉,多半是 qemu/adb 进程还驻留)。+ include: build/installer.nsh# 安装包本身已含完整运行时(emulator + 系统镜像 .gz),装完首次启动# 自动把镜像展开到用户目录,之后不再联网下载任何东西。diff --git a/src/core/doctor.js b/src/core/doctor.jsindex 2234bf2..e8c8044 100644--- a/src/core/doctor.js+++ b/src/core/doctor.js@@ -404,10 +404,29 @@ function writeReport({ dataDir, profile, logLines = [], extra = {} }) {return { file, diagnosis: d };}+/**+ * 检测微软 VC++ 2015-2022 x64 运行库是否安装。+ * 安卓模拟器(Qt6)与 qemu 都依赖它;缺了在「其他电脑」上会直接起不来+ * (报 0xc0000135 / MSVCP140 缺失)。安装版我们已内置 vc_redist.x64.exe,+ * 这里只做检测,供启动前给出明确提示与一键安装入口。+ */+function vcRedistOk() {+ if (process.platform !== 'win32') return true;+ const key = 'HKLM\\SOFTWARE\\Microsoft\\VisualStudio\\14.0\\VC\\Runtimes\\x64';+ for (const k of [key, key.replace('SOFTWARE\\', 'SOFTWARE\\WOW6432Node\\')]) {+ try {+ const out = execFileSync('reg', ['query', k, '/v', 'Installed'],+ { encoding: 'utf8', windowsHide: true, timeout: 5000, stdio: ['ignore', 'pipe', 'ignore'] });+ if (/Installed\s+REG_DWORD\s+0x1/i.test(out)) return true;+ } catch (_) { /* 键不存在 = 没装 */ }+ }+ return false;+}+module.exports = {hostInfo, freeDiskMB, isAsciiPath, shortPath, lcdFor, liteProfile,versionNumbers, gpuCandidates, chooseProfile, planVariants,overridesFromSettings, autoProfile,freePortPair, freeAdbPort, snapshotKey,- diagnose, describeProfile, writeReport,+ diagnose, describeProfile, writeReport, vcRedistOk,};diff --git a/src/core/emulator.js b/src/core/emulator.jsindex b9e8316..b471a12 100644--- a/src/core/emulator.js+++ b/src/core/emulator.js@@ -291,7 +291,9 @@ class EmulatorEngine {const args = ['-avd', AVD_NAME,'-port', String(port),- '-no-audio',+ // 音频:默认开启(让安卓应用的提示音/视频声音能放出来)。+ // 仅当用户在设置里显式关闭时才传 -no-audio 省一点 CPU。+ ...(this.settings?.engine?.audio === false ? ['-no-audio'] : []),'-no-boot-anim','-no-metrics',// 关掉崩溃上报:一旦历史崩溃报告存在,emulator 会弹「同意上传」模态框,diff --git a/src/core/engine.js b/src/core/engine.jsindex 8d60f55..fafe4c3 100644--- a/src/core/engine.js+++ b/src/core/engine.js@@ -925,6 +925,10 @@ class Runtime {try { this.vmProc.kill(); } catch (_) { /* ignore */ }this.vmProc = null;}+ // 退出时务必清掉 detached 的 qemu 进程:它独立于 ApkStart 存活(为了下次秒开),+ // 不在此强杀会一直锁住安装目录里的文件,导致卸载不干净、第三方粉碎工具也删不掉。+ // 仅在本进程真正退出时调用,不影响「关窗口→托盘常驻→下次秒开」的体验。+ this.emulator.killOrphanProcesses().catch(() => {});}get bootLog() { return this._bootLog.slice(-60); }diff --git a/src/core/store.js b/src/core/store.jsindex 33e4a25..374be9d 100644--- a/src/core/store.js+++ b/src/core/store.js@@ -30,6 +30,7 @@ const DEFAULT_SETTINGS = {headless: false,gpuMode: 'auto', // auto = 按 emulator 版本自动挑后端并逐级降级forceTcg: false, // 保留给高级排障;正常路径已由 doctor 自动回退+ audio: true, // 安卓应用的声音(提示音/视频)。关闭可省一点 CPU// ---- 轻量容器(默认全开省资源,用户可逐项关掉)----liteMode: true, // 收敛 vCPU 配额,避免 qemu 占满物理核拖慢 Windows// 鼠标键位:左键由模拟器原生映射为「确认/点击」,无需开关。diff --git a/src/main.js b/src/main.jsindex 468ffa6..922c3c0 100644--- a/src/main.js+++ b/src/main.js@@ -533,10 +533,22 @@ function registerIpc() {version: app.getVersion(),isDev: IS_DEV,dataDir: store.DATA_DIR,+ runtimeDir: runtime.provisioner.paths().root,exe: process.execPath,packaged: app.isPackaged,}));+ // 选文件夹(用于把运行时/镜像/已装应用挪到非系统盘)+ ipcMain.handle('dialog:openDir', async (_e, defaultPath) => {+ const r = await dialog.showOpenDialog(mainWindow, {+ title: '选择数据存放目录',+ defaultPath: defaultPath || store.DATA_DIR,+ properties: ['openDirectory', 'createDirectory'],+ });+ if (r.canceled || !r.filePaths || !r.filePaths[0]) return null;+ return r.filePaths[0];+ });+ipcMain.handle('apps:list', async () => {const apps = store.getApps();const settings = store.getSettings();@@ -699,6 +711,36 @@ function registerIpc() {return r;});+ // 微软 VC++ 2015-2022 x64 运行库:安卓模拟器(Qt6)与 qemu 都依赖它。+ // 缺了在「其他电脑」上会直接起不来(0xc0000135 / MSVCP140 缺失)。+ function vcRedistInstaller() {+ const p = runtime.provisioner.paths();+ const cands = [+ path.join(p.root, 'vc_redist.x64.exe'),+ path.join(process.resourcesPath || '', 'runtime', 'vc_redist.x64.exe'),+ ];+ return cands.find((c) => c && fs.existsSync(c)) || null;+ }+ ipcMain.handle('runtime:vcRedist', () => {+ const doctor = require('./core/doctor');+ return { ok: doctor.vcRedistOk(), path: vcRedistInstaller() };+ });+ ipcMain.handle('runtime:installVcRedist', async () => {+ const file = vcRedistInstaller();+ if (!file) return { ok: false, reason: 'no-installer' };+ const { spawn } = require('child_process');+ await new Promise((resolve) => {+ // 用 RunAs 提权安装(VC++ 是系统级组件,需要管理员);/quiet 静默 /norestart 不重启+ const ps = spawn('powershell.exe', ['-NoProfile', '-Command',+ `Start-Process -FilePath "${file}" -ArgumentList '/quiet','/norestart' -Verb RunAs -Wait`],+ { windowsHide: true, stdio: 'ignore' });+ ps.on('exit', () => resolve());+ ps.on('error', () => resolve());+ });+ const doctor = require('./core/doctor');+ return { ok: doctor.vcRedistOk() };+ });+ipcMain.handle('runtime:usage', () => runtime.usage());ipcMain.handle('runtime:cleanup', async (_e, opts = {}) => {diff --git a/src/preload.js b/src/preload.jsindex f07e899..b68c5a5 100644--- a/src/preload.js+++ b/src/preload.js@@ -16,6 +16,7 @@ contextBridge.exposeInMainWorld('apkstart', {pin: (pkg, pinned) => invoke('app:pin', { pkg, pinned }),revealApk: (pkg) => invoke('app:revealApk', pkg),revealApkDir: () => invoke('apk:reveal'),+ openDir: () => invoke('dialog:openDir'),getSettings: () => invoke('settings:get'),setSettings: (patch) => invoke('settings:set', patch),@@ -30,6 +31,8 @@ contextBridge.exposeInMainWorld('apkstart', {runtimeLog: () => invoke('runtime:log'),doctorProfile: () => invoke('doctor:profile'),doctorReport: () => invoke('doctor:report'),+ vcRedist: () => invoke('runtime:vcRedist'),+ installVcRedist: () => invoke('runtime:installVcRedist'),runtimeUsage: () => invoke('runtime:usage'),runtimeCleanup: (opts) => invoke('runtime:cleanup', opts || {}),displayState: () => invoke('display:state'),diff --git a/src/ui/app.js b/src/ui/app.jsindex c21097e..66a476e 100644--- a/src/ui/app.js+++ b/src/ui/app.js@@ -629,6 +629,7 @@ function fillSettings(s) {$('setMemory').value = s.engine.memoryMB;$('setCores').value = s.engine.cores;$('setIdle').value = s.engine.idleShutdownMinutes;+ $('setAudio').checked = s.engine.audio !== false;$('setLiteMode').checked = s.engine.liteMode !== false;$('setPriorityMode').value = s.engine.priorityMode === 'performance' ? 'performance' : 'balanced';$('setDeepTrim').checked = !!s.engine.deepTrim;@@ -653,7 +654,7 @@ async function openSettings() {state.settings = await api.getSettings();fillSettings(state.settings);const info = await api.info();- $('setDataDir').value = info.dataDir;+ $('setRuntimeDir').value = info.runtimeDir || info.dataDir;const verEl = document.getElementById('aboutVer');if (verEl && info.version) verEl.textContent = `v${info.version}`;const assoc = await api.assocStatus();@@ -693,6 +694,7 @@ function bindSettings() {$('setMemory').addEventListener('change', (e) => save({ engine: { memoryMB: Number(e.target.value) || 0 } }));$('setCores').addEventListener('change', (e) => save({ engine: { cores: Number(e.target.value) || 0 } }));$('setIdle').addEventListener('change', (e) => save({ engine: { idleShutdownMinutes: Number(e.target.value) || 0 } }));+ $('setAudio').addEventListener('change', (e) => save({ engine: { audio: e.target.checked } }));$('setLiteMode').addEventListener('change', (e) => save({ engine: { liteMode: e.target.checked } }));$('setPriorityMode').addEventListener('change', (e) => save({ engine: { priorityMode: e.target.value } }));const savePointer = async (patch) => {@@ -825,7 +827,16 @@ function bindSettings() {})();$('btnOpenData').addEventListener('click', async () => {const info = await api.info();- window.open(`file:///${info.dataDir.replace(/\\/g, '/')}`);+ const dir = info.runtimeDir || info.dataDir;+ window.open(`file:///${dir.replace(/\\/g, '/')}`);+ });+ $('btnBrowseRuntimeDir').addEventListener('click', async () => {+ const info = await api.info();+ const picked = await api.openDir();+ if (!picked) return;+ await api.setSettings({ runtime: { dir: picked } });+ $('setRuntimeDir').value = picked;+ toast({ title: '数据目录已更新', body: '请重启 ApkStart 使其生效(旧数据不会自动搬移)', type: 'ok', sticky: true });});$('btnProbe').addEventListener('click', async () => {@@ -875,6 +886,24 @@ function bindSettings() {/* ---------------- 事件绑定 ---------------- */function bindEvents() {+ // VC++ 运行库:一键提权安装(内置安装包优先,否则提示去官网)+ const btnVc = document.getElementById('btnInstallVcRedist');+ if (btnVc) btnVc.addEventListener('click', async () => {+ btnVc.disabled = true;+ const r = await api.installVcRedist().catch(() => ({ ok: false }));+ if (r && r.ok) {+ document.getElementById('vcRedistWarn').hidden = true;+ toast({ title: 'VC++ 运行库已安装', body: '现在可以启动运行时了', type: 'ok' });+ } else if (r && r.reason === 'no-installer') {+ api.openExternal('https://learn.microsoft.com/zh-CN/cpp/windows/latest-supported-vc-redist?view=msvc-170#visual-studio-2015-2017-2019-and-2022');+ toast({ title: '未找到内置安装包', body: '已打开微软官方下载页,请下载 x64 版本', type: 'info' });+ btnVc.disabled = false;+ } else {+ toast({ title: '安装未完成', body: '可能被取消或需要管理员权限,请重试', type: 'error' });+ btnVc.disabled = false;+ }+ });+// 链接统一走系统浏览器document.addEventListener('click', (e) => {const a = e.target.closest && e.target.closest('a[href^="http"]');@@ -1039,10 +1068,24 @@ async function init() {await refreshStatus();await refreshApps();refreshAndroid();+ checkVcRedist();setInterval(refreshStatus, 6000);setInterval(refreshApps, 15000);}+// VC++ 运行库检测:缺失时显示横幅,提供一键提权安装+async function checkVcRedist() {+ const warn = document.getElementById('vcRedistWarn');+ if (!warn) return;+ try {+ const r = await api.vcRedist();+ if (r && r.ok) { warn.hidden = true; return; }+ warn.hidden = false;+ warn._hasInstaller = !!r.path;+ document.getElementById('btnInstallVcRedist').disabled = !r.path;+ } catch (_) { /* 检测失败不阻断主流程 */ }+}+init().catch((e) => {console.error(e);toast({ title: '初始化失败', body: e.message, type: 'error', sticky: true });diff --git a/src/ui/index.html b/src/ui/index.htmlindex 65ea5e7..df54ba1 100644--- a/src/ui/index.html+++ b/src/ui/index.html@@ -113,6 +113,14 @@<a class="status-item powered-link" href="https://github.com/RoutineMiku/apkstart" target="_blank" rel="noopener">Powered by RoutineMiku</a></div></footer>++ <div id="vcRedistWarn" hidden style="display:flex;align-items:center;gap:12px;margin:10px 14px;padding:10px 14px;border-radius:10px;background:#3a1d1d;color:#ffd9d9;border:1px solid #6b2b2b;">+ <div style="flex:1;">+ <strong style="display:block;">缺少 VC++ 运行库(x64)</strong>+ <span style="font-size:12px;opacity:.9;">安卓运行时依赖微软 VC++ 2015-2022。未安装会导致模拟器无法启动——这是「其他电脑装不上/起不来」最常见的原因。</span>+ </div>+ <button class="btn small" id="btnInstallVcRedist">一键安装(需管理员)</button>+ </div></main><!-- 安装进度 -->@@ -227,6 +235,13 @@<div class="group"><div class="group-title">性能与轻量容器</div>+ <div class="field switch-field">+ <div>+ <label>安卓声音</label>+ <span class="sub">让应用提示音、视频声音正常播放。仅在你完全不需要声音、想再省一点 CPU 时关闭。</span>+ </div>+ <input type="checkbox" id="setAudio" class="switch" />+ </div><div class="field switch-field"><div><label>轻量容器(推荐)</label>@@ -432,11 +447,13 @@<button class="btn ghost sm" id="btnAssoc">检查中…</button></div><div class="field">- <label>数据目录</label>+ <label>运行时数据目录(系统镜像 · 已装应用 · 快照)</label><div class="row">- <input id="setDataDir" type="text" readonly />+ <input id="setRuntimeDir" type="text" readonly placeholder="默认:C 盘用户数据目录" />+ <button class="btn ghost sm" id="btnBrowseRuntimeDir">浏览</button><button class="btn ghost sm" id="btnOpenData">打开</button></div>+ <span class="sub">这里占用空间最大(数 GB)。改到非系统盘可大幅减轻 C 盘压力;修改后需重启软件,已存在的数据不会自动搬移(请手动复制后删除旧目录)。</span></div></div><div class="group" id="aboutGroup">diff --git a/test/auto-test.js b/test/auto-test.jsindex e6de3ea..8d2a591 100644--- a/test/auto-test.js+++ b/test/auto-test.js@@ -309,6 +309,19 @@ const { AdbClient, friendlyInstallError, friendlyLaunchError } = require('../srcassert(/-no-window/.test(headless) && !/-no-skin/.test(headless));});+ await test('音频:默认开启(不带 -no-audio),关闭后才带 -no-audio', () => {+ const { EmulatorEngine } = require('../src/core/emulator');+ const emu = new EmulatorEngine(path.join(__dirname, '..'));+ // 覆盖 settings getter:默认开启不应有 -no-audio+ Object.defineProperty(emu, 'settings', { configurable: true, get: () => ({ engine: { audio: true } }) });+ const on = emu.buildArgs({ headless: false, gpu: 'software' }).join(' ');+ assert(!/-no-audio/.test(on), 'audio=true 时不应传 -no-audio');+ // 关闭后才应带 -no-audio+ Object.defineProperty(emu, 'settings', { configurable: true, get: () => ({ engine: { audio: false } }) });+ const off = emu.buildArgs({ headless: false, gpu: 'software' }).join(' ');+ assert(/-no-audio/.test(off), 'audio=false 时应传 -no-audio');+ });+await test('旧配置强制迁移:无头与「启动后退出」不再生效', () => {const store = require('../src/core/store');store.saveSettings({ engine: { headless: true }, hideAfterLaunch: true });