diff --git a/openandroidinstaller/app_state.py b/openandroidinstaller/app_state.py index 49f69155..eee468a9 100644 --- a/openandroidinstaller/app_state.py +++ b/openandroidinstaller/app_state.py @@ -40,6 +40,7 @@ def __init__( # placeholders self.advanced = False self.install_addons = False + self.addon_paths = [] self.config = None self.image_path = None self.recovery_path = None diff --git a/openandroidinstaller/tooling.py b/openandroidinstaller/tooling.py index c8b95dfd..f377c650 100644 --- a/openandroidinstaller/tooling.py +++ b/openandroidinstaller/tooling.py @@ -262,30 +262,40 @@ def adb_twrp_wipe_and_install( yield line -def adb_twrp_install_addons( - bin_path: Path, addons: List[str], is_ab: bool +def adb_twrp_install_addon( + bin_path: Path, addon_path: str, is_ab: bool ) -> TerminalResponse: - """Flash addons through adb and twrp. + """Flash addon through adb and twrp. Only works for twrp recovery. """ - logger.info("Install addons with twrp.") + logger.info(f"Install addon {addon_path} with twrp.") sleep(0.5) if is_ab: adb_wait_for_recovery(bin_path=bin_path) - logger.info("Sideload and install addons.") - for addon in addons: - # activate sideload - logger.info("Activate sideload.") - for line in activate_sideload(bin_path=bin_path): - yield line - # now flash os image - for line in adb_sideload(bin_path=bin_path, target=addon): - yield line - sleep(7) + # activate sideload + logger.info("Activate sideload.") + for line in activate_sideload(bin_path=bin_path): + yield line + logger.info("Sideload and install addon.") + # now flash the addon + for line in adb_sideload(bin_path=bin_path, target=addon_path): + yield line + sleep(7) + logger.info("done.") + + +def adb_twrp_finish_install_addons( + bin_path: Path, is_ab: bool +) -> TerminalResponse: + """Finish the process of flashing addons with TWRP and reboot. + + Only works for twrp recovery. + """ sleep(3) # finally reboot into os if is_ab: + logger.info("Switch partitions on a/b-partitioned device.") # reboot into the bootloader again for line in adb_reboot_bootloader(bin_path=bin_path): yield line @@ -302,6 +312,7 @@ def adb_twrp_install_addons( yield line else: # reboot with adb + logger.info("Reboot into OS.") for line in adb_reboot(bin_path=bin_path): yield line diff --git a/openandroidinstaller/views/install_addons_view.py b/openandroidinstaller/views/install_addons_view.py index 547ea540..a5a5c294 100644 --- a/openandroidinstaller/views/install_addons_view.py +++ b/openandroidinstaller/views/install_addons_view.py @@ -16,6 +16,7 @@ from loguru import logger from time import sleep from typing import Callable +from pathlib import Path from flet import ( Column, @@ -33,7 +34,7 @@ from views import BaseView from app_state import AppState -from tooling import adb_twrp_install_addons +from tooling import adb_twrp_install_addon, adb_twrp_finish_install_addons from widgets import ( confirm_button, get_title, @@ -55,6 +56,8 @@ def build(self): """Create the content of the view.""" # error text self.error_text = Text("", color=colors.RED) + # text field to inform about the currently installing addon + self.addon_info_text = Text("") # switch to enable advanced output - here it means show terminal input/output in tool def check_advanced_switch(e): @@ -112,8 +115,9 @@ def check_advanced_switch(e): # build the view self.right_view.controls.extend( [ - Row([self.error_text]), + Row([self.addon_info_text]), Row([self.progress_indicator]), + Row([self.error_text]), Column( [ self.advanced_switch, @@ -150,24 +154,38 @@ def run_install_addons(self, e): # disable the call button while the command is running self.install_button.disabled = True self.error_text.value = "" - # reset the progress indicators - self.progress_indicator.clear() + self.addon_info_text.value = "" # reset terminal output if self.state.advanced: self.terminal_box.clear() self.right_view.update() # run the install script - for line in adb_twrp_install_addons( - addons=self.state.addon_paths, + for addon_num, addon_path in enumerate(self.state.addon_paths): + # reset the progress indicators + self.progress_indicator.clear() + # inform about the currently installed addon + self.addon_info_text.value = f"{addon_num + 1}/{len(self.state.addon_paths)}: Installing {Path(addon_path).name} ..." + self.right_view.update() + + # install one addon at the time + for line in adb_twrp_install_addon( + addon_path=addon_path, + bin_path=self.state.bin_path, + is_ab=self.state.config.is_ab, + ): + # write the line to advanced output terminal + self.terminal_box.write_line(line) + # in case the install command is run, we want to update the progress bar + self.progress_indicator.display_progress_bar(line) + self.progress_indicator.update() + + # reboot after installing the addons; here we might switch partitions on ab-partitioned devices + for line in adb_twrp_finish_install_addons( bin_path=self.state.bin_path, is_ab=self.state.config.is_ab, ): - # write the line to advanced output terminal self.terminal_box.write_line(line) - # in case the install command is run, we want to update the progress bar - self.progress_indicator.display_progress_bar(line) - self.progress_indicator.update() success = line # the last element of the iterable is a boolean encoding success/failure # update the view accordingly