@cloud411716/fancy-webnovel 0.1.96 → 0.1.98

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloud411716/fancy-webnovel",
3
- "version": "0.1.96",
3
+ "version": "0.1.98",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "exports": {
@@ -162,8 +162,18 @@ async function runScanWithChromiumFix(ctx, session, invocation, { platform, leng
162
162
  notify(session, '⏳ 正在下载 Chromium 浏览器(首次约 2-3 分钟),请耐心等待...\n');
163
163
  const installStop = startActivity(session);
164
164
 
165
+ // 预先弹出密码框(不等 sudo 提示出现)
166
+ // 密码通过 stdin pipe 传入,用 sudo -S 确保 sudo 从 stdin 读
167
+ const pwdAskPromise = ctx.userQuestions.ask({
168
+ questions: [{
169
+ question: '🔐 安装 Chromium 需要 sudo 权限,请输入密码:',
170
+ hideCustomInput: false,
171
+ }],
172
+ });
173
+
165
174
  const installProc = spawn('sh', ['-c',
166
- 'npm install -g playwright@1.40.0 --registry=https://registry.npmmirror.com && PLAYWRIGHT_DOWNLOAD_HOST=https://npmmirror.com/mirrors/playwright/ playwright install chromium --with-deps'
175
+ 'sudo -S npm install -g playwright@1.40.0 --registry=https://registry.npmmirror.com && ' +
176
+ 'sudo -S PLAYWRIGHT_DOWNLOAD_HOST=https://npmmirror.com/mirrors/playwright/ playwright install chromium --with-deps'
167
177
  ], {
168
178
  stdio: ['pipe', 'pipe', 'pipe'],
169
179
  cwd: process.cwd(),
@@ -179,33 +189,19 @@ async function runScanWithChromiumFix(ctx, session, invocation, { platform, leng
179
189
  installStop();
180
190
  });
181
191
 
182
- let sudoDialogPromise = null;
183
- // sudo 密码提示走 stdout,不是 stderr
184
- installProc.stdout.on('data', async (d) => {
185
- if (sudoDialogPromise) return;
186
- const text = d.toString();
187
- if (/password|密码|sudo/i.test(text)) {
188
- sudoDialogPromise = ctx.userQuestions.ask({
189
- questions: [{
190
- question: '🔐 安装过程需要 sudo 权限,请输入密码:',
191
- hideCustomInput: false,
192
- }],
193
- }).then(async (pwdResult) => {
194
- const pwd = pwdResult.answers[0]?.custom ?? '';
195
- installProc.stdin?.write(pwd + '\n');
196
- }).catch(() => {});
197
- }
198
- });
192
+ // 预先弹出的密码框结果 写入子进程 stdin
193
+ pwdAskPromise.then(async (pwdResult) => {
194
+ const pwd = pwdResult.answers[0]?.custom ?? '';
195
+ if (pwd) installProc.stdin?.write(pwd + '\n');
196
+ }).catch(() => {});
199
197
 
200
198
  return new Promise((resolve) => {
201
199
  installProc.on('close', async (code) => {
202
- // 如果弹过 sudo 框,等弹框结果(最多等 3 分钟,防止卡死)
203
- if (sudoDialogPromise) {
204
- await Promise.race([
205
- sudoDialogPromise.catch(() => {}),
206
- new Promise(r => setTimeout(r, 180000)),
207
- ]);
208
- }
200
+ // 等预弹框完成
201
+ await Promise.race([
202
+ pwdAskPromise.catch(() => {}),
203
+ new Promise(r => setTimeout(r, 180000)),
204
+ ]);
209
205
  stopCancel(); // 移除取消监听
210
206
  installStop();
211
207
  if (code === 0) {