device-shots 0.5.5 → 0.5.7

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 +45 -29
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -31,6 +31,7 @@ var DEFAULTS = {
31
31
  output: "./.screenshots",
32
32
  platform: "both",
33
33
  time: "9:41",
34
+ androidTime: "9:30",
34
35
  frame: true
35
36
  };
36
37
  async function loadConfig() {
@@ -51,6 +52,7 @@ function createDefaultConfig(bundleId) {
51
52
  output: "./.screenshots",
52
53
  platform: "both",
53
54
  time: "9:41",
55
+ androidTime: "9:30",
54
56
  frame: true
55
57
  },
56
58
  null,
@@ -332,36 +334,49 @@ async function discoverAndroidDevices(bundleId) {
332
334
  }
333
335
  return devices;
334
336
  }
335
- async function setAndroidDemoMode(serial, time) {
337
+ async function adbShell(serial, cmd) {
336
338
  const adb = getAdbPath();
339
+ const { stdout, stderr } = await run(adb, ["-s", serial, "shell", cmd]);
340
+ return stdout || stderr;
341
+ }
342
+ function sleep(ms) {
343
+ return new Promise((resolve) => setTimeout(resolve, ms));
344
+ }
345
+ async function setAndroidDemoMode(serial, time = "9:30") {
337
346
  const hhmm = time.replace(":", "");
338
- const commands = [
339
- ["settings", "put", "global", "sysui_demo_allowed", "1"],
340
- ["am", "broadcast", "-a", "com.android.systemui.demo", "-e", "command", "enter"],
341
- ["am", "broadcast", "-a", "com.android.systemui.demo", "-e", "command", "clock", "-e", "hhmm", hhmm],
342
- ["am", "broadcast", "-a", "com.android.systemui.demo", "-e", "command", "wifi", "-e", "fully", "true", "-e", "wifi", "show"],
343
- ["am", "broadcast", "-a", "com.android.systemui.demo", "-e", "command", "network", "-e", "mobile", "show", "-e", "fully", "true", "-e", "level", "4"],
344
- ["am", "broadcast", "-a", "com.android.systemui.demo", "-e", "command", "battery", "-e", "level", "100", "-e", "plugged", "false"],
345
- ["am", "broadcast", "-a", "com.android.systemui.demo", "-e", "command", "notifications", "-e", "visible", "false"]
346
- ];
347
- for (const cmd of commands) {
348
- await run(adb, ["-s", serial, "shell", ...cmd]);
349
- }
347
+ await adbShell(serial, "settings put global sysui_demo_allowed 1");
348
+ await adbShell(
349
+ serial,
350
+ "am broadcast -a com.android.systemui.demo -e command enter"
351
+ );
352
+ await sleep(500);
353
+ await adbShell(
354
+ serial,
355
+ `am broadcast -a com.android.systemui.demo -e command clock -e hhmm ${hhmm}`
356
+ );
357
+ await adbShell(
358
+ serial,
359
+ "am broadcast -a com.android.systemui.demo -e command network -e wifi show -e level 4"
360
+ );
361
+ await adbShell(
362
+ serial,
363
+ "am broadcast -a com.android.systemui.demo -e command network -e mobile show -e datatype none -e level 4"
364
+ );
365
+ await adbShell(
366
+ serial,
367
+ "am broadcast -a com.android.systemui.demo -e command battery -e level 100 -e plugged false"
368
+ );
369
+ await adbShell(
370
+ serial,
371
+ "am broadcast -a com.android.systemui.demo -e command notifications -e visible false"
372
+ );
373
+ await sleep(500);
350
374
  }
351
375
  async function clearAndroidDemoMode(serial) {
352
- const adb = getAdbPath();
353
- await run(adb, [
354
- "-s",
376
+ await adbShell(
355
377
  serial,
356
- "shell",
357
- "am",
358
- "broadcast",
359
- "-a",
360
- "com.android.systemui.demo",
361
- "-e",
362
- "command",
363
- "exit"
364
- ]);
378
+ "am broadcast -a com.android.systemui.demo -e command exit"
379
+ );
365
380
  }
366
381
  async function captureAndroidScreenshot(serial, outputPath) {
367
382
  const adb = getAdbPath();
@@ -597,7 +612,8 @@ async function captureCommand(options) {
597
612
  const bundleIdDisplay = Array.isArray(bundleId) ? bundleId.join(", ") : bundleId;
598
613
  const outputDir = options.output || config.output;
599
614
  const platform = options.platform || config.platform;
600
- const time = options.time || config.time;
615
+ const iosTime = options.time || config.time;
616
+ const androidTime = config.androidTime;
601
617
  const shouldFrame = !options.noFrame && config.frame;
602
618
  const spinner = ora("Discovering devices...").start();
603
619
  const devices = await discoverDevices(bundleId, platform);
@@ -671,13 +687,13 @@ Detected ${devices.length} device(s) with ${bundleIdDisplay}:`)
671
687
  const androidDevices = devices.filter((d) => d.platform === "android");
672
688
  if (iosDevices.length > 0) {
673
689
  const s = ora("Setting clean iOS status bar...").start();
674
- await setIosStatusBar(time);
690
+ await setIosStatusBar(iosTime);
675
691
  s.succeed("iOS status bar set");
676
692
  }
677
693
  if (androidDevices.length > 0) {
678
694
  const s = ora("Setting clean Android status bar...").start();
679
695
  for (const device of androidDevices) {
680
- await setAndroidDemoMode(device.captureId, time);
696
+ await setAndroidDemoMode(device.captureId, androidTime);
681
697
  }
682
698
  s.succeed("Android demo mode set");
683
699
  }
@@ -844,7 +860,7 @@ async function frameCommand(dir, options) {
844
860
  var program = new Command();
845
861
  program.name("device-shots").description(
846
862
  "Capture and frame mobile app screenshots from iOS simulators and Android emulators"
847
- ).version("0.5.5");
863
+ ).version("0.5.7");
848
864
  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) => {
849
865
  await captureCommand({ name, ...opts });
850
866
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "device-shots",
3
- "version": "0.5.5",
3
+ "version": "0.5.7",
4
4
  "description": "Capture and frame mobile app screenshots from iOS simulators and Android emulators",
5
5
  "type": "module",
6
6
  "bin": {