Skip to content

Commit

Permalink
Maybe fix path support
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernthedev committed Nov 22, 2023
1 parent e7a6073 commit c1452b6
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions lib/utils/adb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ abstract class Adb {
hostPath.join(await PlatformUtils.configPath(_adbTempFolder)));
}

static Future<File> _getADBPath() async {
static Future<File> _getADBDownloadPath() async {
var downloadPath = await _getDownloadPath();
return File(hostPath.join(downloadPath.path, "platform-tools", "adb"));
}
Expand Down Expand Up @@ -67,29 +67,36 @@ abstract class Adb {
final archive = ZipDecoder().decodeBuffer(InputStream(stream));

extractArchiveToDisk(archive, downloadPath.path);
_adbCurrentPath = (await _getADBPath()).path;
_adbCurrentPath = (await _getADBDownloadPath()).path;
await Process.run("chmod", ["+x", _adbCurrentPath!]);
}

static Future<String> _getAdbPath() async {
if (_adbCurrentPath == null) {
var downloadPath = await _getDownloadPath();
if (await downloadPath.exists()) {
_adbCurrentPath = (await _getADBPath()).path;
} else {
// Use adb in path
_adbCurrentPath = "adb";
}
if (_adbCurrentPath != null) {
return _adbCurrentPath!;
}

var downloadPath = await _getDownloadPath();
if (await downloadPath.exists()) {
_adbCurrentPath = (await _getADBDownloadPath()).path;
} else if (Platform.isWindows) {
_adbCurrentPath = "adb.exe";
} else {
// Use adb in path

_adbCurrentPath = "adb";
}


return _adbCurrentPath!;
}

static Future<ProcessResult> runAdbCommand(
String? serial, List<String> args) async {
var newArgs = serial != null ? ["-s", serial, ...args] : args;

var process = await Process.run(await _getAdbPath(), newArgs);
var process =
await Process.run(await _getAdbPath(), newArgs, runInShell: true);
if (process.stderr != null && process.stderr.toString().isNotEmpty) {
final error = process.stderr;
debugPrint("Error $error");
Expand All @@ -106,7 +113,7 @@ abstract class Adb {
String? serial, List<String> args) async {
var newArgs = serial != null ? ["-s", serial, ...args] : args;

return await Process.start(await _getAdbPath(), newArgs);
return await Process.start(await _getAdbPath(), newArgs, runInShell: true);
}

static String normalizeOutput(String output) {
Expand Down

0 comments on commit c1452b6

Please sign in to comment.