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

tracking of browser process / waiting for browser close / update start args / couple of example fixes #261

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
21 changes: 20 additions & 1 deletion eel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
_js_functions = []
_mock_queue = []
_mock_queue_done = set()
_spawned_process_list = []

# The maximum time (in milliseconds) that Python will try to retrieve a return value for functions executing in JS
# Can be overridden through `eel.init` with the kwarg `js_result_timeout` (default: 10000)
Expand Down Expand Up @@ -165,7 +166,8 @@ def run_lambda():


def show(*start_urls):
brw.open(start_urls, _start_args)
global _spawned_process_list
_spawned_process_list = brw.open(start_urls, _start_args)


def sleep(seconds):
Expand All @@ -175,6 +177,23 @@ def sleep(seconds):
def spawn(function, *args, **kwargs):
gvt.spawn(function, *args, **kwargs)


def get_browser_process():
"""Get a list of all browser process's opened via Popen"""
return _spawned_process_list


def wait_browser_close():
"""Wait for all browser process's to close"""
for item in _spawned_process_list:
item.wait()


def update_startargs(**kwargs):
"""Update the start args directly, where we want to call show directly"""
_start_args.update(kwargs)


# Bottle Routes

def _eel():
Expand Down
11 changes: 7 additions & 4 deletions eel/browsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,17 @@ def _build_urls(start_pages, options):
def open(start_pages, options):
# Build full URLs for starting pages (including host and port)
start_urls = _build_urls(start_pages, options)

proclist = []

mode = options.get('mode')
if mode in [None, False]:
# Don't open a browser
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)
procitem = sps.Popen(options['cmdline_args'],
stdout=sps.PIPE, stderr=sps.PIPE, stdin=sps.PIPE)
proclist.append(procitem)
elif mode in _browser_modules:
# Run with a specific browser
browser_module = _browser_modules[mode]
Expand All @@ -60,13 +62,14 @@ def open(start_pages, options):
_browser_paths[mode] = path

if path is not None:
browser_module.run(path, options, start_urls)
proclist = browser_module.run(path, options, start_urls)
else:
raise EnvironmentError("Can't find %s installation" % browser_module.name)
else:
# Fall back to system default browser
for url in start_urls:
wbr.open(url)
return proclist


def set_path(browser_name, path):
Expand Down
12 changes: 8 additions & 4 deletions eel/chrome.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@
name = 'Google Chrome/Chromium'

def run(path, options, start_urls):
proclist = []
if options['app_mode']:
for url in start_urls:
sps.Popen([path, '--app=%s' % url] +
options['cmdline_args'],
stdout=sps.PIPE, stderr=sps.PIPE, stdin=sps.PIPE)
procitem = sps.Popen([path, '--app=%s' % url] +
options['cmdline_args'],
stdout=sps.PIPE, stderr=sps.PIPE, stdin=sps.PIPE)
proclist.append(procitem)
else:
args = options['cmdline_args'] + start_urls
sps.Popen([path, '--new-window'] + args,
procitem = sps.Popen([path, '--new-window'] + args,
stdout=sps.PIPE, stderr=sys.stderr, stdin=sps.PIPE)
proclist.append(procitem)
return proclist


def find_path():
Expand Down
5 changes: 4 additions & 1 deletion eel/edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@


def run(_path, options, start_urls):
proclist = []
cmd = 'start microsoft-edge:{}'.format(start_urls[0])
sps.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr, stdin=sps.PIPE, shell=True)
procitem = sps.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr, stdin=sps.PIPE, shell=True)
proclist.append(procitem)
return proclist


def find_path():
Expand Down
6 changes: 4 additions & 2 deletions eel/electron.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
name = 'Electron'

def run(path, options, start_urls):
proclist = []
cmd = [path] + options['cmdline_args']
cmd += ['.', ';'.join(start_urls)]
sps.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr, stdin=sps.PIPE)

procitem = sps.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr, stdin=sps.PIPE)
proclist.append(procitem)
return proclist

def find_path():
if sys.platform in ['win32', 'win64']:
Expand Down
2 changes: 1 addition & 1 deletion examples/01 - hello_world-Edge/hello.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def say_hello_py(x):

# # Launching Edge can also be gracefully handled as a fall back
# try:
# eel.start('hello.html', mode='chrome-app', size=(300, 200))
# eel.start('hello.html', mode='chrome', size=(300, 200))
# except EnvironmentError:
# # If Chrome isn't found, fallback to Microsoft Edge on Win10 or greater
# if sys.platform in ['win32', 'win64'] and int(platform.release()) >= 10:
Expand Down
2 changes: 1 addition & 1 deletion examples/07 - CreateReactApp/eel_CRA.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def start_eel(develop):
page = {'port': 3000}
else:
directory = 'build'
app = 'chrome-app'
app = 'chrome'
page = 'index.html'

eel.init(directory, ['.tsx', '.ts', '.jsx', '.js', '.html'])
Expand Down