1313import yaml
1414from flet .cli .commands .base import BaseCommand
1515from flet_core .utils import random_string , slugify
16- from flet_runtime .utils import copy_tree
16+ from flet_runtime .utils import copy_tree , is_windows
1717from rich import print
1818
19+ if is_windows ():
20+ from ctypes import windll
21+
1922PYODIDE_ROOT_URL = "https://cdn.jsdelivr.net/pyodide/v0.24.1/full"
2023
2124
@@ -509,11 +512,8 @@ def fallback_image(yaml_path: str, images: list):
509512
510513 # generate icons
511514 print ("Generating app icons..." , end = "" )
512- icons_result = subprocess .run (
513- [dart_exe , "run" , "flutter_launcher_icons" ],
514- cwd = str (self .flutter_dir ),
515- capture_output = self .verbose < 2 ,
516- text = True ,
515+ icons_result = self .run (
516+ [dart_exe , "run" , "flutter_launcher_icons" ], cwd = str (self .flutter_dir )
517517 )
518518 if icons_result .returncode != 0 :
519519 if icons_result .stdout :
@@ -527,11 +527,9 @@ def fallback_image(yaml_path: str, images: list):
527527 # generate splash
528528 if target_platform in ["web" , "ipa" , "apk" , "aab" ]:
529529 print ("Generating splash screens..." , end = "" )
530- splash_result = subprocess .run (
530+ splash_result = self .run (
531531 [dart_exe , "run" , "flutter_native_splash:create" ],
532532 cwd = str (self .flutter_dir ),
533- capture_output = self .verbose < 2 ,
534- text = True ,
535533 )
536534 if splash_result .returncode != 0 :
537535 if splash_result .stdout :
@@ -586,12 +584,7 @@ def fallback_image(yaml_path: str, images: list):
586584 ]
587585 )
588586
589- package_result = subprocess .run (
590- package_args ,
591- cwd = str (self .flutter_dir ),
592- capture_output = self .verbose < 2 ,
593- text = True ,
594- )
587+ package_result = self .run (package_args , cwd = str (self .flutter_dir ))
595588
596589 if package_result .returncode != 0 :
597590 if package_result .stdout :
@@ -629,12 +622,7 @@ def fallback_image(yaml_path: str, images: list):
629622 if self .verbose > 0 :
630623 print (build_args )
631624
632- build_result = subprocess .run (
633- build_args ,
634- cwd = str (self .flutter_dir ),
635- capture_output = self .verbose < 2 ,
636- text = True ,
637- )
625+ build_result = self .run (build_args , cwd = str (self .flutter_dir ))
638626
639627 if build_result .returncode != 0 :
640628 if build_result .stdout :
@@ -703,6 +691,27 @@ def copy_icon_image(self, src_path: Path, dest_path: Path, image_name: str):
703691 return Path (images [0 ]).name
704692 return None
705693
694+ def run (self , args , cwd ):
695+ if is_windows ():
696+ # Source: https://stackoverflow.com/a/77374899/1435891
697+ # Save the current console output code page and switch to 65001 (UTF-8)
698+ previousCp = windll .kernel32 .GetConsoleOutputCP ()
699+ windll .kernel32 .SetConsoleOutputCP (65001 )
700+
701+ r = subprocess .run (
702+ args ,
703+ cwd = cwd ,
704+ capture_output = self .verbose < 2 ,
705+ text = True ,
706+ encoding = "utf8" ,
707+ )
708+
709+ if is_windows ():
710+ # Restore the previous output console code page.
711+ windll .kernel32 .SetConsoleOutputCP (previousCp )
712+
713+ return r
714+
706715 def cleanup (self , exit_code : int ):
707716 if self .verbose > 0 :
708717 print (f"Deleting Flutter bootstrap directory { self .flutter_dir } " )
0 commit comments