@@ -337,6 +337,7 @@ def _open_flet_view(page_url):
337337
338338 if is_windows ():
339339 flet_exe = "flet.exe"
340+ temp_flet_dir = Path (tempfile .gettempdir ()).joinpath (f"flet-{ version .version } " )
340341
341342 # check if flet_view.exe exists in "bin" directory (user mode)
342343 p = Path (__file__ ).parent .joinpath ("bin" , "flet" , flet_exe )
@@ -349,7 +350,14 @@ def _open_flet_view(page_url):
349350 if flet_path :
350351 logging .info (f"Flet View found in PATH: { flet_path } " )
351352 else :
352- flet_path = _download_flet_view_windows ()
353+ if not temp_flet_dir .exists ():
354+ zip_file = _download_flet_client ("flet-windows.zip" )
355+
356+ logging .info (f"Extracting flet.exe from archive to { temp_flet_dir } " )
357+ temp_flet_dir .mkdir (parents = True , exist_ok = True )
358+ with zipfile .ZipFile (zip_file , "r" ) as zip_arch :
359+ zip_arch .extractall (str (temp_flet_dir ))
360+ app_path = temp_flet_dir .joinpath ("flet" , flet_exe )
353361 args = [flet_path , page_url ]
354362 elif is_macos ():
355363 # build version-specific path to Flet.app
@@ -358,16 +366,17 @@ def _open_flet_view(page_url):
358366 # check if flet_view.app exists in a temp directory
359367 if not temp_flet_dir .exists ():
360368 # check if flet.tar.gz exists
361- tar_file = Path (__file__ ).parent .joinpath ("bin" , "flet.tar.gz" )
369+ gz_filename = "flet-macos-amd64.tar.gz"
370+ tar_file = Path (__file__ ).parent .joinpath ("bin" , gz_filename )
362371 if not tar_file .exists ():
363- tar_file = _download_flet_view_macos ( )
372+ tar_file = _download_flet_client ( gz_filename )
364373
365374 logging .info (f"Extracting Flet.app from archive to { temp_flet_dir } " )
366375 temp_flet_dir .mkdir (parents = True , exist_ok = True )
367376 with tarfile .open (str (tar_file ), "r:gz" ) as tar_arch :
368377 tar_arch .extractall (str (temp_flet_dir ))
369378 else :
370- logging .info (f"Flet View found in PATH : { temp_flet_dir } " )
379+ logging .info (f"Flet View found in: { temp_flet_dir } " )
371380
372381 app_path = temp_flet_dir .joinpath ("Flet.app" )
373382 args = ["open" , str (app_path ), "-W" , "--args" , page_url ]
@@ -378,16 +387,17 @@ def _open_flet_view(page_url):
378387 # check if flet_view.app exists in a temp directory
379388 if not temp_flet_dir .exists ():
380389 # check if flet.tar.gz exists
381- tar_file = Path (__file__ ).parent .joinpath ("bin" , "flet.tar.gz" )
390+ gz_filename = f"flet-linux-{ get_arch ()} .tar.gz"
391+ tar_file = Path (__file__ ).parent .joinpath ("bin" , gz_filename )
382392 if not tar_file .exists ():
383- tar_file = _download_flet_view_linux ( )
393+ tar_file = _download_flet_client ( gz_filename )
384394
385395 logging .info (f"Extracting Flet from archive to { temp_flet_dir } " )
386396 temp_flet_dir .mkdir (parents = True , exist_ok = True )
387397 with tarfile .open (str (tar_file ), "r:gz" ) as tar_arch :
388398 tar_arch .extractall (str (temp_flet_dir ))
389399 else :
390- logging .info (f"Flet View found in PATH : { temp_flet_dir } " )
400+ logging .info (f"Flet View found in: { temp_flet_dir } " )
391401
392402 app_path = temp_flet_dir .joinpath ("flet" , "flet" )
393403 args = [str (app_path ), page_url ]
@@ -441,52 +451,11 @@ def _download_fletd():
441451 return str (temp_fletd_dir .joinpath (flet_exe ))
442452
443453
444- def _download_flet_view_windows ():
445- ver = version .version
446-
447- # build version-specific path to Flet
448- temp_flet_dir = Path (tempfile .gettempdir ()).joinpath (f"flet-{ ver } " )
449-
450- if not temp_flet_dir .exists ():
451- print (f"Downloading Flet v{ ver } to { temp_flet_dir } " )
452- temp_flet_dir .mkdir (parents = True , exist_ok = True )
453- file_name = "flet.zip"
454- flet_url = (
455- f"https://github.com/flet-dev/flet/releases/download/v{ ver } /{ file_name } "
456- )
457-
458- temp_arch = Path (tempfile .gettempdir ()).joinpath (file_name )
459- try :
460- urllib .request .urlretrieve (flet_url , temp_arch )
461- with zipfile .ZipFile (temp_arch , "r" ) as zip_arch :
462- zip_arch .extractall (str (temp_flet_dir ))
463- finally :
464- os .remove (temp_arch )
465- else :
466- logging .info (f"Flet v{ version .version } is already installed in { temp_flet_dir } " )
467- return str (temp_flet_dir .joinpath ("flet" , "flet.exe" ))
468-
469-
470- def _download_flet_view_macos ():
471- ver = version .version
472-
473- file_name = "flet.app.tar.gz"
474- temp_arch = Path (tempfile .gettempdir ()).joinpath (file_name )
475- print (f"Downloading Flet v{ ver } to { temp_arch } " )
476- flet_url = f"https://github.com/flet-dev/flet/releases/download/v{ ver } /{ file_name } "
477-
478- urllib .request .urlretrieve (flet_url , temp_arch )
479- return str (temp_arch )
480-
481-
482- def _download_flet_view_linux ():
454+ def _download_flet_client (file_name ):
483455 ver = version .version
484-
485- file_name = "flet.tar.gz"
486456 temp_arch = Path (tempfile .gettempdir ()).joinpath (file_name )
487457 print (f"Downloading Flet v{ ver } to { temp_arch } " )
488458 flet_url = f"https://github.com/flet-dev/flet/releases/download/v{ ver } /{ file_name } "
489-
490459 urllib .request .urlretrieve (flet_url , temp_arch )
491460 return str (temp_arch )
492461
0 commit comments