1616import os
1717import sys
1818import webbrowser
19+ import click
20+ import functools
1921from pathlib import Path
2022
2123import flet as ft
5052# where to write the logs
5153logger .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
5857PLATFORM = sys .platform
5958# Define asset paths
6059CONFIG_PATH = (
6463
6564
6665class 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+
135140def 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 ()
0 commit comments