dsh-design-studio 0.22.0 → 0.23.1

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/lib/browser.js CHANGED
@@ -11,7 +11,7 @@ import os from 'node:os'
11
11
  import path from 'node:path'
12
12
  import { spawn, execFile } from 'node:child_process'
13
13
 
14
- const IDLE_MS = 90000 // 闲置多久关掉
14
+ const IDLE_MS = 30000 // 闲置多久关掉(#21:原来 90 秒,活动监视器里 Chrome Helper 挂太久;再开一次约 1 秒)
15
15
  const CALL_MS = 30000 // 一条指令最多等多久
16
16
  const CLOSE_MS = 600 // 让浏览器自己关,最多等多久再强杀
17
17
  const LOAD_MS = 15000 // 页面载入最多等多久(到点照样往下走:有个图一直载不完也能量)
@@ -54,7 +54,7 @@ const PREFIX = 'dsh-design-browser-'
54
54
  const STALE_MS = 3600 * 1000 // 一小时没动过的临时用户目录:上回没删掉的(DSH 被强退、插件进程直接退出)
55
55
  let swept = false
56
56
 
57
- /** 清掉以前留下的临时用户目录(每个进程只扫一次;正在用的浏览器闲置 90 秒就关,不会一小时不动) */
57
+ /** 清掉以前留下的临时用户目录(每个进程只扫一次;正在用的浏览器闲置 30 秒就关,不会一小时不动) */
58
58
  function sweep(dir = os.tmpdir(), now = Date.now()) {
59
59
  if (swept) return
60
60
  swept = true
@@ -210,9 +210,9 @@ export function createBrowser({ bin = findBrowser(), log = () => {}, idleMs = ID
210
210
  stop()
211
211
  }
212
212
 
213
- const touch = () => {
213
+ const touch = (ms = idleMs) => {
214
214
  clearTimeout(idle)
215
- if (!open) idle = setTimeout(() => { if (!open) stop() }, idleMs)
215
+ if (!open) idle = setTimeout(() => { if (!open) stop() }, ms)
216
216
  }
217
217
 
218
218
  /**
@@ -223,7 +223,7 @@ export function createBrowser({ bin = findBrowser(), log = () => {}, idleMs = ID
223
223
  * allow(网址):给了就只让它说行的页面载入(主页面、iframe,连跳转、脚本改地址都算),别的拦下,记在 page.blocked
224
224
  * offline:断网渲染(设计库的检查):所有请求(样式、图片、字体、接口 …)只放行和页面同源的,别的一律拦下,记在 page.blocked
225
225
  */
226
- async function withPage({ url, w, h, scale = 1, dark = false, allow = null, offline = false }, fn) {
226
+ async function withPage({ url, w, h, scale = 1, dark = false, allow = null, offline = false, linger = idleMs }, fn) {
227
227
  if (dead) throw new Error('browser closed')
228
228
  if (open >= MAX_PAGES) await new Promise((r) => queue.push(r))
229
229
  if (dead) throw new Error('browser closed')
@@ -317,7 +317,7 @@ export function createBrowser({ bin = findBrowser(), log = () => {}, idleMs = ID
317
317
  open--
318
318
  const next = queue.shift()
319
319
  if (next) next()
320
- touch()
320
+ touch(Math.min(linger, idleMs)) // 后台活(画布缩略图)可以要求早点关
321
321
  }
322
322
  }
323
323
 
package/lib/canvthumb.js CHANGED
@@ -172,7 +172,7 @@ export function createCanvasThumbs({ tracker, browser, trust = () => '', strictR
172
172
  const b = browser()
173
173
  if (!b || !b.available()) throw new Error('no browser')
174
174
  let title = ''
175
- const jpg = await b.withPage({ url: o.url, w: o.w, h: o.h, scale: Math.min(1, WIDTH / o.w), dark: o.dark, offline: strictRoot(o.root) }, async (page) => {
175
+ const jpg = await b.withPage({ url: o.url, w: o.w, h: o.h, scale: Math.min(1, WIDTH / o.w), dark: o.dark, offline: strictRoot(o.root), linger: 10000 }, async (page) => {
176
176
  const { info } = await prepare(page, o.dark)
177
177
  title = cut(String((info && info.title) || '').replace(/\s+/g, ' ').trim(), 80)
178
178
  return page.shot({ quality: 72 })