Skip to content

Commit d009450

Browse files
committed
Refactor some methods
1 parent 2d7aac0 commit d009450

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

openandroidinstaller/tool_utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
STDOUT,
2121
CalledProcessError,
2222
CompletedProcess,
23-
call,
2423
check_output,
2524
run,
2625
)
@@ -214,7 +213,6 @@ def search_device(platform: str, bin_path: Path) -> Optional[str]:
214213
logger.info(f"Search devices on {platform} with {bin_path}...")
215214
try:
216215
# read device properties
217-
# TODO: This is not windows ready...
218216
if platform in ("linux", "darwin"):
219217
output = check_output(
220218
[
@@ -246,5 +244,5 @@ def search_device(platform: str, bin_path: Path) -> Optional[str]:
246244
logger.info(device_code)
247245
return device_code
248246
except CalledProcessError:
249-
logger.info(f"Did not detect a device.")
247+
logger.info(f"Failed to detect a device.")
250248
return None

openandroidinstaller/views.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import flet
2222
from flet import (
2323
AlertDialog,
24+
alignment,
2425
AppBar,
2526
Banner,
2627
Checkbox,
@@ -501,17 +502,22 @@ def call_to_phone(self, e, command: str):
501502
Row(
502503
[ProgressRing(color="#00d886")],
503504
alignment="center",
504-
)
505+
),
505506
)
506507
self.right_view.update()
507508

509+
cmd_mapping = {
510+
"adb_reboot": adb_reboot,
511+
"adb_reboot_bootloader": adb_reboot_bootloader,
512+
"adb_reboot_download": adb_reboot_download,
513+
"fastboot_unlock": fastboot_unlock,
514+
"fastboot_oem_unlock": fastboot_oem_unlock,
515+
"fastboot_reboot": fastboot_reboot,
516+
}
517+
508518
# run the right command
509-
if command == "adb_reboot":
510-
success = adb_reboot(bin_path=self.state.bin_path)
511-
elif command == "adb_reboot_bootloader":
512-
success = adb_reboot_bootloader(bin_path=self.state.bin_path)
513-
elif command == "adb_reboot_download":
514-
success = adb_reboot_download(bin_path=self.state.bin_path)
519+
if command in cmd_mapping.keys():
520+
success = cmd_mapping.get(command)(bin_path=self.state.bin_path)
515521
elif command == "adb_sideload":
516522
success = adb_sideload(
517523
bin_path=self.state.bin_path, target=self.state.image_path
@@ -528,12 +534,6 @@ def call_to_phone(self, e, command: str):
528534
success = fastboot_unlock_with_code(
529535
bin_path=self.state.bin_path, unlock_code=self.inputtext.value
530536
)
531-
elif command == "fastboot_unlock":
532-
success = fastboot_unlock(bin_path=self.state.bin_path)
533-
elif command == "fastboot_oem_unlock":
534-
success = fastboot_oem_unlock(bin_path=self.state.bin_path)
535-
elif command == "fastboot_reboot":
536-
success = fastboot_reboot(bin_path=self.state.bin_path)
537537
elif command == "heimdall_flash_recovery":
538538
success = heimdall_flash_recovery(
539539
bin_path=self.state.bin_path, recovery=self.state.recovery_path

0 commit comments

Comments
 (0)