Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to getting Electron to work #373

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}*
Expand Down
4 changes: 3 additions & 1 deletion eel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
7 changes: 5 additions & 2 deletions eel/browsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 7 additions & 1 deletion eel/electron.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down