@@ -8,6 +8,9 @@ const { normalize } = require("path")
88const { recordVideo } = require ( "./src/recordVideo" )
99const { takeScreenshot } = require ( "./src/takeScreenshot" )
1010const open = require ( "open" )
11+ const { bgRed, bold } = require ( "kleur" )
12+ const { selectOption } = require ( "./src/selectOption" )
13+ const logUpdate = require ( "log-update" )
1114
1215const version = require ( join ( __dirname , "./package.json" ) ) . version
1316
@@ -33,20 +36,42 @@ const imageTypes = {
3336 png : true ,
3437}
3538
39+ /**
40+ * @param {any } message
41+ */
42+ function fail ( message ) {
43+ console . error ( bgRed ( " ERROR " ) , message )
44+ console . error ( "\nRun with" , bold ( "--help" ) , "for usage information." )
45+ process . exit ( 1 )
46+ }
47+
3648async function run ( ) {
3749 try {
3850 const [ type = "" , filename , ...others ] = cli . input
3951
40- const mode =
52+ /**
53+ * @type {"video" | "image" | null }
54+ */
55+ let mode =
4156 type in imageTypes ? "image" : type in videoTypes ? "video" : null
4257
4358 if ( ! mode ) {
44- cli . showHelp ( 1 )
59+ const idx = await selectOption ( "What do you want to capture?" , [
60+ "Video" ,
61+ "Screenshot" ,
62+ ] )
63+ mode = idx === 0 ? "video" : "image"
64+ logUpdate (
65+ `💡 Hint! In the future you can run ${ bold (
66+ `npx android-capture ${ mode } ` ,
67+ ) } \n`,
68+ )
69+ logUpdate . done ( )
70+ await new Promise ( ( r ) => setTimeout ( r , 1000 ) )
4571 }
4672
4773 if ( others . length ) {
48- console . error ( "Unexpected arguements: " , others . join ( " " ) )
49- cli . showHelp ( 1 )
74+ fail ( "Unexpected arguements: " + others . join ( " " ) )
5075 }
5176
5277 const extension = mode === "image" ? "png" : "mp4"
@@ -58,12 +83,18 @@ async function run() {
5883 generateFilename ( defaultFilename , extension ) ,
5984 )
6085
86+ if ( cli . flags . copy && mode === "video" ) {
87+ fail ( `The ${ bold ( "--copy" ) } option does not work with video.` )
88+ }
89+
90+ const useTemporaryFile = ! filename && cli . flags . copy && ! cli . flags . open
91+
6192 await init ( )
6293
6394 if ( mode === "video" ) {
6495 await recordVideo ( outPath )
6596 } else {
66- await takeScreenshot ( outPath )
97+ await takeScreenshot ( outPath , useTemporaryFile )
6798 }
6899
69100 if ( cli . flags . open ) {
0 commit comments