1+ from time import sleep
12import flet
2- from flet import AppBar , ElevatedButton , Page , Text , View , Row
3+ from flet import (AppBar , ElevatedButton , Page , Text , View , Row , ProgressRing , Column , FilePicker , FilePickerResultEvent , icons )
4+ from typing import List
5+ from subprocess import check_output , STDOUT , call
6+ from functools import partial
37
48
5- from subprocess import check_output , STDOUT
9+ recovery_path = None
10+ image_path = None
611
712
813def main (page : Page ):
914 page .title = "OpenAndroidInstaller"
1015 views = []
11- blocked = False
1216
1317 # Click-event handlers
1418
15- def go_next (e ):
19+ def confirm (e ):
1620 view_num = int (page .views [- 1 ].route ) + 1
17- if view_num > 6 :
18- view_num = 6
21+ # if view_num > 6:
22+ # view_num = 6
1923 page .views .clear ()
2024 page .views .append (views [view_num ])
2125 page .update ()
@@ -28,108 +32,108 @@ def go_back(e):
2832 page .views .append (views [view_num ])
2933 page .update ()
3034
31- def check_devices (e ):
35+ def search_devices (e ):
3236 try :
3337 output = check_output (["adb" , "shell" , "dumpsys" , "bluetooth_manager" , "|" , "grep" , "\' name:\' " , "|" , "cut" , "-c9-" ], stderr = STDOUT ).decode ()
3438 page .views [- 1 ].controls .append (Text (f"Detected: { output } " ))
35- page .views [- 1 ].controls .append (get_confirm_button ( "Is this correct?" ))
39+ page .views [- 1 ].controls .append (ElevatedButton ( "Confirm and continue" , on_click = confirm ))
3640 except :
3741 output = "No device detected!"
3842 page .views [- 1 ].controls .append (Text (f"{ output } " ))
3943 page .update ()
4044
45+ def call_to_phone (e , command : str ):
46+ command = command .replace ("recovery" , recovery_path )
47+ #command = command.replace("image", pick_image_dialog.result.path)
48+ page .views [- 1 ].controls .append (ProgressRing ())
49+ page .update ()
50+ res = call (f'{ command } ' , shell = True )
51+ if res != 0 :
52+ page .views [- 1 ].controls .pop ()
53+ page .views [- 1 ].controls .append (Text ("Command {command} failed!" ))
54+ else :
55+ sleep (5 )
56+ page .views [- 1 ].controls .pop ()
57+ page .views [- 1 ].controls .append (ElevatedButton ("Confirm and continue" , on_click = confirm ))
58+ page .update ()
4159
42- def confirm (e ):
43- # unblock
44- blocked = False
60+ # file picker setup
61+
62+ def pick_image_result (e : FilePickerResultEvent ):
63+ selected_image .value = (
64+ ", " .join (map (lambda f : f .name , e .files )) if e .files else "Cancelled!"
65+ )
66+ global image_path
67+ image_path = e .files [0 ].path
68+ selected_image .update ()
69+
70+ def pick_recovery_result (e : FilePickerResultEvent ):
71+ selected_recovery .value = (
72+ ", " .join (map (lambda f : f .name , e .files )) if e .files else "Cancelled!"
73+ )
74+ global recovery_path
75+ recovery_path = e .files [0 ].path
76+ selected_recovery .update ()
77+
78+ pick_image_dialog = FilePicker (on_result = pick_image_result )
79+ pick_recovery_dialog = FilePicker (on_result = pick_recovery_result )
80+ selected_image = Text ()
81+ selected_recovery = Text ()
82+ page .overlay .append (pick_image_dialog )
83+ page .overlay .append (pick_recovery_dialog )
4584
4685 # Generate the Views for the different steps
4786
48- def get_nav ( ) -> Row :
87+ def confirm_button ( text : str , confirm_text : str = "Confirm and continue" ) -> Row :
4988 return Row ([
50- ElevatedButton ( "Back" , on_click = go_back ),
51- ElevatedButton ("Next " , on_click = go_next ),
89+ Text ( f" { text } " ),
90+ ElevatedButton (f" { confirm_text } " , on_click = confirm )
5291 ])
5392
54-
55- def get_confirm_button (notification_text : str ) -> Row :
56- """Get a button with a text to confirm."""
93+
94+ def call_button (text : str , command : str , confirm_text : str = "Confirm and run" ) -> Row :
5795 return Row ([
58- Text (notification_text ),
59- ElevatedButton ("Confirm " , on_click = confirm ),
96+ Text (f" { text } " ),
97+ ElevatedButton (f" { confirm_text } " , on_click = partial ( call_to_phone , command = command ))
6098 ])
6199
62-
63- def get_welcome_view (page : Page ) -> View :
100+ def get_new_view (title : str , index : int , content : List = []) -> View :
64101 return View (
65- "0" ,
66- [
67- AppBar (title = Text ("Welcome to OpenAndroidInstaller!" )),
68- ElevatedButton ("Check devices" , on_click = check_devices ),
69- ElevatedButton ("Next" , on_click = go_next ),
70- ],
71- )
72-
73-
74- def get_bootloader_view (page : Page ) -> View :
75- return View (
76- "1" ,
77- [
78- AppBar (title = Text ("Unlock bootloder" )),
79- Text ("Turn on developer options and OEM Unlock on your phone." ),
80- get_nav (),
81- ],
82- )
83-
84-
85- def get_image_select_view (page : Page ) -> View :
86- return View (
87- "2" ,
88- [
89- AppBar (title = Text ("Select images." )),
90- get_nav (),
91- ],
92- )
93-
94-
95- def get_recovery_view (page : Page ) -> View :
96- return View (
97- "3" ,
98- [
99- AppBar (title = Text ("Boot recovery" )),
100- get_nav (),
101- ],
102- )
103-
104-
105- def get_install_view (page : Page ) -> View :
106- return View (
107- "4" ,
108- [
109- AppBar (title = Text ("Install Lineage OS" )),
110- get_nav (),
111- ],
112- )
113-
114-
115- def get_success_view (page : Page ) -> View :
116- return View (
117- "5" ,
118- [
119- AppBar (title = Text ("Success!" )),
120- ElevatedButton ("Back" , on_click = go_back ),
121- ],
102+ f"{ index } " , [AppBar (title = Text (f"{ title } " ))] + content
122103 )
123104
124105 # main part
125106
126107 views = [
127- get_welcome_view (page ),
128- get_bootloader_view (page ),
129- get_image_select_view (page ),
130- get_recovery_view (page ),
131- get_install_view (page ),
132- get_success_view (page )
108+ get_new_view (title = "Welcome to OpenAndroidInstaller!" , content = [ElevatedButton ("Search device" , on_click = search_devices )], index = 0 ),
109+ get_new_view (title = "Pick image and recovery" , content = [Row (
110+ [
111+ ElevatedButton (
112+ "Pick image file" ,
113+ icon = icons .UPLOAD_FILE ,
114+ on_click = lambda _ : pick_image_dialog .pick_files (
115+ allow_multiple = False
116+ ),
117+ ),
118+ selected_image ,
119+ ]), Row (
120+ [
121+ ElevatedButton (
122+ "Pick recovery file" ,
123+ icon = icons .UPLOAD_FILE ,
124+ on_click = lambda _ : pick_recovery_dialog .pick_files (
125+ allow_multiple = False
126+ ),
127+ ),
128+ selected_recovery ,
129+ ]
130+
131+ ), confirm_button ("Done?" )], index = 1 ),
132+ get_new_view (title = "Unlock the bootloader" , content = [confirm_button ("Turn on developer options and OEM Unlock on your phone." )], index = 2 ),
133+ get_new_view (title = "Boot into recovery" , content = [confirm_button ("Turn on your device and wait until its fully booted." )], index = 3 ),
134+ get_new_view (title = "Boot into recovery" , content = [call_button ("Reboot into bootloader" , command = "adb reboot download" )], index = 4 ),
135+ get_new_view (title = "Boot into recovery" , content = [call_button ("Flash custom recovery" , command = "heimdall flash --no-reboot --RECOVERY recovery" )], index = 5 ),
136+ get_new_view (title = "Continue somehow" , content = [confirm_button ("Turn on your device and wait until its fully booted." )], index = 6 ),
133137 ]
134138
135139 page .views .append (views [0 ])
0 commit comments