@cloud411716/fancy-webnovel 0.1.97 → 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.97",
3
+ "version": "0.1.98",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "exports": {
@@ -162,12 +162,21 @@ 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(),
170
- setsid: true, // 创建新 session,无 controlling TTY,sudo 密码不会跑到输入框
171
180
  });
172
181
  const installOut = [];
173
182
 
@@ -180,33 +189,19 @@ async function runScanWithChromiumFix(ctx, session, invocation, { platform, leng
180
189
  installStop();
181
190
  });
182
191
 
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
- });
192
+ // 预先弹出的密码框结果 写入子进程 stdin
193
+ pwdAskPromise.then(async (pwdResult) => {
194
+ const pwd = pwdResult.answers[0]?.custom ?? '';
195
+ if (pwd) installProc.stdin?.write(pwd + '\n');
196
+ }).catch(() => {});
200
197
 
201
198
  return new Promise((resolve) => {
202
199
  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
- }
200
+ // 等预弹框完成
201
+ await Promise.race([
202
+ pwdAskPromise.catch(() => {}),
203
+ new Promise(r => setTimeout(r, 180000)),
204
+ ]);
210
205
  stopCancel(); // 移除取消监听
211
206
  installStop();
212
207
  if (code === 0) {