3939from widgets import get_title , confirm_button
4040from utils import (
4141 get_download_link ,
42- image_recovery_works_with_device ,
42+ image_works_with_device ,
43+ recovery_works_with_device
4344)
4445
4546
@@ -58,25 +59,25 @@ def build(self):
5859 modal = True ,
5960 title = Text ("What is an OS image and recovery and why do I need it?" ),
6061 content = Markdown (
61- """
62- ## OS image or ROM
63- An operating system (OS) is system software that manages computer hardware, software resources, and provides common services for computer programs.
62+ """## OS image or ROM
63+ An operating system (OS) is system software that manages computer hardware,
64+ software resources, and provides common services for computer programs.
6465Popular, custom operating systems for mobile devices based on Android are
6566- [LineageOS](https://lineageos.org/)
6667- [/e/OS](https://e.foundation/e-os/) or
6768- [LineageOS for microG](https://lineage.microg.org/)
6869- and many others.
6970
70- Often, the related OS images are called 'ROM'. 'ROM' stands for *R*ead-*o*nly *m*emory, which is a type of non-volatile memory used in computers
71- for storing software that is rarely changed during the life of the system, also known as firmware.
71+ Often, the related OS images are called 'ROM'. 'ROM' stands for *R*ead-*o*nly *m*emory,
72+ which is a type of non-volatile memory used in computers for storing software that is
73+ rarely changed during the life of the system, also known as firmware.
7274
7375# Recovery Image
7476A custom recovery is used for installing custom software on your device.
7577This custom software can include smaller modifications like rooting your device or even
7678replacing the firmware of the device with a completely custom ROM. .
7779
78- OpenAndroidInstaller works with the [TWRP recovery project](https://twrp.me/about/).
79- """ ,
80+ OpenAndroidInstaller works with the [TWRP recovery project](https://twrp.me/about/).""" ,
8081 on_tap_link = lambda e : self .page .launch_url (e .data ),
8182 ),
8283 actions = [
@@ -220,6 +221,7 @@ def close_developer_options_dlg(self, e):
220221
221222 def pick_image_result (self , e : FilePickerResultEvent ):
222223 path = ", " .join (map (lambda f : f .name , e .files )) if e .files else "Cancelled!"
224+ # update the textfield with the name of the file
223225 self .selected_image .value = (
224226 self .selected_image .value .split (":" )[0 ] + f": { path } "
225227 )
@@ -229,10 +231,18 @@ def pick_image_result(self, e: FilePickerResultEvent):
229231 logger .info (f"Selected image from { self .image_path } " )
230232 else :
231233 logger .info ("No image selected." )
234+ # check if the image works with the device and show the filename in different colors accordingly
235+ device_code = self .state .config .metadata .get ("devicecode" )
236+ if image_works_with_device (device_code = device_code , image_path = self .state .image_path ):
237+ self .selected_image .color = colors .GREEN
238+ else :
239+ self .selected_image .color = colors .RED
240+ # update
232241 self .selected_image .update ()
233242
234243 def pick_recovery_result (self , e : FilePickerResultEvent ):
235244 path = ", " .join (map (lambda f : f .name , e .files )) if e .files else "Cancelled!"
245+ # update the textfield with the name of the file
236246 self .selected_recovery .value = (
237247 self .selected_recovery .value .split (":" )[0 ] + f": { path } "
238248 )
@@ -242,17 +252,23 @@ def pick_recovery_result(self, e: FilePickerResultEvent):
242252 logger .info (f"Selected recovery from { self .recovery_path } " )
243253 else :
244254 logger .info ("No image selected." )
255+ # check if the recovery works with the device and show the filename in different colors accordingly
256+ device_code = self .state .config .metadata .get ("devicecode" )
257+ if recovery_works_with_device (device_code = device_code , recovery_path = self .state .recovery_path ):
258+ self .selected_recovery .color = colors .GREEN
259+ else :
260+ self .selected_recovery .color = colors .RED
261+ # update
245262 self .selected_recovery .update ()
246263
247264 def enable_button_if_ready (self , e ):
248265 """Enable the confirm button if both files have been selected."""
249266 if (".zip" in self .selected_image .value ) and (
250267 ".img" in self .selected_recovery .value
251268 ):
252- if not image_recovery_works_with_device (
253- device_code = self .state .config .metadata .get ("devicecode" ),
254- image_path = self .state .image_path ,
255- recovery_path = self .state .recovery_path ,
269+ device_code = self .state .config .metadata .get ("devicecode" )
270+ if not (image_works_with_device (device_code = device_code , image_path = self .state .image_path )
271+ and recovery_works_with_device (device_code = device_code , recovery_path = self .state .recovery_path )
256272 ):
257273 # if image and recovery work for device allow to move on, otherwise display message
258274 logger .error (
@@ -261,7 +277,7 @@ def enable_button_if_ready(self, e):
261277 self .info_field .controls = [
262278 Text (
263279 "Image and/or recovery don't work with the device. Make sure you use a TWRP-based recovery." ,
264- color = colors .RED ,
280+ color = colors .RED , weight = "bold" ,
265281 )
266282 ]
267283 self .right_view .update ()
0 commit comments