Skip to content

Commit

Permalink
Imrpove the addons installer progress bars and fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
tsterbak committed Apr 11, 2023
1 parent 3b75594 commit 406ac40
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 24 deletions.
1 change: 1 addition & 0 deletions openandroidinstaller/app_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 25 additions & 14 deletions openandroidinstaller/tooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
38 changes: 28 additions & 10 deletions openandroidinstaller/views/install_addons_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from loguru import logger
from time import sleep
from typing import Callable
from pathlib import Path

from flet import (
Column,
Expand All @@ -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,
Expand All @@ -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):
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 406ac40

Please sign in to comment.