Skip to content

Commit

Permalink
Add socket name as cli argument
Browse files Browse the repository at this point in the history
e.g. to get tabs from Chrome Beta instead of regular Chrome (see machinateur#2)
  • Loading branch information
devnll committed May 24, 2022
1 parent 933bc81 commit 17d422a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Arguments:

Options:
-p, --port=PORT The port to forward requests using `adb`. [default: 9222]
-s, --socket=SOCKET The socket to forward requests using `adb`. [default: "chrome_devtools_remote"]
-h, --help Display help for the given command. When no command is given display help for the copy-tabs command
-q, --quiet Do not output any message
-V, --version Display this application version
Expand Down
22 changes: 19 additions & 3 deletions src/Command/CopyTabsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class CopyTabsCommand extends Command
*/
private const DEFAULT_PORT = 9222;

/**
* @var string
*/
private const DEFAULT_SOCKET = 'chrome_devtools_remote';

/**
* @var string
*/
Expand All @@ -59,7 +64,8 @@ protected function configure(): void
$this
->setDescription('A tool to transfer tabs from your android phone to your computer using `adb`.')
->addArgument('file', InputArgument::OPTIONAL, 'The relative filepath to write.', self::DEFAULT_FILE)
->addOption('port', 'p', InputOption::VALUE_REQUIRED, 'The port to forward requests using `adb`.', self::DEFAULT_PORT);
->addOption('port', 'p', InputOption::VALUE_REQUIRED, 'The port to forward requests using `adb`.', self::DEFAULT_PORT)
->addOption('socket', 's', InputOption::VALUE_REQUIRED, 'The socket to forward requests using `adb`.', self::DEFAULT_SOCKET);
}

/**
Expand Down Expand Up @@ -87,13 +93,23 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln("Invalid port given, default to {$argumentPort}.");
}

// Get `socket` argument:

$argumentSocket = $input->getOption('socket');

if (!is_string($argumentSocket)) {
$argumentSocket = self::DEFAULT_SOCKET;

$output->writeln("Invalid socket given, default to {$argumentSocket}.");
}

// Run `adb` command:

$output->writeln('Running adb command...');

$output->writeln("> adb -d forward tcp:{$argumentPort} localabstract:chrome_devtools_remote");
$output->writeln("> adb -d forward tcp:{$argumentPort} localabstract:{$argumentSocket}");
$output->write(
shell_exec("adb -d forward tcp:{$argumentPort} localabstract:chrome_devtools_remote")
shell_exec("adb -d forward tcp:{$argumentPort} localabstract:{$argumentSocket}")
);

// Download tabs:
Expand Down

0 comments on commit 17d422a

Please sign in to comment.