Skip to content

Commit

Permalink
Start adding a progressbar for flashing
Browse files Browse the repository at this point in the history
  • Loading branch information
tsterbak committed Jan 7, 2023
1 parent 53712c1 commit f665349
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion openandroidinstaller/views/step_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from time import sleep
from typing import Callable
from functools import partial
import regex as re

from flet import (
UserControl,
Expand All @@ -29,6 +30,7 @@
Container,
Switch,
alignment,
ProgressBar,
colors,
)

Expand Down Expand Up @@ -73,6 +75,9 @@ def __init__(
self.inputtext = TextField(
hint_text="your unlock code", expand=False
) # textfield for the unlock code

# placeholder for the flashing progressbar
self.progressbar = None

def build(self):
"""Create the content of a view from step."""
Expand Down Expand Up @@ -226,6 +231,26 @@ def call_to_phone(self, e, command: str):
if command in cmd_mapping.keys():
for line in cmd_mapping.get(command)(bin_path=self.state.bin_path):
self.terminal_box.write_line(line)
# in case the install command is run, we want to update the progress bar
if command == "adb_twrp_wipe_and_install":
# TODO: add and/or update the progressbar here
percentage_done = -1
# get the progress numbers from the output lines
result = re.search(r"\(~(\d{1,3})\%\)|(Total xfer: 1.00x)", line)
if result.group(1):
percentage_done = int(result.group(1))
elif result.group(2):
percentage_done = 100

# create the progress bar on first occurrence
if percentage_done == 0:
self.progressbar = ProgressBar(width=400, bar_height=8, color="#00d886")
self.right_view.controls.append(self.progressbar)
# update the progress bar
if self.progressbar:
self.progressbar.value = percentage_done / 100
self.right_view.update()

else:
msg = f"Unknown command type: {command}. Stopping."
logger.error(msg)
Expand All @@ -242,7 +267,7 @@ def call_to_phone(self, e, command: str):
else:
sleep(5) # wait to make sure everything is fine
logger.success(f"Command {command} run successfully. Allow to continue.")
# emable the confirm buton and disable the call button
# enable the confirm button and disable the call button
self.confirm_button.disabled = False
self.call_button.disabled = True
self.view.update()
Expand Down

0 comments on commit f665349

Please sign in to comment.