INNER CODE UNIT · TypeScript

captureIndexedScreenshot

SimonAKing/scrcpy-gui · src/main/main.ts:307

async function captureIndexedScreenshot(
  runtime: RuntimeConfig,
  serial: string,
  label?: string
): Promise<{ message: string; artifactId?: string }> {
  const safeSerial = serial.replace(/[^a-zA-Z0-9._-]+/g, '-').slice(0, 80) || 'device'
  const safeLabel = label?.trim().replace(/[^\p{L}\p{N}._-]+/gu, '-').replace(/^-+|-+$/g, '').slice(0, 60)
  const timestamp = new Date().toISOString().replaceAll(':', '-').slice(0, 19)
  const directory = join(app.getPath('pictures'), 'Scrcpy GUI')
  await mkdir(directory, { recursive: true })
  const path = join(directory, `scrcpy-${safeSerial}-${safeLabel ? `${safeLabel}-` : ''}${timestamp}-${randomUUID().slice(0, 8)}.png`)
  const capture = await captureDeviceScreenshot(runtime, serial, path)
  if (!capture.ok) throw new Error(capture.error?.detail || capture.error?.message || 'Screenshot failed.')
  const artifact = artifactService ? await artifactService.register({ kind: 'screenshot', path, deviceId: serial }) : undefined
  if (artifact) eventStore.publish({
    level: 'info', domain: 'artifact', action: 'screenshot-indexed', deviceId: serial,
    stage: artifact.status, message: 'Screenshot added to the artifact library.',
    data: { artifactId: artifact.id, size: artifact.size }

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…