diff --git a/sdk/python/flet/__pyinstaller/__init__.py b/sdk/python/flet/__pyinstaller/__init__.py new file mode 100644 index 000000000..1c52aadf4 --- /dev/null +++ b/sdk/python/flet/__pyinstaller/__init__.py @@ -0,0 +1,5 @@ +import os + + +def get_hook_dirs(): + return [os.path.dirname(__file__)] diff --git a/sdk/python/flet/__pyinstaller/hook-flet.py b/sdk/python/flet/__pyinstaller/hook-flet.py new file mode 100644 index 000000000..a5925b1ad --- /dev/null +++ b/sdk/python/flet/__pyinstaller/hook-flet.py @@ -0,0 +1,11 @@ +import os + +# package entire "bin" folder +bin_path = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, "bin")) + +# package "bin/fletd" only +if os.getenv("PACKAGE_FLETD_ONLY"): + bin_path = os.path.join(bin_path, "fletd*") + +# binaries = [(bin_path, "flet/bin")] +binaries = [(bin_path, "flet/bin")] diff --git a/sdk/python/flet/__pyinstaller/rthooks.dat b/sdk/python/flet/__pyinstaller/rthooks.dat new file mode 100644 index 000000000..9c1464dee --- /dev/null +++ b/sdk/python/flet/__pyinstaller/rthooks.dat @@ -0,0 +1,5 @@ +{ + 'flet': [ + 'pyi_rth_localhost_fletd.py' + ], +} \ No newline at end of file diff --git a/sdk/python/flet/__pyinstaller/rthooks/pyi_rth_localhost_fletd.py b/sdk/python/flet/__pyinstaller/rthooks/pyi_rth_localhost_fletd.py new file mode 100644 index 000000000..16f673cd8 --- /dev/null +++ b/sdk/python/flet/__pyinstaller/rthooks/pyi_rth_localhost_fletd.py @@ -0,0 +1,6 @@ +import logging +import os + +logging.info("Running PyInstaller runtime hook for Flet...") + +os.environ["FLET_SERVER_IP"] = "localhost" diff --git a/sdk/python/flet/flet.py b/sdk/python/flet/flet.py index b079a55ee..b8237907f 100644 --- a/sdk/python/flet/flet.py +++ b/sdk/python/flet/flet.py @@ -279,6 +279,11 @@ def _start_flet_server(port, attached, assets_dir, web_renderer): log_level_name = logging.getLevelName(log_level).lower() args.extend(["--log-level", log_level_name]) + startupinfo = None + if is_windows(): + startupinfo = subprocess.STARTUPINFO() + startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW + subprocess.Popen( args, env=fletd_env, @@ -286,6 +291,7 @@ def _start_flet_server(port, attached, assets_dir, web_renderer): start_new_session=start_new_session, stdout=subprocess.DEVNULL if log_level >= logging.WARNING else None, stderr=subprocess.DEVNULL if log_level >= logging.WARNING else None, + startupinfo=startupinfo, ) return port diff --git a/sdk/python/pyproject.toml b/sdk/python/pyproject.toml index d6b1b4ecf..c8a97c004 100644 --- a/sdk/python/pyproject.toml +++ b/sdk/python/pyproject.toml @@ -32,8 +32,10 @@ tests = [ "pytest>=6.1.2", ] dev = [ - "pre-commit>=2.17.0", -] + "pre-commit>=2.17.0"] + +[project.entry-points.pyinstaller40] +hook-dirs = "flet.__pyinstaller:get_hook_dirs" [build-system] requires = ["pdm-pep517"] diff --git a/server/config/config.go b/server/config/config.go index b2098a409..fa0d93b89 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -27,6 +27,7 @@ const ( defaultAppURL = "http://localhost:3000" defaultServerPort = 8550 serverPort = "SERVER_PORT" + serverIP = "SERVER_IP" forceSSL = "FORCE_SSL" defaultWebSocketMaxMessageSize = 2097152 // 2 MB wsMaxMessageSize = "WS_MAX_MESSAGE_SIZE" @@ -170,6 +171,10 @@ func ServerPort() int { return viper.GetInt(serverPort) } +func ServerIP() string { + return viper.GetString(serverIP) +} + func MaxWebSocketMessageSize() int { return viper.GetInt(wsMaxMessageSize) } diff --git a/server/server/server.go b/server/server/server.go index 4d7f01baa..16d60c7b5 100644 --- a/server/server/server.go +++ b/server/server/server.go @@ -126,11 +126,12 @@ func Start(ctx context.Context, wg *sync.WaitGroup, serverPort int) { } }) - log.Println("Starting server on port", serverPort) + addr := fmt.Sprintf("%s:%d", config.ServerIP(), serverPort) + log.Println("Starting server on", addr) // Start and run the server srv := &http.Server{ - Addr: fmt.Sprintf(":%d", serverPort), + Addr: addr, Handler: router, }