Skip to content

Commit 2d7aac0

Browse files
committed
major refactoring and decupling of frontend and logic
1 parent be8ef3f commit 2d7aac0

File tree

10 files changed

+693
-610
lines changed

10 files changed

+693
-610
lines changed

openandroidinstaller/app_state.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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.config = None
49+
self.image_path = None
50+
self.recovery_path = None
51+
52+
# is this still needed?
53+
self.steps = None
54+
55+
def load_config(self, device_code: str):
56+
"""Load the config from file to state by device code."""
57+
self.config = _load_config(device_code, self.config_path)
58+
if self.config:
59+
self.steps = (
60+
self.config.unlock_bootloader
61+
+ self.config.flash_recovery
62+
+ self.config.install_os
63+
)
64+
self.num_total_steps = len(self.steps)
65+
66+
def increment_progressbar(self):
67+
"""Increment the progressbar and step counter."""
68+
self.progressbar.value = (self.num_steps - 1) / (
69+
self.num_total_steps + 2
70+
) # don't show on the first step
71+
self.num_steps += 1 # increase the step counter

openandroidinstaller/installer_config.py

Lines changed: 2 additions & 2 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:

0 commit comments

Comments
 (0)