Skip to content

Commit 5189364

Browse files
committed
refactor call_to_phone method
1 parent 36c326d commit 5189364

1 file changed

Lines changed: 7 additions & 27 deletions

File tree

openandroidinstaller/views/step_view.py

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from time import sleep
1818
from typing import Callable
1919
from pathlib import Path
20+
from functools import partial
2021

2122
from flet import (
2223
UserControl,
@@ -182,46 +183,25 @@ def call_to_phone(self, e, command: str):
182183
self.right_view.controls.append(progress_bar)
183184
self.right_view.update()
184185

186+
# get the appropriate function to run for every possible command.
185187
cmd_mapping = {
186188
"adb_reboot": adb_reboot,
187189
"adb_reboot_bootloader": adb_reboot_bootloader,
188190
"adb_reboot_download": adb_reboot_download,
191+
"adb_sideload": partial(adb_sideload, target=self.state.image_path),
192+
"adb_twrp_wipe_and_install": partial(adb_twrp_wipe_and_install, target=self.state.image_path, config_path=self.state.config_path),
189193
"fastboot_unlock": fastboot_unlock,
194+
"fastboot_unlock_with_code": partial(fastboot_unlock_with_code, unlock_code=self.inputtext.value),
190195
"fastboot_oem_unlock": fastboot_oem_unlock,
196+
"fastboot_flash_recovery": partial(fastboot_flash_recovery, recovery=self.state.recovery_path),
191197
"fastboot_reboot": fastboot_reboot,
198+
"heimdall_flash_recovery": partial(heimdall_flash_recovery, recovery=self.state.recovery_path),
192199
}
193200

194201
# run the right command
195202
if command in cmd_mapping.keys():
196203
for line in cmd_mapping.get(command)(bin_path=self.state.bin_path):
197204
self.terminal_box.write_line(line)
198-
elif command == "adb_sideload":
199-
for line in adb_sideload(
200-
bin_path=self.state.bin_path, target=self.state.image_path
201-
):
202-
self.terminal_box.write_line(line)
203-
elif command == "adb_twrp_wipe_and_install":
204-
for line in adb_twrp_wipe_and_install(
205-
bin_path=self.state.bin_path,
206-
target=self.state.image_path,
207-
config_path=self.state.config_path,
208-
):
209-
self.terminal_box.write_line(line)
210-
elif command == "fastboot_flash_recovery":
211-
for line in fastboot_flash_recovery(
212-
bin_path=self.state.bin_path, recovery=self.state.recovery_path
213-
):
214-
self.terminal_box.write_line(line)
215-
elif command == "fastboot_unlock_with_code":
216-
for line in fastboot_unlock_with_code(
217-
bin_path=self.state.bin_path, unlock_code=self.inputtext.value
218-
):
219-
self.terminal_box.write_line(line)
220-
elif command == "heimdall_flash_recovery":
221-
for line in heimdall_flash_recovery(
222-
bin_path=self.state.bin_path, recovery=self.state.recovery_path
223-
):
224-
self.terminal_box.write_line(line)
225205
else:
226206
msg = f"Unknown command type: {command}. Stopping."
227207
logger.error(msg)

0 commit comments

Comments
 (0)