@@ -251,33 +251,38 @@ def build(self):
251251 ),
252252 self .selected_image ,
253253 Divider (),
254- Text ("Select a TWRP recovery image:" , style = "titleSmall" ),
255- Markdown (
256- f"""
254+ ]
255+ )
256+ if self .state .flash_recovery :
257+ self .right_view .controls .extend (
258+ [
259+ Text ("Select a TWRP recovery image:" , style = "titleSmall" ),
260+ Markdown (
261+ f"""
257262The recovery image should look something like `twrp-3.7.0_12-0-{ self .state .config .device_code } .img`.
258263
259264**Note:** This tool **only supports TWRP recoveries**.""" ,
260- extension_set = "gitHubFlavored" ,
261- ),
262- Row (
263- [
264- FilledButton (
265- "Pick TWRP recovery file" ,
266- icon = icons .UPLOAD_FILE ,
267- on_click = lambda _ : self .pick_recovery_dialog .pick_files (
268- allow_multiple = False ,
269- file_type = "custom" ,
270- allowed_extensions = ["img" ],
265+ extension_set = "gitHubFlavored" ,
266+ ),
267+ Row (
268+ [
269+ FilledButton (
270+ "Pick TWRP recovery file" ,
271+ icon = icons .UPLOAD_FILE ,
272+ on_click = lambda _ : self .pick_recovery_dialog .pick_files (
273+ allow_multiple = False ,
274+ file_type = "custom" ,
275+ allowed_extensions = ["img" ],
276+ ),
277+ expand = True ,
271278 ),
272- expand = True ,
273- ),
274- ]
275- ),
276- self .selected_recovery ,
277- Divider (),
278- self .additional_image_selection ,
279- ]
280- )
279+ ]
280+ ),
281+ self .selected_recovery ,
282+ Divider (),
283+ self .additional_image_selection ,
284+ ]
285+ )
281286
282287 # attach the bottom buttons
283288 self .right_view .controls .extend (
@@ -296,11 +301,11 @@ def get_notes(self) -> str:
296301 notes = []
297302
298303 brand = self .state .config .metadata .get ("brand" , "" )
299- if brand in "xiaomi" :
304+ if brand == "xiaomi" :
300305 notes .append (
301306 "- If something goes wrong, you can reinstall MiUI here:\n <https://xiaomifirmwareupdater.com/>\n "
302307 )
303- elif brand in "poco" :
308+ elif brand == "poco" :
304309 notes .append (
305310 f"- If something goes wrong, you can reinstall MiUI here:\n <https://xiaomifirmwareupdater.com/miui/{ self .state .config .device_code } />\n "
306311 )
@@ -498,14 +503,15 @@ def pick_image_result(self, e: FilePickerResultEvent):
498503 else :
499504 self .selected_image .color = colors .RED
500505 # if the image works and the sdk level is 33 or higher, show the additional image selection
501- if (
502- self .selected_image .color == colors .GREEN
503- and image_sdk_level (self .state .image_path ) >= 33
504- ):
505- self .toggle_additional_image_selection ()
506- else :
507- self .additional_image_selection .controls = []
508- self .additional_image_selection .update ()
506+ if self .state .flash_recovery :
507+ if (
508+ self .selected_image .color == colors .GREEN
509+ and image_sdk_level (self .state .image_path ) >= 33
510+ ):
511+ self .toggle_additional_image_selection ()
512+ else :
513+ self .additional_image_selection .controls = []
514+ self .additional_image_selection .update ()
509515 # update
510516 self .selected_image .update ()
511517
@@ -523,9 +529,9 @@ def pick_recovery_result(self, e: FilePickerResultEvent):
523529 logger .info ("No image selected." )
524530 # check if the recovery works with the device and show the filename in different colors accordingly
525531 if e .files :
526- device_code = self .state .config .device_code
527532 if recovery_works_with_device (
528- device_code = device_code , recovery_path = self .state .recovery_path
533+ supported_device_codes = self .state .config .supported_device_codes ,
534+ recovery_path = self .state .recovery_path ,
529535 ):
530536 self .selected_recovery .color = colors .GREEN
531537 else :
@@ -642,5 +648,31 @@ def enable_button_if_ready(self, e):
642648 self .info_field .controls = []
643649 self .confirm_button .disabled = False
644650 self .right_view .update ()
651+ elif (".zip" in self .selected_image .value ) and (not self .state .flash_recovery ):
652+ if not (
653+ image_works_with_device (
654+ supported_device_codes = self .state .config .supported_device_codes ,
655+ image_path = self .state .image_path ,
656+ )
657+ ):
658+ # if image works for device allow to move on, otherwise display message
659+ logger .error (
660+ "Image doesn't work with the device. Please select a different one."
661+ )
662+ self .info_field .controls = [
663+ Text (
664+ "Image doesn't work with the device." ,
665+ color = colors .RED ,
666+ weight = "bold" ,
667+ )
668+ ]
669+ self .confirm_button .disabled = True
670+ self .right_view .update ()
671+ return
672+
673+ logger .info ("Image works with the device. You can continue." )
674+ self .info_field .controls = []
675+ self .confirm_button .disabled = False
676+ self .right_view .update ()
645677 else :
646678 self .confirm_button .disabled = True
0 commit comments