Skip to content

Commit 2b952b0

Browse files
authored
Refactor (#47)
This PR adds: - a debug mode (addressing #27) - basic tests for the full app - Open Feedback page when finishing the install process
2 parents 65e6b4d + 9f588fd commit 2b952b0

4 files changed

Lines changed: 105 additions & 41 deletions

File tree

Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,21 @@ install:
88
export:
99
poetry export -f requirements.txt --output requirements.txt
1010

11+
format:
12+
poetry run black .
13+
1114
lint:
1215
poetry run ruff openandroidinstaller/ --ignore E501
1316

14-
test:
15-
poetry run black .
16-
poetry run ruff openandroidinstaller/ --ignore E501
17+
test: format lint
1718
PYTHONPATH=openandroidinstaller:$(PYTHONPATH) poetry run pytest --cov=openandroidinstaller tests/
1819

1920
app:
2021
poetry run python openandroidinstaller/openandroidinstaller.py
2122

23+
test-app:
24+
poetry run python openandroidinstaller/openandroidinstaller.py --test --test_config sargo
25+
2226
build-app:
2327
poetry run python scripts/build.py
2428

openandroidinstaller/openandroidinstaller.py

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import os
1717
import sys
1818
import webbrowser
19+
import click
20+
import functools
1921
from pathlib import Path
2022

2123
import flet as ft
@@ -50,11 +52,8 @@
5052
# where to write the logs
5153
logger.add("openandroidinstaller.log")
5254

53-
# Toggle to True for development purposes
54-
DEVELOPMENT = False
55-
DEVELOPMENT_CONFIG = "sargo" # "a3y17lte" # "sargo"
56-
5755

56+
# detect platform
5857
PLATFORM = sys.platform
5958
# Define asset paths
6059
CONFIG_PATH = (
@@ -64,15 +63,9 @@
6463

6564

6665
class MainView(UserControl):
67-
def __init__(self):
66+
def __init__(self, state: AppState):
6867
super().__init__()
69-
self.state = AppState(
70-
platform=PLATFORM,
71-
config_path=CONFIG_PATH,
72-
bin_path=BIN_PATH,
73-
test=DEVELOPMENT,
74-
test_config=DEVELOPMENT_CONFIG,
75-
)
68+
self.state = state
7669
# create the main columns
7770
self.view = Column(expand=True, width=1200)
7871

@@ -132,6 +125,18 @@ def confirm(self, e):
132125
self.view.update()
133126

134127

128+
def configure(page: Page):
129+
"""Configure the application."""
130+
# Configure the application base page
131+
page.title = "OpenAndroidInstaller"
132+
page.window_height = 900
133+
page.window_width = int(1.5 * page.window_height)
134+
page.window_top = 100
135+
page.window_left = 120
136+
page.scroll = "adaptive"
137+
page.horizontal_alignment = "center"
138+
139+
135140
def log_version_infos(bin_path):
136141
"""Log the version infos of adb, fastboot and heimdall."""
137142
# adb
@@ -146,18 +151,13 @@ def log_version_infos(bin_path):
146151
logger.info(f"Heimdall version: {hdversion[0]}")
147152

148153

149-
def main(page: Page):
154+
def main(page: Page, test: bool = False, test_config: str = "sargo"):
150155
logger.info(f"Running OpenAndroidInstaller on {PLATFORM}")
151156
log_version_infos(bin_path=BIN_PATH)
152157
logger.info(100 * "-")
153-
# Configure the application base page
154-
page.title = "OpenAndroidInstaller"
155-
page.window_height = 900
156-
page.window_width = int(1.5 * page.window_height)
157-
page.window_top = 100
158-
page.window_left = 120
159-
page.scroll = "adaptive"
160-
page.horizontal_alignment = "center"
158+
159+
# configure the page
160+
configure(page)
161161

162162
# header
163163
page.appbar = AppBar(
@@ -203,26 +203,35 @@ def close_banner(e):
203203
page.banner.open = True
204204
page.update()
205205

206+
# create the State object
207+
state = AppState(
208+
platform=PLATFORM,
209+
config_path=CONFIG_PATH,
210+
bin_path=BIN_PATH,
211+
test=test,
212+
test_config=test_config,
213+
)
206214
# create application instance
207-
app = MainView()
208-
209-
# add a button that restarts the process
210-
# def restart_process(e):
211-
# logger.info("Restarted the process. Reset everything.")
212-
# page.controls.pop()
213-
# app = MainView()
214-
# page.add(app)
215-
# page.update()
216-
217-
# page.floating_action_button = FloatingActionButton(
218-
# text="Restart the process",
219-
# icon=icons.RESTART_ALT_OUTLINED,
220-
# tooltip="You can safely restart if you missed a step or didn't make it.",
221-
# on_click=restart_process,
222-
# )
215+
app = MainView(state=state)
223216

224217
# add application's root control to the page
225218
page.add(app)
226219

227220

228-
ft.app(target=main, assets_dir="assets")
221+
@click.command()
222+
@click.option(
223+
"--test", is_flag=True, default=False, help="Start the application in testing mode."
224+
)
225+
@click.option(
226+
"--test_config", default="sargo", type=str, help="Config to use for testing"
227+
)
228+
def startup(test: bool, test_config: str):
229+
"Main entrypoint to the app."
230+
ft.app(
231+
target=functools.partial(main, test=test, test_config=test_config),
232+
assets_dir="assets",
233+
)
234+
235+
236+
if __name__ == "__main__":
237+
startup()

openandroidinstaller/views/success_view.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# If not, see <https://www.gnu.org/licenses/>."""
1414
# Author: Tobias Sterbak
1515

16+
import webbrowser
1617
from loguru import logger
1718
from flet import (
1819
ElevatedButton,
@@ -35,6 +36,10 @@ def build(
3536
):
3637
def close_window(e):
3738
logger.success("Success! Close the window.")
39+
# open the feedback page
40+
feedback_url = "https://openandroidinstaller.org/feedback.html"
41+
webbrowser.open(feedback_url)
42+
# close the window
3843
self.page.window_close()
3944

4045
# right view header

tests/test_app.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""Test if the main app starts up."""
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+
import flet as ft
17+
from openandroidinstaller.openandroidinstaller import main
18+
19+
20+
class MockResult:
21+
def __init__(
22+
self,
23+
):
24+
self.results = "testtesttest"
25+
26+
27+
class MockConn:
28+
def __init__(self):
29+
self.page_name = "Test page"
30+
self.pubsubhub = "Pub"
31+
32+
def send_commands(self, command, other):
33+
return MockResult()
34+
35+
36+
def test_app():
37+
page = ft.Page(conn=MockConn(), session_id=1)
38+
# test if it would start up
39+
main(page=page, test=True, test_config="sargo")
40+
41+
# test if you can go through all views
42+
state = page.controls[0].state
43+
state.load_config(device_code="sargo")
44+
for _ in range(len(state.steps) + 5):
45+
page.controls[0].confirm(None)
46+
assert "SuccessView" in str(page.controls[0].view.controls[0])

0 commit comments

Comments
 (0)