Skip to content

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

feat: 快捷方式加固、环境自检与磁盘守卫(v0.2.8)

RoutineMiku8c43681fe399
diff --git a/build/installer.nsh b/build/installer.nsh
index f1956bd..79624bc 100644
--- a/build/installer.nsh
+++ b/build/installer.nsh
@@ -5,7 +5,27 @@
; ApkStart 退出后仍可能留下 detached 的 qemu(为了下次秒开),
; 所以卸载环节必须自己兜底清一遍。
+; 安装收尾:再兜一层桌面图标。
+; electron-builder 的 createDesktopShortcut 走的是它自己的 CreateShortcuts 流程,
+; 个别环境(桌面被 OneDrive 重定向、快捷方式被安全软件回滚)里会生成失败,
+; 用户装完发现桌面上什么都没有。这里用 NSIS 原生的 CreateShortcut 再写一次:
+; $DESKTOP 走 SHGetFolderPath,能正确跟随桌面的重定向路径;写成幂等操作,
+; 和 electron-builder 的重复执行也只是覆盖同一个 .lnk。
+!macro customInstall
+ DetailPrint "正在创建桌面快捷方式…"
+ CreateShortcut "$DESKTOP\ApkStart.lnk" "$INSTDIR\ApkStart.exe" "" "$INSTDIR\ApkStart.exe" 0 \
+ SW_SHOWNORMAL "" "ApkStart — 在电脑上直接运行安卓应用"
+ CreateDirectory "$SMPROGRAMS\ApkStart"
+ CreateShortcut "$SMPROGRAMS\ApkStart\ApkStart.lnk" "$INSTDIR\ApkStart.exe" "" "$INSTDIR\ApkStart.exe" 0 \
+ SW_SHOWNORMAL "" "ApkStart — 在电脑上直接运行安卓应用"
+!macroend
+
!macro customUnInstall
+ ; 先删自己写的快捷方式入口(未安装 ApkStart 时也应无残留)
+ Delete "$DESKTOP\ApkStart.lnk"
+ Delete "$SMPROGRAMS\ApkStart\ApkStart.lnk"
+ RMDir "$SMPROGRAMS\ApkStart"
+
DetailPrint "正在结束 ApkStart 残留进程…"
; /F 强杀 /T 连带子进程。进程不存在时 taskkill 返回 128,忽略即可。
nsExec::Exec 'taskkill.exe /F /T /IM ApkStart.exe'
diff --git a/electron-builder.yml b/electron-builder.yml
index c986031..a21c68e 100644
--- a/electron-builder.yml
+++ b/electron-builder.yml
@@ -52,7 +52,12 @@ nsis:
perMachine: false
allowToChangeInstallationDirectory: true
displayLanguageSelector: false
- createDesktopShortcut: true
+ # always:即使桌面上已有同名 .lnk 也重建一次。
+ # 默认的 true 只在「不存在」时才创建,某些机器上(安全软件拦截、桌面被
+ # OneDrive 重定向、旧版残留了指向已删目录的坏快捷方式)会出现装完没图标,
+ # 或者图标还指着旧 exe。always 保证每次安装后都指向当前安装目录。
+ createDesktopShortcut: always
+ createStartMenuShortcut: true
artifactName: ApkStart-${version}-Setup.exe
# 卸载前先结束仍在运行的运行时进程,避免文件被锁导致无法删除
# (火绒等粉碎工具删不掉,多半是 qemu/adb 进程还驻留)。
diff --git a/package-lock.json b/package-lock.json
index e330174..7acee15 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "apkstart",
- "version": "0.2.4",
+ "version": "0.2.8",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "apkstart",
- "version": "0.2.4",
+ "version": "0.2.8",
"license": "MIT",
"os": [
"win32"
diff --git a/package.json b/package.json
index 4ae1804..88ddd36 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "apkstart",
"productName": "ApkStart",
- "version": "0.2.7",
+ "version": "0.2.8",
"description": "极致轻量的 Windows 安卓应用运行器:双击 APK 即装,应用以独立窗口与桌面图标运行",
"main": "src/main.js",
"author": "RoutineMiku",
diff --git a/src/core/agent.js b/src/core/agent.js
index ef3c5c0..cf9be7b 100644
--- a/src/core/agent.js
+++ b/src/core/agent.js
@@ -160,6 +160,23 @@ class WinAgent extends EventEmitter {
async detach() { return this.call({ cmd: 'detach' }, 5000); }
async probe() { return this.call({ cmd: 'probe' }, 4000); }
+ /**
+ * 开机阶段把模拟器窗口(QWindowIcon 主帧缓冲)+ 它的工具栏(QWindowTool)
+ * + qemu 的黑色控制台窗口全部藏起来,直到 embed 完成才显示。
+ * 这是「彻底隐藏命令窗口 / 模拟器浮窗」的关键:emulator 拉起 detached 的
+ * qemu 控制台子进程,Node 的 windowsHide 覆盖不到它;只能由窗口代理周期性
+ * 用 ShowWindow(SW_HIDE) 压住。启动即调用,boot 期间每帧都压一次,
+ * 避免任何闪现。失败(非 Windows / 代理不可用)时静默降级,不阻断启动。
+ */
+ async bootHide() {
+ return this.call({ cmd: 'boothide', on: 1 }, 4000).catch(() => ({ ok: false }));
+ }
+
+ /** 开机完成:停止隐藏,并让模拟器窗口显示出来(随后会被 embed 重新父化) */
+ async bootShow() {
+ return this.call({ cmd: 'boothide', on: 0 }, 4000).catch(() => ({ ok: false }));
+ }
+
/**
* 全局鼠标钩子开关(幂等)。
* 只在应用窗口前台、且至少一项映射开启时才安装;opts 变化时不重装线程,
diff --git a/src/core/appwin.js b/src/core/appwin.js
index 572451c..82d1a2c 100644
--- a/src/core/appwin.js
+++ b/src/core/appwin.js
@@ -209,6 +209,10 @@ class AppWindow {
const hwnd = this._hwnd();
if (!hwnd) return false;
const r = await this.agent.embed(hwnd, this._rect()).catch(() => null);
+ if (r && r.ok) {
+ // 嵌入完成后停止「开机隐藏」,让画面显出来(同时把 qemu 控制台黑窗永久藏好)
+ await this.agent.bootShow().catch(() => {});
+ }
return !!(r && r.ok);
}
diff --git a/src/core/installer.js b/src/core/installer.js
index 951b037..c1320ca 100644
--- a/src/core/installer.js
+++ b/src/core/installer.js
@@ -284,35 +284,58 @@ class Installer {
const args = `${baseArgs ? baseArgs + ' ' : ''}--launch "${app.package}"`.trim();
const ico = app.icoPath && fs.existsSync(app.icoPath) ? app.icoPath : undefined;
const paths = this.shortcutPaths(app);
+
+ const write = (shortcutPath) => writeShortcut({
+ shortcutPath,
+ target,
+ args,
+ iconIcoPath: ico,
+ description: `${app.label} — 由 ApkStart 运行`,
+ cwd: this.ctx.cwd,
+ // 每个应用一个 AUMID:任务栏上按应用分组,不会全挤到 ApkStart 里
+ appUserModelId: `RoutineMiku.ApkStart.${app.package}`.slice(0, 128),
+ });
+
let first = null;
+ let startMenuPath = null;
const errors = [];
- for (const p of paths) {
+ paths.forEach((p, i) => {
try {
- writeShortcut({
- shortcutPath: p,
- target,
- args,
- iconIcoPath: ico,
- description: `${app.label} — 由 ApkStart 运行`,
- cwd: this.ctx.cwd,
- // 每个应用一个 AUMID:任务栏上按应用分组,不会全挤到 ApkStart 里
- appUserModelId: `RoutineMiku.ApkStart.${app.package}`.slice(0, 128),
- });
+ write(p);
if (!first) first = p;
+ if (i === 1) startMenuPath = p;
} catch (e) {
errors.push(`${p}: ${e.message}`);
}
+ });
+
+ // 主路径全失败(自定义快捷方式目录不可写 / 被安全软件拦截):
+ // 退回桌面再试一次——桌面上有图标,用户才找得到应用。
+ if (!first) {
+ const fallback = path.join(this.ctx.desktopDir, `${safeFileName(app.label)}.lnk`);
+ try {
+ write(fallback);
+ first = fallback;
+ } catch (e) {
+ errors.push(`${fallback}: ${e.message}`);
+ }
}
if (!first) throw new Error(errors.join('; ') || '创建快捷方式失败');
// 开始菜单那份的路径也存下来,卸载时一起删
- store.upsertApp({ package: app.package, startMenuPath: paths[1] || null });
+ if (startMenuPath || first) {
+ store.upsertApp({ package: app.package, startMenuPath });
+ }
return first;
}
/** 补全缺失的快捷方式与图标:老版本只建了桌面那份,且 WebP 图标当时没转成功 */
async ensureShortcuts() {
const made = [];
+ // 用户明确关掉「安装后自动创建」、且这个应用本来就没有任何入口时不要擅自补,
+ // 否则开关关掉了也挡不住启动时被重建。
+ const auto = store.getSettings().createShortcutOnInstall !== false;
for (const app of store.getApps()) {
+ if (!auto && !app.shortcutPath && !app.startMenuPath) continue;
let dirty = false;
if ((!app.icoPath || !fs.existsSync(app.icoPath)) && app.iconPath && fs.existsSync(app.iconPath)) {
try {
@@ -330,8 +353,8 @@ class Installer {
if (!missing.length && !dirty) continue;
try {
// 图标刚补出来时,即使 .lnk 存在也要重建,让快捷方式换上真实应用图标
- this.createShortcut(app);
- store.upsertApp({ package: app.package, shortcutPath: this.shortcutPath(app) });
+ const madePath = this.createShortcut(app);
+ store.upsertApp({ package: app.package, shortcutPath: madePath });
made.push(app.label);
} catch (_) { /* 单个失败不阻塞启动 */ }
}
diff --git a/src/core/provision.js b/src/core/provision.js
index 5253fd4..482f548 100644
--- a/src/core/provision.js
+++ b/src/core/provision.js
@@ -10,6 +10,7 @@ const path = require('path');
const zlib = require('zlib');
const { spawn, execFile } = require('child_process');
const store = require('./store');
+const doctor = require('./doctor');
const { download, downloadAny, downloadAnyParallel, head } = require('./download');
const { ZipArchive, ZipFile } = require('./zip');
@@ -158,6 +159,30 @@ class Provisioner {
return p;
}
+ /**
+ * 磁盘守卫:在下载 / 解压一份大体积组件之前,先确认目标盘有足够可用空间。
+ * 否则会下到一半把系统盘撑爆,或解压阶段直接失败(且残留半截文件)。
+ * 预留 1GB 缓冲:模拟器/镜像解压后还有快照、用户数据分区会持续膨胀。
+ * @param {string} component 组件名(决定所需空间估算)
+ * @param {string} targetDir 写入目录(据此定位所在盘)
+ */
+ async guardDisk(component, targetDir) {
+ const need = {
+ adb: 64, emulator: 600, sysimg: 1800, playimg: 1800, qemu: 320, iso: 1100, aehd: 64,
+ }[component] || 512; // MB
+ const buf = 1024; // 额外预留 1GB(快照 / 数据分区 / 解压中间文件)
+ const dir = targetDir || this.root;
+ const free = doctor.freeDiskMB(dir);
+ if (free && free < need + buf) {
+ throw new Error(
+ `目标磁盘空间不足:该组件约需 ${need + buf} MB,但「${dir}」所在盘仅剩 ${free} MB。\n`
+ + '建议:把「运行时数据目录」改到空间更大的盘(设置 → 系统集成 → 运行时数据目录 → 浏览),'
+ + '或先清理磁盘 / 卸载不用的应用后再试。',
+ );
+ }
+ return free;
+ }
+
// ---------------- 环境检查 ----------------
async hypervisor() {
@@ -309,6 +334,7 @@ class Provisioner {
async installAdb(onProgress = () => {}) {
const p = this.ensureDirs();
+ await this.guardDisk('adb', p.root);
const zipPath = path.join(p.tmp, 'platform-tools.zip');
onProgress({ stage: 'download', message: '下载 Android platform-tools(约 8MB)…', percent: 2 });
@@ -605,6 +631,11 @@ class Provisioner {
if (usable) {
const kind = hasAehdFile && /aehd/i.test(text) ? 'aehd' : 'whpx';
result = { ok: true, kind, note: kind === 'whpx' ? 'WHPX 硬件加速已启用' : 'AEHD 硬件加速已启用' };
+ } else if (/can't find the emulator-check|corrupted tools installation/i.test(text) && hasAehdFile) {
+ // 部分精简运行时包会漏掉 emulator-check.exe,导致 -accel-check 无法给出结论。
+ // 此时只要 AEHD 驱动已安装,就按「可用」处理:启动时 emulator 自己会挂载驱动,
+ // 避免被误判成无加速而强行 -accel off(软件模拟在部分机器上会直接崩溃)。
+ result = { ok: true, kind: 'aehd', note: 'AEHD 硬件加速已启用(emulator-check 缺失,按驱动判定)' };
} else if (hasAehdFile && /aehd/i.test(text) && !/ERROR_ACCESS_DENIED/i.test(text)) {
result = { ok: true, kind: 'aehd', note: 'AEHD 硬件加速已启用' };
} else if (hv.dll && /whpx/i.test(text) && !/error|denied/i.test(text)) {
@@ -627,6 +658,7 @@ class Provisioner {
/** 下载并安装 emulator(zip 顶层就是 emulator/,直接解到 SDK root) */
async installEmulator(onProgress = () => {}) {
const p = this.ensureDirs();
+ await this.guardDisk('emulator', p.root);
const url = await this.resolveEmulatorUrl();
const zip = path.join(p.tmp, 'emulator.zip');
onProgress({ stage: 'download', message: '下载运行时引擎(约 440MB,走 Google 官方源)…', percent: 1 });
@@ -725,6 +757,7 @@ class Provisioner {
/** 下载并安装 ARM 兼容镜像(Google Play 版,约 1.5GB) */
async installPlayImage(onProgress = () => {}) {
const p = this.ensureDirs();
+ await this.guardDisk('playimg', p.sysImgRoot);
const url = await this.resolvePlayUrl();
const zip = path.join(p.tmp, 'play-sysimg.zip');
onProgress({ stage: 'download', message: '下载 ARM 兼容镜像(Android 14,约 1.5GB)…', percent: 1 });
@@ -767,6 +800,7 @@ class Provisioner {
/** 下载 AEHD 驱动(小文件);安装需要管理员权限,交给引导流程 */
async installAehd(onProgress = () => {}) {
const p = this.ensureDirs();
+ await this.guardDisk('aehd', p.aehdDir);
const zip = path.join(p.tmp, 'aehd.zip');
onProgress({ stage: 'download', message: '下载 AEHD 驱动…', percent: 10 });
await downloadAnyParallel([SOURCES.aehdFallback], zip, { connections: 2 });
@@ -809,6 +843,7 @@ class Provisioner {
async installQemu(onProgress = () => {}) {
const p = this.ensureDirs();
+ await this.guardDisk('qemu', p.root);
const setup = path.join(p.tmp, 'qemu-setup.exe');
onProgress({ stage: 'resolve', message: '查找最新 QEMU 版本…', percent: 1 });
@@ -854,6 +889,7 @@ class Provisioner {
const p = this.ensureDirs();
const s = store.getSettings();
const dest = s.runtime.isoPath || p.iso;
+ await this.guardDisk('iso', path.dirname(dest));
const custom = s.runtime.isoUrl && s.runtime.isoUrl.trim();
const urls = custom ? [custom, ...SOURCES.iso] : SOURCES.iso;
diff --git a/src/core/shortcut.js b/src/core/shortcut.js
index df0245a..10b4efb 100644
--- a/src/core/shortcut.js
+++ b/src/core/shortcut.js
@@ -134,12 +134,21 @@ async function iconToIco(raw, { decode } = {}) {
/**
* 生成桌面快捷方式
+ *
+ * writeShortcutLink 返回 true 并不代表文件真的落盘了:安全软件拦截、
+ * 桌面目录被重定向到未登录的网盘时都可能「成功但没文件」。所以写完必须
+ * 回读一次,保证调用方拿到的路径是真实存在的入口。
+ *
* @param {object} opt { shortcutPath, target, args, iconIcoPath, description, cwd }
*/
function writeShortcut(opt) {
const { shell } = require('electron');
const dir = path.dirname(opt.shortcutPath);
- if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
+ try {
+ if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
+ } catch (e) {
+ throw new Error(`快捷方式目录不可写:${dir}(${e.message})`);
+ }
if (fs.existsSync(opt.shortcutPath)) {
try { fs.unlinkSync(opt.shortcutPath); } catch (_) { /* ignore */ }
}
@@ -153,6 +162,9 @@ function writeShortcut(opt) {
appUserModelId: opt.appUserModelId,
});
if (!ok) throw new Error('创建快捷方式失败(writeShortcutLink 返回 false)');
+ if (!fs.existsSync(opt.shortcutPath)) {
+ throw new Error(`快捷方式未落盘:${opt.shortcutPath}`);
+ }
return opt.shortcutPath;
}
diff --git a/src/core/win/agent.ps1 b/src/core/win/agent.ps1
index b3fbc37..c4cfdea 100644
--- a/src/core/win/agent.ps1
+++ b/src/core/win/agent.ps1
@@ -100,6 +100,9 @@ public class ApkAgent
static readonly ConcurrentQueue<string> _events = new ConcurrentQueue<string>();
static long _lastToolSweep = 0;
static long _embedAt = 0;
+ // 开机隐藏:把模拟器主窗口 + 工具栏 + qemu 控制台黑窗一起压住,直到 embed 完成
+ static volatile bool _bootHide = false;
+ static long _bootHideSweep = 0;
// Hook options. All three default to OFF: an "hook on" without options must
// never swallow anybody's clicks. JS sends the real config on every enable.
@@ -165,6 +168,37 @@ public class ApkAgent
}, IntPtr.Zero);
}
+ // 开机阶段:把 qemu / emulator 的黑色控制台窗口藏起来,避免「命令窗口」闪现。
+ // 它们是 console 子系统进程,Node 的 windowsHide 覆盖不到子进程,只能靠 Win32 周期压住。
+ static void HideConsoleWindows()
+ {
+ var pids = new System.Collections.Generic.HashSet<uint>();
+ try {
+ foreach (var p in Process.GetProcessesByName("qemu-system-x86_64")) pids.Add((uint)p.Id);
+ foreach (var p in Process.GetProcessesByName("emulator")) pids.Add((uint)p.Id);
+ } catch { }
+ if (pids.Count == 0) return;
+ EnumWindows(delegate(IntPtr h, IntPtr p)
+ {
+ uint pid;
+ GetWindowThreadProcessId(h, out pid);
+ if (!pids.Contains(pid)) return true;
+ // 只藏控制台窗口(ConsoleWindowClass),绝不动 Qt 画面窗口(QWindowIcon)
+ if (ClassOf(h).IndexOf("ConsoleWindowClass", StringComparison.Ordinal) >= 0)
+ ShowWindow(h, 0);
+ return true;
+ }, IntPtr.Zero);
+ }
+
+ // 开机隐藏扫描:周期性把模拟器主窗口 + 工具栏 + 控制台黑窗一起压住
+ static void BootHideSweep()
+ {
+ IntPtr e = _emu != IntPtr.Zero ? _emu : FindEmulator();
+ if (e != IntPtr.Zero && IsWindowVisible(e)) ShowWindow(e, 0);
+ HideToolWindows();
+ HideConsoleWindows();
+ }
+
// ------------------------------------------------------------------ embed / detach
static bool Embed(IntPtr host, IntPtr emu)
{
@@ -505,6 +539,13 @@ public class ApkAgent
}
if (_embedAt != 0 && now - _embedAt >= 8000) _embedAt = 0;
+ // 开机阶段周期性隐藏模拟器主窗 + 工具栏 + qemu 控制台黑窗,避免任何闪现
+ if (_bootHide && now - _bootHideSweep > 300)
+ {
+ _bootHideSweep = now;
+ BootHideSweep();
+ }
+
try
{
// Short poll: keep the message pump responsive even when no command
@@ -577,6 +618,23 @@ public class ApkAgent
if (e != IntPtr.Zero) GetWindowRect(e, out r);
Reply(sock, "{\"ok\":true,\"emu\":" + e.ToInt64() + ",\"w\":" + (r.R - r.L) + ",\"h\":" + (r.B - r.T) + "}");
}
+ else if (cmd == "boothide")
+ {
+ if (L(line, "on") == 1)
+ {
+ _bootHide = true;
+ _bootHideSweep = 0;
+ BootHideSweep();
+ }
+ else
+ {
+ _bootHide = false;
+ // embed 完成后 _emu 已经就位,Fit 已把它显示出来;
+ // 这里只确保 qemu 控制台黑窗被永久藏好(不再闪现命令窗口)
+ HideConsoleWindows();
+ }
+ Reply(sock, "{\"ok\":true}");
+ }
else if (cmd == "quit")
{
Reply(sock, "{\"ok\":true}");
diff --git a/src/main.js b/src/main.js
index 922c3c0..cc22b2f 100644
--- a/src/main.js
+++ b/src/main.js
@@ -316,6 +316,34 @@ function launcherInfo() {
return { target: process.execPath, args: `"${APP_ROOT}"`, cwd: APP_ROOT };
}
+/** 递归复制目录内容(best-effort,不删源;用于共享目录改路径时一次性搬迁旧文件) */
+function copyDirContents(src, dest) {
+ if (!fs.existsSync(src)) return;
+ fs.mkdirSync(dest, { recursive: true });
+ for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
+ const s = path.join(src, entry.name);
+ const d = path.join(dest, entry.name);
+ try {
+ if (entry.isDirectory()) copyDirContents(s, d);
+ else fs.copyFileSync(s, d);
+ } catch (_) { /* 单文件失败不影响其余 */ }
+ }
+}
+
+/** 以管理员权限启用一个 Windows 可选功能(如 VirtualMachinePlatform / HypervisorPlatform) */
+function enableWindowsFeature(feature) {
+ return new Promise((resolve) => {
+ const inner = `Enable-WindowsOptionalFeature -Online -FeatureName '${feature}' -NoRestart -All`;
+ const ps = `Start-Process -FilePath powershell.exe -Verb RunAs -Wait `
+ + `-ArgumentList @('-NoProfile','-NonInteractive','-Command',${JSON.stringify(inner)})`;
+ const { spawn } = require('child_process');
+ const proc = spawn('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command', ps],
+ { windowsHide: true, stdio: ['ignore', 'pipe', 'pipe'] });
+ proc.on('exit', (code) => resolve({ ok: code === 0, restart: true, code }));
+ proc.on('error', () => resolve({ ok: false, error: '无法启动 PowerShell' }));
+ });
+}
+
// ---------------- 主窗口 ----------------
function createWindow({ show = true } = {}) {
@@ -453,6 +481,9 @@ async function runLaunch(pkg) {
try {
// 1) 先把「应用窗口」打开显示启动动画:整个过程看不到安卓桌面,也看不到模拟器窗口
openAppWindow(pkg, '正在启动安卓运行时…');
+ // 开机阶段把模拟器主窗 + qemu 控制台黑窗藏起来,避免任何闪现(embed 完成后由
+ // appWin.embed() 调用 bootShow 解除隐藏)。失败(非 Windows/代理不可用)静默降级。
+ if (winAgent) winAgent.bootHide().catch(() => {});
if (mainWindow && mainWindow.isVisible() && !IS_DEV) mainWindow.hide();
const r = await installer.launch(pkg, {
@@ -484,6 +515,8 @@ async function runLaunch(pkg) {
} catch (e) {
appLog(`launch failed ${pkg}: ${e && (e.stack || e.message)}`);
try { appWin.close({ keepApp: true }); } catch (_) { /* ignore */ }
+ // 启动失败也要解除开机隐藏,避免模拟器被永久藏住(下次还能用)
+ if (winAgent) winAgent.bootShow().catch(() => {});
showWindow();
send('toast', { type: 'error', message: `启动失败:${e.message}` });
return { ok: false, error: e.message };
@@ -534,6 +567,9 @@ function registerIpc() {
isDev: IS_DEV,
dataDir: store.DATA_DIR,
runtimeDir: runtime.provisioner.paths().root,
+ diskFreeMB: (() => {
+ try { return require('./core/doctor').freeDiskMB(runtime.provisioner.paths().root); } catch (_) { return 0; }
+ })(),
exe: process.execPath,
packaged: app.isPackaged,
}));
@@ -644,6 +680,24 @@ function registerIpc() {
return next;
});
+ /**
+ * 修改本机共享目录:把旧目录里已有的文件一次性迁到新目录(best-effort,不删旧文件),
+ * 再保存设置。Sharer 每次同步都动态读 store.getSettings().sharedDir,无需重启即可生效。
+ */
+ ipcMain.handle('settings:setSharedDir', async (_e, dir) => {
+ if (!dir || !dir.trim()) return { ok: false, error: '目录不能为空' };
+ const newDir = dir.trim();
+ const oldDir = store.getSettings().sharedDir;
+ try {
+ if (oldDir && oldDir !== newDir) copyDirContents(oldDir, newDir);
+ fs.mkdirSync(newDir, { recursive: true });
+ store.saveSettings({ sharedDir: newDir });
+ return { ok: true, oldDir, newDir };
+ } catch (e) {
+ return { ok: false, error: e.message };
+ }
+ });
+
// ---------------- 显示模式 / 快捷方式 / 一键部署 ----------------
ipcMain.handle('display:state', () => ({
@@ -711,6 +765,65 @@ function registerIpc() {
return r;
});
+ /**
+ * 系统问题自动校验:启动前/运行中自动检查常见导致「装不上、起不来」的根因,
+ * 并给出可操作的修复建议(在首页横幅 + 设置面板里展示,按问题一键修复)。
+ */
+ ipcMain.handle('doctor:selfCheck', async () => {
+ const doctor = require('./core/doctor');
+ const issues = [];
+ // 这两个值在 try 内赋值、在 try 外返回,必须在作用域外声明
+ let accel = { ok: false };
+ let free = 0;
+ try {
+ if (!doctor.vcRedistOk()) {
+ issues.push({
+ code: 'vcRedist', severity: 'error', title: '缺少 VC++ 运行库(x64)',
+ hint: '安卓运行时依赖微软 VC++ 2015-2022,缺失会导致模拟器无法启动(0xc0000135)。', fix: 'vcRedist',
+ });
+ }
+ accel = await runtime.provisioner.emulatorAccel().catch(() => ({ ok: false }));
+ if (!accel.ok) {
+ issues.push({
+ code: 'accel', severity: 'warn', title: '未启用硬件加速',
+ hint: (accel.note || '将回退软件模拟(能跑但很慢)。开启虚拟化后可获得最佳性能。'), fix: 'virtualization',
+ });
+ }
+ free = doctor.freeDiskMB(runtime.provisioner.paths().root);
+ if (free && free < 8192) {
+ issues.push({
+ code: 'disk', severity: free < 2048 ? 'error' : 'warn', title: '运行时磁盘空间紧张',
+ hint: `「${runtime.provisioner.paths().root}」所在盘仅剩 ${free} MB,运行时与镜像可能撑爆硬盘。`, fix: 'disk',
+ });
+ }
+ const rtDir = runtime.provisioner.paths().root;
+ if (!doctor.isAsciiPath(rtDir)) {
+ issues.push({
+ code: 'pathRuntime', severity: 'warn', title: '运行时目录含中文/特殊字符',
+ hint: '部分运行时组件对中文路径敏感,可能引发启动失败。建议改到纯英文目录。', fix: 'path',
+ });
+ }
+ const env = await runtime.provisioner.checkEnv().catch(() => ({}));
+ if (!env.adb || !env.adb.ok) {
+ issues.push({ code: 'adb', severity: 'error', title: 'adb 工具链缺失', hint: '无法连接安卓运行时。', fix: 'deploy' });
+ }
+ if (!env.emulator || !env.emulator.ok) {
+ issues.push({ code: 'emulator', severity: 'error', title: '运行时引擎未安装', hint: '需要先部署运行时引擎(约 440MB)。', fix: 'deploy' });
+ }
+ if (!env.sysimg || !env.sysimg.ok) {
+ issues.push({ code: 'sysimg', severity: 'warn', title: '系统镜像未就绪', hint: '需要先下载 Android 系统镜像(约 1.5GB)。', fix: 'deploy' });
+ }
+ // 残留锁文件:会让下一次启动被判定为「AVD 已被占用」而 FATAL
+ const avdHome = runtime.provisioner.paths().avdHome;
+ let locked = false;
+ try { for (const f of fs.readdirSync(avdHome)) { if (/\.lock$/i.test(f)) { locked = true; break; } } } catch (_) { /* ignore */ }
+ if (locked) {
+ issues.push({ code: 'lock', severity: 'warn', title: '检测到上次残留的锁文件', hint: '可能导致下一次启动被判定为「AVD 已被占用」。', fix: 'lock' });
+ }
+ } catch (_) { /* 自检失败不阻断使用 */ }
+ return { issues, accel, free };
+ });
+
// 微软 VC++ 2015-2022 x64 运行库:安卓模拟器(Qt6)与 qemu 都依赖它。
// 缺了在「其他电脑」上会直接起不来(0xc0000135 / MSVCP140 缺失)。
function vcRedistInstaller() {
@@ -839,6 +952,56 @@ function registerIpc() {
}
});
+ /**
+ * 自动开启虚拟化:用户无需手动去「Windows 功能」面板。
+ * 优先启用系统自带的「虚拟机平台」(WHPX)功能;若该 DLL 都不存在(老系统),
+ * 退而安装并启用 Google 的 AEHD 驱动。两种方式都需要管理员提权。
+ */
+ ipcMain.handle('provision:enableVirtualization', async () => {
+ try {
+ const accel = await runtime.provisioner.emulatorAccel();
+ if (accel.ok) return { ok: true, already: true, accel, note: '硬件加速已可用,无需额外操作' };
+
+ const hv = await runtime.provisioner.hypervisor();
+ if (hv.dll) {
+ // 系统带 WinHvPlatform.dll:开启「虚拟机平台」功能(可能需要重启)
+ const r = await enableWindowsFeature('VirtualMachinePlatform');
+ const r2 = await enableWindowsFeature('HypervisorPlatform').catch(() => ({ ok: false }));
+ const ok = r.ok || r2.ok;
+ const after = await runtime.provisioner.emulatorAccel();
+ return {
+ ok,
+ restartNeeded: r.restart || r2.restart,
+ accel: after,
+ note: ok
+ ? (r.restart ? '已开启「虚拟机平台」,请重启电脑后获得最佳性能' : '「虚拟机平台」已开启,硬件加速即时生效')
+ : (r.error || r2.error || '无法开启系统虚拟化功能'),
+ };
+ }
+
+ // 没有 WHPX 组件:改用 AEHD 驱动(Google 自家,装完即用)
+ const ae = await runtime.provisioner.installAehd(
+ (x) => send('provision:progress', { ...x, component: 'aehd' }),
+ ).catch((e) => ({ ok: false, error: e.message }));
+ if (!ae.ok) return { ok: false, error: ae.error || 'AEHD 驱动包准备失败' };
+ const bat = path.join(runtime.provisioner.paths().aehdDir, 'silent_install.bat');
+ await new Promise((resolve, reject) => {
+ const { spawn: sp } = require('child_process');
+ const esc = bat.replace(/'/g, "''");
+ const ps = `try { $p = Start-Process -FilePath '${esc}' -WorkingDirectory '${path.dirname(bat).replace(/'/g, "''")}' -Verb RunAs -Wait -PassThru; exit $p.ExitCode } catch { exit 2 }`;
+ const proc = sp('powershell', ['-NoProfile', '-NonInteractive', '-Command', ps], { windowsHide: true });
+ proc.on('exit', (code) => (code === 0 ? resolve() : reject(new Error(
+ code === 2 ? '已取消管理员授权(需要点「是」才能安装驱动)' : `驱动安装失败(退出码 ${code})`,
+ ))));
+ proc.on('error', (e) => reject(e));
+ });
+ const after = await runtime.provisioner.emulatorAccel();
+ return { ok: after.ok, accel: after, note: after.ok ? 'AEHD 硬件加速已启用' : after.note };
+ } catch (e) {
+ return { ok: false, error: e.message };
+ }
+ });
+
ipcMain.handle('provision:installAdb', async () => {
try {
const r = await runtime.provisioner.installAdb((p) => send('provision:progress', { ...p, component: 'adb' }));
@@ -964,6 +1127,48 @@ function registerIpc() {
shell.openPath(dir);
});
+ /** 清理上次残留的 AVD 锁文件:会让下次启动被误判为「AVD 已被占用」而 FATAL */
+ ipcMain.handle('app:clearLocks', async () => {
+ try {
+ const avdHome = runtime.provisioner.paths().avdHome;
+ let removed = 0;
+ for (const f of fs.readdirSync(avdHome)) {
+ if (/\.lock$/i.test(f)) {
+ try { fs.rmSync(path.join(avdHome, f), { force: true }); removed++; } catch (_) { /* ignore */ }
+ }
+ }
+ return { ok: true, removed };
+ } catch (e) {
+ return { ok: false, error: e.message };
+ }
+ });
+
+ /**
+ * 一键卸载 ApkStart 本体:
+ * 1) 先取消 .apk 文件关联(避免卸载后双击 APK 指向已删除的程序)
+ * 2) 安装版:启动 NSIS 卸载程序(它会自行请求管理员/确认),随后退出本程序
+ * 3) 便携版(旁加载 / 免安装):没有 uninstaller.exe,返回提示让用户手动删除程序与数据目录
+ */
+ ipcMain.handle('app:removeSelf', async () => {
+ try {
+ try { await assoc.unregisterAssociation(); } catch (_) { /* 取消关联失败不影响卸载 */ }
+ const exeDir = path.dirname(process.execPath);
+ const uninstaller = path.join(exeDir, 'uninstaller.exe');
+ if (!fs.existsSync(uninstaller)) {
+ return { ok: true, portable: true, dataDir: store.DATA_DIR, exeDir };
+ }
+ const { spawn } = require('child_process');
+ // 先让本程序退出,再由一个独立进程延迟 2 秒拉起卸载器:
+ // 运行中的 exe 会锁住安装目录里的文件,直接拉起卸载器容易删不干净。
+ const cmd = `ping 127.0.0.1 -n 3 >nul & start "" "${uninstaller}"`;
+ spawn('cmd.exe', ['/c', cmd], { detached: true, stdio: 'ignore', windowsHide: true }).unref();
+ setTimeout(() => app.quit(), 300);
+ return { ok: true, portable: false };
+ } catch (e) {
+ return { ok: false, error: e.message };
+ }
+ });
+
ipcMain.handle('shell:open', (_e, url) => shell.openExternal(url));
ipcMain.handle('window:minimize', () => mainWindow?.minimize());
diff --git a/src/preload.js b/src/preload.js
index b68c5a5..db5e421 100644
--- a/src/preload.js
+++ b/src/preload.js
@@ -53,11 +53,17 @@ contextBridge.exposeInMainWorld('apkstart', {
installPlayImage: () => invoke('provision:installPlayImage'),
installAehd: () => invoke('provision:installAehd'),
enableAccel: () => invoke('provision:enableAccel'),
+ enableVirtualization: () => invoke('provision:enableVirtualization'),
downloadIso: () => invoke('provision:downloadIso'),
createDisk: (gb) => invoke('provision:createDisk', gb),
importIso: () => invoke('provision:importIso'),
importDisk: () => invoke('provision:importDisk'),
+ selfCheck: () => invoke('doctor:selfCheck'),
+ clearLocks: () => invoke('app:clearLocks'),
+ removeSelf: () => invoke('app:removeSelf'),
+ setSharedDir: (dir) => invoke('settings:setSharedDir', dir),
+
assocStatus: () => invoke('assoc:status'),
assocRegister: () => invoke('assoc:register'),
assocUnregister: () => invoke('assoc:unregister'),
diff --git a/src/ui/app.js b/src/ui/app.js
index 66a476e..aaa0697 100644
--- a/src/ui/app.js
+++ b/src/ui/app.js
@@ -347,6 +347,7 @@ async function deployAll() {
} finally {
setStepBusy('all', false);
await refreshStatus();
+ selfCheck();
}
}
@@ -725,7 +726,6 @@ function bindSettings() {
$('setAutoShortcut').addEventListener('change', (e) => save({ createShortcutOnInstall: e.target.checked }));
$('setStartMenuShortcut').addEventListener('change', (e) => save({ createStartMenuShortcut: e.target.checked }));
$('setShortcutDir').addEventListener('change', (e) => save({ shortcutDir: e.target.value.trim() }));
- $('setSharedDir').addEventListener('change', (e) => save({ sharedDir: e.target.value.trim() }));
$('setDeviceSharedDir').addEventListener('change', (e) => save({ deviceSharedDir: e.target.value.trim() }));
$('setAutoStart').addEventListener('change', (e) => save({ autoStart: e.target.checked }));
$('setDisplayMode').addEventListener('change', async (e) => {
@@ -783,6 +783,67 @@ function bindSettings() {
$('btnOpenShared').addEventListener('click', () => api.openSharedDir());
+ // 重建快捷方式:桌面图标被误删 / 被安全软件拦掉时的兜底入口
+ $('btnRebuildShortcuts').addEventListener('click', async () => {
+ const btn = $('btnRebuildShortcuts');
+ btn.disabled = true;
+ try {
+ const r = await api.rebuildShortcuts().catch(() => ({ ok: false }));
+ const fixed = (r && r.fixed) || [];
+ toast(fixed.length
+ ? { title: '快捷方式已重建', body: fixed.join('、'), type: 'ok' }
+ : { title: '快捷方式都在', body: '没有需要重建的入口', type: 'info' });
+ } finally {
+ btn.disabled = false;
+ }
+ });
+
+ // 共享目录:先浏览选目录,再「保存并迁移」把旧文件一次性搬到新目录
+ $('btnBrowseShared').addEventListener('click', async () => {
+ const picked = await api.openDir();
+ if (!picked) return;
+ $('setSharedDir').value = picked;
+ toast({ title: '已选新目录', body: '点「保存并迁移」把旧文件搬过去', type: 'info' });
+ });
+ $('btnSaveShared').addEventListener('click', async () => {
+ const dir = $('setSharedDir').value.trim();
+ if (!dir) { toast({ title: '请先填写或浏览目录', type: 'error' }); return; }
+ const btn = $('btnSaveShared');
+ btn.disabled = true;
+ const r = await api.setSharedDir(dir).catch(() => ({ ok: false }));
+ btn.disabled = false;
+ if (r.ok) {
+ const moved = r.oldDir && r.oldDir !== r.newDir;
+ toast({ title: '共享目录已更新', body: moved ? '旧目录里已有的文件已迁移到新目录' : '已保存', type: 'ok' });
+ } else {
+ toast({ title: '保存失败', body: r.error, type: 'error' });
+ }
+ });
+
+ // 一键卸载 ApkStart 本体(取消 .apk 关联 + 启动卸载程序;便携版手动删除)
+ $('btnUninstall').addEventListener('click', async () => {
+ const ok = window.confirm('确定卸载 ApkStart?\n\n将取消 .apk 文件关联并移除程序。此操作不可撤销。');
+ if (!ok) return;
+ const btn = $('btnUninstall');
+ btn.disabled = true;
+ const r = await api.removeSelf().catch(() => ({ ok: false }));
+ if (r.ok && r.portable) {
+ btn.disabled = false;
+ toast({
+ title: '便携版无法自动卸载',
+ body: `请手动删除程序目录(${r.exeDir})与数据目录(${r.dataDir})`,
+ type: 'info', sticky: true,
+ });
+ return;
+ }
+ if (!r.ok) {
+ btn.disabled = false;
+ toast({ title: '卸载失败', body: r.error, type: 'error' });
+ return;
+ }
+ toast({ title: '正在卸载…', body: '卸载程序已启动,ApkStart 即将退出', type: 'ok', sticky: true });
+ });
+
// ARM 兼容镜像下载(带进度 toast)
$('btnInstallPlay').addEventListener('click', async () => {
const btn = $('btnInstallPlay');
@@ -1069,8 +1130,10 @@ async function init() {
await refreshApps();
refreshAndroid();
checkVcRedist();
+ selfCheck();
setInterval(refreshStatus, 6000);
setInterval(refreshApps, 15000);
+ setInterval(selfCheck, 60000);
}
// VC++ 运行库检测:缺失时显示横幅,提供一键提权安装
@@ -1086,6 +1149,138 @@ async function checkVcRedist() {
} catch (_) { /* 检测失败不阻断主流程 */ }
}
+/* ---------------- 环境自检 ---------------- */
+
+let envBusy = false;
+
+/** 拉取 doctor:selfCheck 并渲染横幅;VC++ 由独立横幅负责,这里不再重复列出 */
+async function selfCheck() {
+ if (envBusy) return;
+ envBusy = true;
+ try {
+ const r = await api.selfCheck().catch(() => null);
+ if (r) renderEnvCheck(r);
+ } catch (_) { /* 自检失败不阻断主流程 */ }
+ finally { envBusy = false; }
+}
+
+function renderEnvCheck(r) {
+ const box = $('envCheck');
+ if (!box) return;
+ // 首次部署向导本身已在补齐组件,此时不再重复列出「组件缺失」类问题
+ const setupVisible = !$('setupView').hidden;
+ const issues = (r.issues || []).filter((i) =>
+ i.code !== 'vcRedist' && !(setupVisible && i.fix === 'deploy'));
+ if (!issues.length) {
+ if (setupVisible) { box.hidden = true; return; }
+ box.hidden = false;
+ box.innerHTML = `
+ <div class="env-check-ok">
+ <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2"><path d="M20 6 9 17l-5-5"/></svg>
+ <span>环境自检通过,没有发现会影响运行的问题。</span>
+ <span style="flex:1"></span>
+ <button class="btn ghost sm" id="btnEnvRecheck">重新检查</button>
+ </div>`;
+ const re = $('btnEnvRecheck');
+ if (re) re.addEventListener('click', selfCheck);
+ return;
+ }
+ const errs = issues.filter((i) => i.severity === 'error').length;
+ const warns = issues.length - errs;
+ box.hidden = false;
+ box.innerHTML = `
+ <div class="env-check-head">
+ <span class="ec-title">环境自检</span>
+ ${errs ? `<span class="ec-count">${errs} 个严重</span>` : ''}
+ ${warns ? `<span class="ec-count warn">${warns} 个提示</span>` : ''}
+ <span class="ec-spacer"></span>
+ <button class="btn ghost sm" id="btnEnvRecheck">重新检查</button>
+ <button class="btn primary sm" id="btnEnvFixAll">一键修复全部</button>
+ </div>
+ <div class="env-check-list">
+ ${issues.map((i) => `
+ <div class="env-check-item ${i.severity}">
+ <span class="ec-sev"></span>
+ <div class="ec-body">
+ <div class="ec-name">${esc(i.title)}</div>
+ <div class="ec-hint">${esc(i.hint || '')}</div>
+ </div>
+ ${i.fix ? `<button class="ec-fix" data-code="${esc(i.code)}">修复</button>` : ''}
+ </div>`).join('')}
+ </div>`;
+ const re = $('btnEnvRecheck');
+ if (re) re.addEventListener('click', selfCheck);
+ const fixAll = $('btnEnvFixAll');
+ if (fixAll) fixAll.addEventListener('click', () => fixAllIssues(issues));
+ box.querySelectorAll('.ec-fix').forEach((b) => {
+ b.addEventListener('click', () => {
+ const issue = issues.find((x) => x.code === b.dataset.code);
+ if (issue) fixIssue(issue);
+ });
+ });
+}
+
+async function fixIssue(issue) {
+ switch (issue.fix) {
+ case 'vcRedist': {
+ const r = await api.installVcRedist().catch(() => ({ ok: false }));
+ toast(r.ok
+ ? { title: 'VC++ 运行库已安装', type: 'ok' }
+ : { title: '安装未完成', body: r.error || (r.reason === 'no-installer' ? '安装包缺失,请重新部署后再试' : '请重试'), type: 'error' });
+ break;
+ }
+ case 'virtualization': {
+ const t = toast({ title: '正在开启硬件加速…', body: '请在弹出的窗口点「是」', sticky: true, spinner: true });
+ const r = await api.enableVirtualization().catch(() => ({ ok: false }));
+ if (r.ok) {
+ t.update({ title: '硬件加速已启用', body: r.restartNeeded ? '请重启电脑以获得最佳性能' : (r.note || ''), type: 'ok' });
+ setTimeout(t.dismiss, 3200);
+ } else {
+ t.update({ title: '未能开启', body: r.error || '请重试', type: 'error', sticky: true });
+ }
+ break;
+ }
+ case 'disk': {
+ // 主进程会弹出原生确认框(含可释放空间预览),这里不再重复 confirm
+ const r = await api.runtimeCleanup({ apply: true }).catch(() => null);
+ if (!r) { toast({ title: '清理失败', body: '请重试', type: 'error' }); break; }
+ if (r.cancelled) break;
+ toast({ title: '清理完成', body: `释放约 ${((r.saved || 0) / 1048576).toFixed(0)} MB`, type: 'ok' });
+ break;
+ }
+ case 'path': {
+ toast({ title: '建议改到纯英文目录', body: '在 设置 → 系统集成 里修改「运行时数据目录」,再重启软件。', type: 'info', sticky: true });
+ openSettings();
+ break;
+ }
+ case 'deploy': {
+ toast({ title: '正在补齐缺失的运行时组件…', type: 'info', sticky: true, spinner: true });
+ await deployAll();
+ break;
+ }
+ case 'lock': {
+ const r = await api.clearLocks().catch(() => ({ ok: false }));
+ toast(r.ok ? { title: '已清理残留锁文件', type: 'ok' } : { title: '清理失败', body: r.error, type: 'error' });
+ break;
+ }
+ default:
+ toast({ title: '暂不支持自动修复', body: issue.hint || '', type: 'info' });
+ }
+ // 修复后重新自检,刷新横幅与状态
+ setTimeout(selfCheck, 600);
+ setTimeout(refreshStatus, 600);
+}
+
+async function fixAllIssues(issues) {
+ const fixable = issues.filter((i) => i.fix);
+ for (const i of fixable) {
+ // eslint-disable-next-line no-await-in-loop
+ await fixIssue(i);
+ // eslint-disable-next-line no-await-in-loop
+ await new Promise((res) => setTimeout(res, 500));
+ }
+}
+
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.html
index df54ba1..fd1c620 100644
--- a/src/ui/index.html
+++ b/src/ui/index.html
@@ -40,6 +40,9 @@
</div>
</section>
+ <!-- 环境自检横幅:自动检测常见问题并给出一键修复 -->
+ <div id="envCheck" class="env-check" hidden></div>
+
<section class="content" id="content">
<div class="grid" id="grid"></div>
<div class="empty" id="empty">
@@ -419,6 +422,10 @@
<label>快捷方式目录</label>
<input id="setShortcutDir" type="text" placeholder="留空 = 桌面" />
</div>
+ <div class="runtime-actions">
+ <button class="btn ghost sm" id="btnRebuildShortcuts">重建快捷方式</button>
+ <span class="inline-note">桌面图标被误删或被安全软件拦掉时,点这里按当前设置全部补齐。</span>
+ </div>
</div>
<div class="group">
@@ -427,8 +434,11 @@
<label>本机共享目录</label>
<div class="row">
<input id="setSharedDir" type="text" />
+ <button class="btn ghost sm" id="btnBrowseShared">浏览</button>
<button class="btn ghost sm" id="btnOpenShared">打开</button>
+ <button class="btn primary sm" id="btnSaveShared">保存并迁移</button>
</div>
+ <span class="sub">修改后旧目录里已有的文件会自动搬到新目录;正在运行的文件互通不受影响。</span>
</div>
<div class="field">
<label>安卓内对应目录</label>
@@ -455,6 +465,13 @@
</div>
<span class="sub">这里占用空间最大(数 GB)。改到非系统盘可大幅减轻 C 盘压力;修改后需重启软件,已存在的数据不会自动搬移(请手动复制后删除旧目录)。</span>
</div>
+ <div class="field">
+ <label>卸载 ApkStart</label>
+ <div class="row">
+ <button class="btn ghost sm" id="btnUninstall">一键卸载</button>
+ <span class="inline-note">卸载会取消 .apk 关联并移除程序;便携版请按提示手动删除目录。</span>
+ </div>
+ </div>
</div>
<div class="group" id="aboutGroup">
<div class="group-title">关于</div>
diff --git a/src/ui/style.css b/src/ui/style.css
index 316064e..f2953d0 100644
--- a/src/ui/style.css
+++ b/src/ui/style.css
@@ -472,6 +472,57 @@ body {
.runtime-actions { display: flex; align-items: center; gap: 8px; margin: 2px 0 10px; }
.inline-note { font-size: 11.5px; color: var(--faint); }
+/* ---------------- 环境自检横幅 ---------------- */
+
+.env-check {
+ flex: 0 0 auto;
+ margin: 0 0 12px;
+ border: 1px solid var(--line-strong);
+ border-radius: var(--r-md);
+ background: var(--panel);
+ box-shadow: var(--shadow-sm);
+ overflow: hidden;
+}
+.env-check-head {
+ display: flex; align-items: center; gap: 10px;
+ padding: 10px 14px;
+ border-bottom: 1px solid var(--line);
+ background: var(--panel-2);
+}
+.env-check-head .ec-title { font-weight: 600; }
+.env-check-head .ec-count {
+ font-size: 11.5px; color: #fff; background: var(--danger);
+ border-radius: 999px; padding: 1px 8px;
+}
+.env-check-head .ec-count.warn { background: #d97706; }
+.env-check-head .ec-spacer { flex: 1; }
+.env-check-head button { height: 28px; padding: 0 12px; font-size: 12px; border-radius: 8px; }
+.env-check-list { padding: 6px 8px; display: flex; flex-direction: column; gap: 6px; }
+.env-check-item {
+ display: flex; align-items: flex-start; gap: 10px;
+ padding: 8px 10px; border-radius: 10px; background: var(--panel-2);
+ border: 1px solid var(--line);
+}
+.env-check-item .ec-sev {
+ flex: 0 0 auto; width: 6px; align-self: stretch; border-radius: 4px; background: var(--faint);
+}
+.env-check-item.error .ec-sev { background: var(--danger); }
+.env-check-item.warn .ec-sev { background: #d97706; }
+.env-check-item .ec-body { flex: 1; min-width: 0; }
+.env-check-item .ec-name { font-weight: 600; font-size: 12.5px; }
+.env-check-item .ec-hint { font-size: 11.5px; color: var(--muted); margin-top: 2px; line-height: 1.5; }
+.env-check-item .ec-fix {
+ flex: 0 0 auto; align-self: center;
+ height: 28px; padding: 0 12px; font-size: 12px; border-radius: 8px;
+ border: 1px solid var(--brand); color: var(--brand); background: var(--brand-soft);
+}
+.env-check-item .ec-fix:hover { background: var(--brand); color: #fff; }
+.env-check-ok {
+ display: flex; align-items: center; gap: 8px;
+ padding: 12px 14px; color: var(--brand-dark); font-size: 12.5px;
+}
+
+
.modal-foot {
flex: 0 0 auto;
display: flex; align-items: center;