« script/electric-sheep-dump-current-location.pl
↑ Summary
script/electric-sheep-dump-screen-shot.pl »
| 1 | #!/usr/bin/env perl | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | our $VERSION = '0.09'; | ||
| 7 | |||
| 8 | use lib ('blib/lib'); | ||
| 9 | |||
| 10 | use Getopt::Long qw(:config no_ignore_case); | ||
| 11 | use Data::Roundtrip qw/perl2dump perl2json no-unicode-escape-permanently/; | ||
| 12 | |||
| 13 | use Android::ElectricSheep::Automator; | ||
| 14 | |||
| 15 | my $VERBOSITY = 0; # we need verbosity of 10 (max), so this is not used | ||
| 16 | my $DEVICE; | ||
| 17 | my $CONFIGFILE; | ||
| 18 | my $OUTFILE; | ||
| 19 | |||
| 20 | if( ! Getopt::Long::GetOptions( | ||
| 21 | 'device|d=s' => \$DEVICE, | ||
| 22 | 'verbosity|v=i' => \$VERBOSITY, | ||
| 23 | 'output|o=s'=> \$OUTFILE, | ||
| 24 | 'configfile|c=s' => \$CONFIGFILE, | ||
| 25 | 'help|h' => sub { print STDOUT usage(); exit(0); } | ||
| 26 | ) ){ die usage() } | ||
| 27 | |||
| 28 | if( ! defined $CONFIGFILE ){ print STDERR usage(); print STDERR "\n$0 : error, a configuration file must be specified with '--configfile'.\n"; exit(1); } | ||
| 29 | if( ! -f $CONFIGFILE ){ die "$0 : failed to find config file '$CONFIGFILE'." } | ||
| 30 | |||
| 31 | my $params = { | ||
| 32 | 'configfile' => $CONFIGFILE, | ||
| 33 | 'verbosity' => $VERBOSITY, | ||
| 34 | }; | ||
| 35 | # we assume there is a device connected which the user | ||
| 36 | # must specify by serial, of if just one, we connect to | ||
| 37 | # it without the serial | ||
| 38 | if( defined $DEVICE ){ $params->{'device-serial'} = $DEVICE } | ||
| 39 | else { $params->{'device-is-connected'} = 1 } | ||
| 40 | |||
| 41 | my $client = Android::ElectricSheep::Automator->new($params); | ||
| 42 | if( ! defined($client) ){ die "$0 : failed to instantiate the automator." } | ||
| 43 | |||
| 44 | my $uparams = {}; | ||
| 45 | if( defined $OUTFILE ){ $uparams->{'filename'} = $OUTFILE } | ||
| 46 | my $uixml = $client->dump_current_screen_ui($uparams); | ||
| 47 | if( ! defined($uixml) ){ die "$0 : failed to dump current screen UI." } | ||
| 48 | |||
| 49 | if( ! defined $OUTFILE ){ print STDOUT $uixml->{'raw'} } | ||
| 50 | |||
| 51 | print STDOUT "$0 : done, success!".(defined($OUTFILE)?" Output written to file '$OUTFILE'.\n":"\n"); | ||
| 52 | |||
| 53 | sub usage { | ||
| 54 | return "Usage $0 --configfile CONFIGFILE [--output file.xml] [--device DEVICE] [--verbosity v]\n" | ||
| 55 | . "\nThis script will dump the current screen UI layout as XML.\n" | ||
| 56 | . "\nExample:\n" | ||
| 57 | . "$0 --configfile config/myapp.conf --output ui.xml\n" | ||
| 58 | . "\nProgram by Andreas Hadjiprocopis (c) 2025 / bliako at cpan.org / andreashad2 at gmail.com\n\n" | ||
| 59 | ; | ||
| 60 | } | ||
| 61 | |||
| 62 | 1; |