Skip to content

Commit f665349

Browse files
committed
Start adding a progressbar for flashing
1 parent 53712c1 commit f665349

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

openandroidinstaller/views/step_view.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from time import sleep
1818
from typing import Callable
1919
from functools import partial
20+
import regex as re
2021

2122
from flet import (
2223
UserControl,
@@ -29,6 +30,7 @@
2930
Container,
3031
Switch,
3132
alignment,
33+
ProgressBar,
3234
colors,
3335
)
3436

@@ -73,6 +75,9 @@ def __init__(
7375
self.inputtext = TextField(
7476
hint_text="your unlock code", expand=False
7577
) # textfield for the unlock code
78+
79+
# placeholder for the flashing progressbar
80+
self.progressbar = None
7681

7782
def build(self):
7883
"""Create the content of a view from step."""
@@ -226,6 +231,26 @@ def call_to_phone(self, e, command: str):
226231
if command in cmd_mapping.keys():
227232
for line in cmd_mapping.get(command)(bin_path=self.state.bin_path):
228233
self.terminal_box.write_line(line)
234+
# in case the install command is run, we want to update the progress bar
235+
if command == "adb_twrp_wipe_and_install":
236+
# TODO: add and/or update the progressbar here
237+
percentage_done = -1
238+
# get the progress numbers from the output lines
239+
result = re.search(r"\(~(\d{1,3})\%\)|(Total xfer: 1.00x)", line)
240+
if result.group(1):
241+
percentage_done = int(result.group(1))
242+
elif result.group(2):
243+
percentage_done = 100
244+
245+
# create the progress bar on first occurrence
246+
if percentage_done == 0:
247+
self.progressbar = ProgressBar(width=400, bar_height=8, color="#00d886")
248+
self.right_view.controls.append(self.progressbar)
249+
# update the progress bar
250+
if self.progressbar:
251+
self.progressbar.value = percentage_done / 100
252+
self.right_view.update()
253+
229254
else:
230255
msg = f"Unknown command type: {command}. Stopping."
231256
logger.error(msg)
@@ -242,7 +267,7 @@ def call_to_phone(self, e, command: str):
242267
else:
243268
sleep(5) # wait to make sure everything is fine
244269
logger.success(f"Command {command} run successfully. Allow to continue.")
245-
# emable the confirm buton and disable the call button
270+
# enable the confirm button and disable the call button
246271
self.confirm_button.disabled = False
247272
self.call_button.disabled = True
248273
self.view.update()

0 commit comments

Comments
 (0)