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/__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) 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] 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')