|
15 | 15 |
|
16 | 16 | import sys |
17 | 17 | import webbrowser |
18 | | -from loguru import logger |
| 18 | +from pathlib import Path |
19 | 19 | from subprocess import STDOUT, CalledProcessError, call, check_output |
20 | 20 | from time import sleep |
21 | 21 | from typing import Callable, Optional |
22 | | -from pathlib import Path |
23 | 22 |
|
24 | 23 | import flet |
25 | | -from flet import ( |
26 | | - AppBar, |
27 | | - Banner, |
28 | | - Checkbox, |
29 | | - Column, |
30 | | - Container, |
31 | | - Divider, |
32 | | - ElevatedButton, |
33 | | - FilePicker, |
34 | | - FilePickerResultEvent, |
35 | | - Icon, |
36 | | - Image, |
37 | | - Page, |
38 | | - ProgressBar, |
39 | | - ProgressRing, |
40 | | - Row, |
41 | | - Text, |
42 | | - TextButton, |
43 | | - TextField, |
44 | | - UserControl, |
45 | | - VerticalDivider, |
46 | | - colors, |
47 | | - FilledButton, |
48 | | - AlertDialog, |
49 | | - icons, |
50 | | -) |
| 24 | +from flet import (AlertDialog, AppBar, Banner, Checkbox, Column, Container, |
| 25 | + Divider, ElevatedButton, FilePicker, FilePickerResultEvent, |
| 26 | + FilledButton, Icon, Image, Page, ProgressBar, ProgressRing, |
| 27 | + Row, Text, TextButton, TextField, UserControl, |
| 28 | + VerticalDivider, colors, icons) |
51 | 29 | from installer_config import InstallerConfig, Step |
| 30 | +from loguru import logger |
| 31 | +from tool_utils import call_tool_with_command, search_device |
52 | 32 | from widgets import call_button, confirm_button, get_title |
53 | | -from tool_utils import search_device, call_tool_with_command |
54 | 33 |
|
55 | 34 | # Toggle to True for development purposes |
56 | | -DEVELOPMENT = False |
| 35 | +DEVELOPMENT = False |
57 | 36 | DEVELOPMENT_CONFIG = "a3y17lte" # "sargo" |
58 | 37 |
|
59 | 38 |
|
@@ -183,17 +162,21 @@ def search_devices(self, e): |
183 | 162 | if DEVELOPMENT: |
184 | 163 | # this only happens for testing |
185 | 164 | device_code = DEVELOPMENT_CONFIG |
186 | | - logger.info(f"Running search in development mode and loading config {device_code}.yaml.") |
| 165 | + logger.info( |
| 166 | + f"Running search in development mode and loading config {device_code}.yaml." |
| 167 | + ) |
187 | 168 | else: |
188 | 169 | device_code = search_device(platform=PLATFORM, bin_path=BIN_PATH) |
189 | 170 | if device_code: |
190 | 171 | self.device_name.value = device_code |
191 | 172 | else: |
192 | | - self.device_name.value = "No device detected! Connect to USB and try again." |
| 173 | + self.device_name.value = ( |
| 174 | + "No device detected! Connect to USB and try again." |
| 175 | + ) |
193 | 176 |
|
194 | 177 | # load the config, if a device is detected |
195 | 178 | if device_code: |
196 | | - self.device_name.value = device_code |
| 179 | + self.device_name.value = device_code |
197 | 180 | # load config from file |
198 | 181 | path = CONFIG_PATH.joinpath(Path(f"{device_code}.yaml")) |
199 | 182 | device_name = self.load_config(path) |
@@ -401,7 +384,7 @@ def load_config(self, path: str) -> Optional[str]: |
401 | 384 | return self.config.metadata.get("devicename", "No device name in config.") |
402 | 385 | except FileNotFoundError: |
403 | 386 | logger.info(f"No device config found for {path}.") |
404 | | - return None |
| 387 | + return None |
405 | 388 |
|
406 | 389 | def pick_image_result(self, e: FilePickerResultEvent): |
407 | 390 | self.selected_image.value = ( |
@@ -476,36 +459,32 @@ def build(self): |
476 | 459 | def call_to_phone(self, e, command: str): |
477 | 460 | """ |
478 | 461 | Run the command given on the phone. |
479 | | - |
| 462 | +
|
480 | 463 | Some parts of the command are changed by placeholders. |
481 | 464 | """ |
482 | | - command = command.replace("adb", str(BIN_PATH.joinpath(Path("adb")))) |
483 | | - command = command.replace("fastboot", str(BIN_PATH.joinpath(Path("fastboot")))) |
484 | | - command = command.replace("heimdall", str(BIN_PATH.joinpath(Path("heimdall")))) |
485 | | - |
486 | 465 | command = command.replace("<recovery>", self.recovery_path) |
487 | 466 | command = command.replace("<image>", self.image_path) |
488 | 467 | command = command.replace("<inputtext>", self.inputtext.value) |
| 468 | + |
489 | 469 | self.right_view.controls.append( |
490 | 470 | Row( |
491 | | - [ProgressRing(color="#00d886")], # , Text("Wait for completion...")], |
| 471 | + [ProgressRing(color="#00d886")], |
492 | 472 | alignment="center", |
493 | 473 | ) |
494 | 474 | ) |
495 | 475 | self.right_view.update() |
496 | | - logger.info(f"Run command: {command}") |
497 | | - res = call(f"{command}", shell=True) |
498 | | - if res != 0: |
499 | | - logger.info(f"Command {command} failed.") |
| 476 | + # run the command |
| 477 | + success = call_tool_with_command(command=command, bin_path=BIN_PATH) |
| 478 | + # update the view accordingly |
| 479 | + if success: |
500 | 480 | self.right_view.controls.pop() |
501 | | - self.right_view.controls.append(Text("Command {command} failed!")) |
| 481 | + self.right_view.controls.append(Text(f"Command {command} failed!")) |
502 | 482 | else: |
503 | | - sleep(5) |
| 483 | + sleep(5) # wait to make sure everything is fine |
504 | 484 | self.right_view.controls.pop() # pop the progress ring |
505 | 485 | self.right_view.controls.append( |
506 | 486 | ElevatedButton("Confirm and continue", on_click=self.on_confirm) |
507 | 487 | ) |
508 | | - logger.info("Success.") |
509 | 488 | self.view.update() |
510 | 489 |
|
511 | 490 |
|
|
0 commit comments