Skip to content

Commit 406ac40

Browse files
committed
Imrpove the addons installer progress bars and fix issues
1 parent 3b75594 commit 406ac40

File tree

3 files changed

+54
-24
lines changed

3 files changed

+54
-24
lines changed

openandroidinstaller/app_state.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def __init__(
4040
# placeholders
4141
self.advanced = False
4242
self.install_addons = False
43+
self.addon_paths = []
4344
self.config = None
4445
self.image_path = None
4546
self.recovery_path = None

openandroidinstaller/tooling.py

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -262,30 +262,40 @@ def adb_twrp_wipe_and_install(
262262
yield line
263263

264264

265-
def adb_twrp_install_addons(
266-
bin_path: Path, addons: List[str], is_ab: bool
265+
def adb_twrp_install_addon(
266+
bin_path: Path, addon_path: str, is_ab: bool
267267
) -> TerminalResponse:
268-
"""Flash addons through adb and twrp.
268+
"""Flash addon through adb and twrp.
269269
270270
Only works for twrp recovery.
271271
"""
272-
logger.info("Install addons with twrp.")
272+
logger.info(f"Install addon {addon_path} with twrp.")
273273
sleep(0.5)
274274
if is_ab:
275275
adb_wait_for_recovery(bin_path=bin_path)
276-
logger.info("Sideload and install addons.")
277-
for addon in addons:
278-
# activate sideload
279-
logger.info("Activate sideload.")
280-
for line in activate_sideload(bin_path=bin_path):
281-
yield line
282-
# now flash os image
283-
for line in adb_sideload(bin_path=bin_path, target=addon):
284-
yield line
285-
sleep(7)
276+
# activate sideload
277+
logger.info("Activate sideload.")
278+
for line in activate_sideload(bin_path=bin_path):
279+
yield line
280+
logger.info("Sideload and install addon.")
281+
# now flash the addon
282+
for line in adb_sideload(bin_path=bin_path, target=addon_path):
283+
yield line
284+
sleep(7)
285+
logger.info("done.")
286+
287+
288+
def adb_twrp_finish_install_addons(
289+
bin_path: Path, is_ab: bool
290+
) -> TerminalResponse:
291+
"""Finish the process of flashing addons with TWRP and reboot.
292+
293+
Only works for twrp recovery.
294+
"""
286295
sleep(3)
287296
# finally reboot into os
288297
if is_ab:
298+
logger.info("Switch partitions on a/b-partitioned device.")
289299
# reboot into the bootloader again
290300
for line in adb_reboot_bootloader(bin_path=bin_path):
291301
yield line
@@ -302,6 +312,7 @@ def adb_twrp_install_addons(
302312
yield line
303313
else:
304314
# reboot with adb
315+
logger.info("Reboot into OS.")
305316
for line in adb_reboot(bin_path=bin_path):
306317
yield line
307318

openandroidinstaller/views/install_addons_view.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from loguru import logger
1717
from time import sleep
1818
from typing import Callable
19+
from pathlib import Path
1920

2021
from flet import (
2122
Column,
@@ -33,7 +34,7 @@
3334

3435
from views import BaseView
3536
from app_state import AppState
36-
from tooling import adb_twrp_install_addons
37+
from tooling import adb_twrp_install_addon, adb_twrp_finish_install_addons
3738
from widgets import (
3839
confirm_button,
3940
get_title,
@@ -55,6 +56,8 @@ def build(self):
5556
"""Create the content of the view."""
5657
# error text
5758
self.error_text = Text("", color=colors.RED)
59+
# text field to inform about the currently installing addon
60+
self.addon_info_text = Text("")
5861

5962
# switch to enable advanced output - here it means show terminal input/output in tool
6063
def check_advanced_switch(e):
@@ -112,8 +115,9 @@ def check_advanced_switch(e):
112115
# build the view
113116
self.right_view.controls.extend(
114117
[
115-
Row([self.error_text]),
118+
Row([self.addon_info_text]),
116119
Row([self.progress_indicator]),
120+
Row([self.error_text]),
117121
Column(
118122
[
119123
self.advanced_switch,
@@ -150,24 +154,38 @@ def run_install_addons(self, e):
150154
# disable the call button while the command is running
151155
self.install_button.disabled = True
152156
self.error_text.value = ""
153-
# reset the progress indicators
154-
self.progress_indicator.clear()
157+
self.addon_info_text.value = ""
155158
# reset terminal output
156159
if self.state.advanced:
157160
self.terminal_box.clear()
158161
self.right_view.update()
159162

160163
# run the install script
161-
for line in adb_twrp_install_addons(
162-
addons=self.state.addon_paths,
164+
for addon_num, addon_path in enumerate(self.state.addon_paths):
165+
# reset the progress indicators
166+
self.progress_indicator.clear()
167+
# inform about the currently installed addon
168+
self.addon_info_text.value = f"{addon_num + 1}/{len(self.state.addon_paths)}: Installing {Path(addon_path).name} ..."
169+
self.right_view.update()
170+
171+
# install one addon at the time
172+
for line in adb_twrp_install_addon(
173+
addon_path=addon_path,
174+
bin_path=self.state.bin_path,
175+
is_ab=self.state.config.is_ab,
176+
):
177+
# write the line to advanced output terminal
178+
self.terminal_box.write_line(line)
179+
# in case the install command is run, we want to update the progress bar
180+
self.progress_indicator.display_progress_bar(line)
181+
self.progress_indicator.update()
182+
183+
# reboot after installing the addons; here we might switch partitions on ab-partitioned devices
184+
for line in adb_twrp_finish_install_addons(
163185
bin_path=self.state.bin_path,
164186
is_ab=self.state.config.is_ab,
165187
):
166-
# write the line to advanced output terminal
167188
self.terminal_box.write_line(line)
168-
# in case the install command is run, we want to update the progress bar
169-
self.progress_indicator.display_progress_bar(line)
170-
self.progress_indicator.update()
171189
success = line # the last element of the iterable is a boolean encoding success/failure
172190

173191
# update the view accordingly

0 commit comments

Comments
 (0)