device-shots 0.5.10 → 0.5.12

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.
Files changed (2) hide show
  1. package/dist/index.js +30 -26
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -269,6 +269,7 @@ async function captureIosScreenshot(udid, outputPath) {
269
269
  }
270
270
 
271
271
  // src/devices/android.ts
272
+ import { execSync } from "child_process";
272
273
  function sanitizeName2(name) {
273
274
  return name.replace(/[ (),]/g, "_").replace(/[^A-Za-z0-9_-]/g, "");
274
275
  }
@@ -337,47 +338,50 @@ async function discoverAndroidDevices(bundleId) {
337
338
  function sleep(ms) {
338
339
  return new Promise((resolve) => setTimeout(resolve, ms));
339
340
  }
340
- async function demoBroadcast(serial, extras) {
341
- const adb = getAdbPath();
342
- const cmd = `am broadcast -a com.android.systemui.demo ${extras}`;
343
- const { stdout, stderr } = await run(adb, ["-s", serial, "shell", "sh", "-c", cmd]);
344
- return stdout || stderr;
341
+ function adbShellSync(adb, serial, cmd) {
342
+ try {
343
+ const result = execSync(`${adb} -s ${serial} shell ${cmd}`, {
344
+ encoding: "utf-8",
345
+ timeout: 1e4
346
+ });
347
+ return result.trim();
348
+ } catch (e) {
349
+ return e.stdout?.trim() || e.stderr?.trim() || "";
350
+ }
345
351
  }
346
352
  async function setAndroidDemoMode(serial, time = "9:30") {
347
353
  const hhmm = time.replace(":", "");
348
354
  const adb = getAdbPath();
349
- await run(adb, ["-s", serial, "shell", "settings", "put", "global", "sysui_demo_allowed", "1"]);
350
- await run(adb, ["-s", serial, "shell", "settings", "put", "global", "sysui_tuner_demo_on", "1"]);
355
+ const ACTION = "com.android.systemui.demo";
356
+ adbShellSync(adb, serial, "settings put global sysui_demo_allowed 1");
357
+ adbShellSync(adb, serial, "settings put global sysui_tuner_demo_on 1");
351
358
  await sleep(500);
352
- let result = await demoBroadcast(serial, "-e command enter");
353
- process.stderr.write(`[demo] enter: ${result.trim()}
359
+ let r = adbShellSync(adb, serial, `am broadcast -a ${ACTION} --es command enter`);
360
+ process.stderr.write(`[demo] enter: ${r}
354
361
  `);
355
362
  await sleep(1e3);
356
- result = await demoBroadcast(serial, `-e command clock -e hhmm ${hhmm}`);
357
- process.stderr.write(`[demo] clock: ${result.trim()}
363
+ r = adbShellSync(adb, serial, `am broadcast -a ${ACTION} --es command clock --es hhmm ${hhmm}`);
364
+ process.stderr.write(`[demo] clock: ${r}
358
365
  `);
359
- await sleep(300);
360
- result = await demoBroadcast(serial, "-e command network -e wifi show -e level 4");
361
- process.stderr.write(`[demo] wifi: ${result.trim()}
366
+ r = adbShellSync(adb, serial, `am broadcast -a ${ACTION} --es command network --es wifi show --es level 4`);
367
+ process.stderr.write(`[demo] wifi: ${r}
362
368
  `);
363
- await sleep(300);
364
- result = await demoBroadcast(serial, "-e command network -e mobile show -e datatype none -e level 4");
365
- process.stderr.write(`[demo] mobile: ${result.trim()}
369
+ r = adbShellSync(adb, serial, `am broadcast -a ${ACTION} --es command network --es mobile show --es datatype none --es level 4`);
370
+ process.stderr.write(`[demo] mobile: ${r}
366
371
  `);
367
- await sleep(300);
368
- result = await demoBroadcast(serial, "-e command battery -e level 100 -e plugged false");
369
- process.stderr.write(`[demo] battery: ${result.trim()}
372
+ r = adbShellSync(adb, serial, `am broadcast -a ${ACTION} --es command battery --es level 100 --es plugged false`);
373
+ process.stderr.write(`[demo] battery: ${r}
370
374
  `);
371
- await sleep(300);
372
- result = await demoBroadcast(serial, "-e command notifications -e visible false");
373
- process.stderr.write(`[demo] notif: ${result.trim()}
375
+ r = adbShellSync(adb, serial, `am broadcast -a ${ACTION} --es command notifications --es visible false`);
376
+ process.stderr.write(`[demo] notif: ${r}
374
377
  `);
375
378
  await sleep(1e3);
376
379
  }
377
380
  async function clearAndroidDemoMode(serial) {
378
- await demoBroadcast(serial, "-e command exit");
379
381
  const adb = getAdbPath();
380
- await run(adb, ["-s", serial, "shell", "settings", "put", "global", "sysui_tuner_demo_on", "0"]);
382
+ const ACTION = "com.android.systemui.demo";
383
+ adbShellSync(adb, serial, `am broadcast -a ${ACTION} --es command exit`);
384
+ adbShellSync(adb, serial, "settings put global sysui_tuner_demo_on 0");
381
385
  }
382
386
  async function captureAndroidScreenshot(serial, outputPath) {
383
387
  const adb = getAdbPath();
@@ -861,7 +865,7 @@ async function frameCommand(dir, options) {
861
865
  var program = new Command();
862
866
  program.name("device-shots").description(
863
867
  "Capture and frame mobile app screenshots from iOS simulators and Android emulators"
864
- ).version("0.5.10");
868
+ ).version("0.5.12");
865
869
  program.command("capture").description("Capture screenshots from running devices").argument("[name]", "Screenshot name").option("-b, --bundle-id <id>", "App bundle ID").option("-o, --output <dir>", "Output directory").option("-p, --platform <platform>", "ios, android, or both").option("--no-frame", "Skip framing after capture").option("--time <time>", "Status bar time", "9:41").action(async (name, opts) => {
866
870
  await captureCommand({ name, ...opts });
867
871
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "device-shots",
3
- "version": "0.5.10",
3
+ "version": "0.5.12",
4
4
  "description": "Capture and frame mobile app screenshots from iOS simulators and Android emulators",
5
5
  "type": "module",
6
6
  "bin": {