@cloud411716/fancy-webnovel 0.1.97 → 0.1.99

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.97",
3
+ "version": "0.1.99",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "exports": {
@@ -162,17 +162,28 @@ 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
+ }).then(() => {
173
+ notify(session, '✅ 密码已收到,正在安装...\n');
174
+ });
175
+
165
176
  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'
177
+ 'sudo -S npm install -g playwright@1.40.0 --registry=https://registry.npmmirror.com && ' +
178
+ 'sudo -S PLAYWRIGHT_DOWNLOAD_HOST=https://npmmirror.com/mirrors/playwright/ playwright install chromium --with-deps'
167
179
  ], {
168
180
  stdio: ['pipe', 'pipe', 'pipe'],
169
181
  cwd: process.cwd(),
170
- setsid: true, // 创建新 session,无 controlling TTY,sudo 密码不会跑到输入框
171
182
  });
172
- const installOut = [];
183
+ const installOut = [], installErr = [];
173
184
 
174
185
  installProc.stdout.on('data', d => { installOut.push(d.toString()); });
175
- // stderr 不进 installOut(sudo 提示等交互信息不要混入最终报告)
186
+ installProc.stderr.on('data', d => { installErr.push(d.toString()); });
176
187
 
177
188
  // 注册 CTRL+C 取消处理:kill 安装进程
178
189
  const stopCancel = onUserCancel(session, () => {
@@ -180,33 +191,19 @@ async function runScanWithChromiumFix(ctx, session, invocation, { platform, leng
180
191
  installStop();
181
192
  });
182
193
 
183
- let sudoDialogPromise = null;
184
- // sudo 密码提示走 stdout,不是 stderr
185
- installProc.stdout.on('data', async (d) => {
186
- if (sudoDialogPromise) return;
187
- const text = d.toString();
188
- if (/password|密码|sudo/i.test(text)) {
189
- sudoDialogPromise = ctx.userQuestions.ask({
190
- questions: [{
191
- question: '🔐 安装过程需要 sudo 权限,请输入密码:',
192
- hideCustomInput: false,
193
- }],
194
- }).then(async (pwdResult) => {
195
- const pwd = pwdResult.answers[0]?.custom ?? '';
196
- installProc.stdin?.write(pwd + '\n');
197
- }).catch(() => {});
198
- }
199
- });
194
+ // 预先弹出的密码框结果 写入子进程 stdin
195
+ pwdAskPromise.then(async (pwdResult) => {
196
+ const pwd = pwdResult.answers[0]?.custom ?? '';
197
+ if (pwd) installProc.stdin?.write(pwd + '\n');
198
+ }).catch(() => {});
200
199
 
201
200
  return new Promise((resolve) => {
202
201
  installProc.on('close', async (code) => {
203
- // 如果弹过 sudo 框,等弹框结果(最多等 3 分钟,防止卡死)
204
- if (sudoDialogPromise) {
205
- await Promise.race([
206
- sudoDialogPromise.catch(() => {}),
207
- new Promise(r => setTimeout(r, 180000)),
208
- ]);
209
- }
202
+ // 等预弹框完成
203
+ await Promise.race([
204
+ pwdAskPromise.catch(() => {}),
205
+ new Promise(r => setTimeout(r, 180000)),
206
+ ]);
210
207
  stopCancel(); // 移除取消监听
211
208
  installStop();
212
209
  if (code === 0) {
@@ -222,7 +219,8 @@ async function runScanWithChromiumFix(ctx, session, invocation, { platform, leng
222
219
  resolve('retry');
223
220
  } else {
224
221
  const out = installOut.join('').slice(-300);
225
- notify(session, `❌ Chromium 安装失败(exit ${code})。\n请手动运行以下命令后重试:\n 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\n\n安装日志末尾:\n${out}`);
222
+ const err = installErr.join('').slice(-300);
223
+ notify(session, `❌ Chromium 安装失败(exit ${code})。\n请手动运行以下命令后重试:\n 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\n\nstdout末尾:\n${out}\n\nstderr末尾:\n${err}`);
226
224
  resolve(undefined);
227
225
  }
228
226
  });