Fix PWA install by registering service worker in theme

VitePress did not auto-inject SW registration; manual registerSW enables true app install on HTTPS.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-05 17:47:57 +08:00
parent f663867a25
commit c9f78ef25f
3 changed files with 31 additions and 1 deletions
+23
View File
@@ -367,6 +367,29 @@ ss -tlnp | grep 12100
- **对外访问必须使用 HTTPS**(云服务器反代层配置 SSL)
- 内网 `http://192.168.x.x:12100` 仅适合调试,Android 通常不会弹出「安装应用」
### 只能「创建快捷方式」,没有「安装应用」?
常见两个原因:
**1. 用了 HTTP 内网地址(如 `http://192.168.x.x:12100`**
| 访问方式 | 浏览器行为 |
|----------|------------|
| HTTP 内网 IP | 只能「创建快捷方式」,**不能**真正安装 PWA |
| **HTTPS 域名** | 可「安装应用 / 添加到主屏幕」 |
**2. Service Worker 未注册(已在最新代码修复)**
更新后按 F12 → **Application(应用)****Service Workers**,应看到 `/sw.js` 状态为 **activated**
若仍是红色报错,执行:
```bash
git pull && npm install && npm run build && npm run start
```
然后 **Ctrl+Shift+R** 强刷,或删除旧快捷方式后重装。
### 电脑(Chrome / Edge
1. 用 HTTPS 域名打开站点并登录