Skip to content

Commit 6b418e7

Browse files
authored
Improve architecture (#34)
- Only support twrp recoveries in tool now - major refactoring and decoupling of frontend and logic - Enable terminal output in tool - Improve logging
2 parents be8ef3f + 9dd8671 commit 6b418e7

File tree

11 files changed

+903
-723
lines changed

11 files changed

+903
-723
lines changed

openandroidinstaller/app_state.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
"""This file contains a class and function to manage the app state over various steps."""
2+
3+
# This file is part of OpenAndroidInstaller.
4+
# OpenAndroidInstaller is free software: you can redistribute it and/or modify it under the terms of
5+
# the GNU General Public License as published by the Free Software Foundation,
6+
# either version 3 of the License, or (at your option) any later version.
7+
8+
# OpenAndroidInstaller is distributed in the hope that it will be useful, but WITHOUT ANY
9+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or
10+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
11+
12+
# You should have received a copy of the GNU General Public License along with OpenAndroidInstaller.
13+
# If not, see <https://www.gnu.org/licenses/>."""
14+
# Author: Tobias Sterbak
15+
16+
from pathlib import Path
17+
18+
from flet import ProgressBar
19+
from installer_config import _load_config
20+
from loguru import logger
21+
22+
23+
class AppState:
24+
"""Container class to store the state of the application."""
25+
26+
def __init__(
27+
self,
28+
platform: str,
29+
config_path: Path,
30+
bin_path: Path,
31+
progressbar: ProgressBar,
32+
num_steps: int,
33+
test: bool = False,
34+
test_config: str = None,
35+
):
36+
self.platform = platform
37+
self.config_path = config_path
38+
self.bin_path = bin_path
39+
self.progressbar = progressbar
40+
self.num_steps = num_steps # keep track of the steps already taken
41+
self.test = test
42+
self.test_config = test_config
43+
44+
# initialize the progress bar at 0
45+
self.progressbar.value = 0
46+
47+
# placeholders
48+
self.advanced = False
49+
self.config = None
50+
self.image_path = None
51+
self.recovery_path = None
52+
53+
# is this still needed?
54+
self.steps = None
55+
56+
def load_config(self, device_code: str):
57+
"""Load the config from file to state by device code."""
58+
self.config = _load_config(device_code, self.config_path)
59+
if self.config:
60+
self.steps = (
61+
self.config.unlock_bootloader
62+
+ self.config.flash_recovery
63+
+ self.config.install_os
64+
)
65+
self.num_total_steps = len(self.steps)
66+
67+
def increment_progressbar(self):
68+
"""Increment the progressbar and step counter."""
69+
self.progressbar.value = (self.num_steps - 1) / (
70+
self.num_total_steps + 2
71+
) # don't show on the first step
72+
self.num_steps += 1 # increase the step counter

openandroidinstaller/assets/configs/sargo.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ steps:
4444
- type: call_button
4545
content: >
4646
In the next steps, you finally flash the selected OS image.
47-
Connect your device with your computer with the USB-Cable.
47+
Wait until the TWRP screen appears. Then run the command.
4848
This step will format your phone and wipe all the data. It will also remove encryption and delete all files stored
4949
in the internal storage. Then the OS image will be installed. Confirm to run. This might take a while. At the end your phone will boot into the new OS.
5050
command: adb_twrp_wipe_and_install

openandroidinstaller/installer_config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515

1616
from pathlib import Path
1717
from typing import List, Optional
18-
import schema
19-
from schema import Regex, Schema, SchemaError
2018

19+
import schema
2120
import yaml
2221
from loguru import logger
22+
from schema import Regex, Schema, SchemaError
2323

2424

2525
class Step:
@@ -148,8 +148,8 @@ def validate_config(config: str) -> bool:
148148
)
149149
try:
150150
config_schema.validate(config)
151-
logger.info("Config is valid.")
151+
logger.success("Config is valid.")
152152
return True
153153
except SchemaError as se:
154-
logger.info(f"Config is invalid. Error {se}")
154+
logger.error(f"Config is invalid. Error {se}")
155155
return False

0 commit comments

Comments
 (0)