diff --git a/eel/__init__.py b/eel/__init__.py index b911e77e..d1d8203e 100644 --- a/eel/__init__.py +++ b/eel/__init__.py @@ -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) @@ -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): @@ -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(): diff --git a/eel/browsers.py b/eel/browsers.py index 79639141..fe05f092 100644 --- a/eel/browsers.py +++ b/eel/browsers.py @@ -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] @@ -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): diff --git a/eel/chrome.py b/eel/chrome.py index 569b3459..ffe93200 100644 --- a/eel/chrome.py +++ b/eel/chrome.py @@ -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(): diff --git a/eel/edge.py b/eel/edge.py index eebe805e..8a8a82b1 100644 --- a/eel/edge.py +++ b/eel/edge.py @@ -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(): diff --git a/eel/electron.py b/eel/electron.py index 7a443025..64340935 100644 --- a/eel/electron.py +++ b/eel/electron.py @@ -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']: diff --git a/examples/01 - hello_world-Edge/hello.py b/examples/01 - hello_world-Edge/hello.py index 965b9d5b..117557ab 100644 --- a/examples/01 - hello_world-Edge/hello.py +++ b/examples/01 - hello_world-Edge/hello.py @@ -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: diff --git a/examples/07 - CreateReactApp/eel_CRA.py b/examples/07 - CreateReactApp/eel_CRA.py index 2a5240fd..379a9a83 100644 --- a/examples/07 - CreateReactApp/eel_CRA.py +++ b/examples/07 - CreateReactApp/eel_CRA.py @@ -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'])