From 1aa07064d396705f612b1cc3bae082900fac7e60 Mon Sep 17 00:00:00 2001 From: Youness Alaoui Date: Mon, 3 Aug 2020 21:13:10 -0400 Subject: [PATCH 1/3] Use _MEIPASS only for pyinstaller frozen apps cx_freeze frozen apps don't define/use _MEIPASS Fixes #371 --- eel/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/eel/__init__.py b/eel/__init__.py index 2f28ce89..059dc7f9 100644 --- a/eel/__init__.py +++ b/eel/__init__.py @@ -294,9 +294,11 @@ def _process_message(message, ws): def _get_real_path(path): - if getattr(sys, 'frozen', False): + if getattr(sys, 'frozen', False) and hasattr(sys, "_MEIPASS"): + # Pyinstaller uses _MEIPASS for frozen paths return os.path.join(sys._MEIPASS, path) else: + # Unfrozen app or cx_freeze can use the path directly return os.path.abspath(path) From 635e799a8b86ba5fa15b904e09935bced8550101 Mon Sep 17 00:00:00 2001 From: Youness Alaoui Date: Mon, 3 Aug 2020 21:16:49 -0400 Subject: [PATCH 2/3] Avoid crash with trying to join path for non existing electron If electron isn't found on windows, the os.path.join will complain about passing NoneType to it Also, return the original electron found if if the path that was found doesn't have a relative ../node_modules/etc.. file This allows bundling of electron.exe directly in an app --- eel/electron.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/eel/electron.py b/eel/electron.py index 7a443025..80fc3300 100644 --- a/eel/electron.py +++ b/eel/electron.py @@ -15,7 +15,13 @@ def find_path(): if sys.platform in ['win32', 'win64']: # It doesn't work well passing the .bat file to Popen, so we get the actual .exe bat_path = wch.which('electron') - return os.path.join(bat_path, r'..\node_modules\electron\dist\electron.exe') + if bat_path is not None: + exe_path = os.path.join(bat_path, r'..\node_modules\electron\dist\electron.exe') + if os.path.exists(exe_path): + return exe_path + else: + return bat_path + return None elif sys.platform in ['darwin', 'linux']: # This should work find... return wch.which('electron') From 366980e05ed1a7f1ad85d73cfda03751c62e54a0 Mon Sep 17 00:00:00 2001 From: Youness Alaoui Date: Mon, 3 Aug 2020 22:08:43 -0400 Subject: [PATCH 3/3] Add custom_callback option This allows us to specify the custom command to launch and passing any argument to it, including the URL of the server that was just created. Without this option, there is no way to run a custom command while also giving it the actual url to launch. Hardcoding the url in cmdline_args being unfeasable if using port=0 for example. --- README.md | 1 + eel/browsers.py | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a445cc84..652c13ec 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,7 @@ As of Eel v0.12.0, the following options are available to `start()`: - **block**, a bool saying whether or not the call to `start()` should block the calling thread. *Default: `True`* - **jinja_templates**, a string specifying a folder to use for Jinja2 templates, e.g. `my_templates`. *Default: `None`* - **cmdline_args**, a list of strings to pass to the command to start the browser. For example, we might add extra flags for Chrome; ```eel.start('main.html', mode='chrome-app', port=8080, cmdline_args=['--start-fullscreen', '--browser-startup-dialog'])```. *Default: `[]`* + - **custom_callback**, a callback function to be called when using `"custom"` mode which would be responsible for calling `subprocess.Popen` for example. It receives an array of command line arguments and an array of start urls in argument: `custom_callback(args, urls)`. If not set, the `cmdline_args` option is launched as the command to execute. - **size**, a tuple of ints specifying the (width, height) of the main window in pixels *Default: `None`* - **position**, a tuple of ints specifying the (left, top) of the main window in pixels *Default: `None`* - **geometry**, a dictionary specifying the size and position for all windows. The keys should be the relative path of the page, and the values should be a dictionary of the form `{'size': (200, 100), 'position': (300, 50)}`. *Default: {}* diff --git a/eel/browsers.py b/eel/browsers.py index 79639141..872e67db 100644 --- a/eel/browsers.py +++ b/eel/browsers.py @@ -48,8 +48,11 @@ def open(start_pages, options): pass elif mode == 'custom': # Just run whatever command the user provided - sps.Popen(options['cmdline_args'], - stdout=sps.PIPE, stderr=sps.PIPE, stdin=sps.PIPE) + if options["custom_callback"]: + options["custom_callback"](options['cmdline_args'], start_urls) + else: + sps.Popen(options['cmdline_args'], + stdout=sps.PIPE, stderr=sps.PIPE, stdin=sps.PIPE) elif mode in _browser_modules: # Run with a specific browser browser_module = _browser_modules[mode]