diff --git a/.gitignore b/.gitignore index 781d9ca4..ca34cae9 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ Eel.egg-info *.swp venv/ .tox +.vscode \ No newline at end of file diff --git a/eel/edge.py b/eel/edge.py index 7f2dab1e..15d4ab7f 100644 --- a/eel/edge.py +++ b/eel/edge.py @@ -1,20 +1,48 @@ -import platform +import os import subprocess as sps import sys from typing import List from eel.types import OptionsDictT -name: str = 'Edge' +name: str = "Edge" -def run(_path: str, options: OptionsDictT, start_urls: List[str]) -> None: - cmd = 'start microsoft-edge:{}'.format(start_urls[0]) - sps.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr, stdin=sps.PIPE, shell=True) +def run(path: str, options: OptionsDictT, start_urls: List[str]) -> None: + if path != "edge_legacy": + 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) + else: + args = options["cmdline_args"] + start_urls + sps.Popen([path, "--new-window"] + args, stdout=sps.PIPE, stderr=sps.PIPE, stdin=sps.PIPE) + else: + cmd = "start microsoft-edge:{}".format(start_urls[0]) + sps.Popen(cmd, stdout=sps.PIPE, stderr=sps.PIPE, stdin=sps.PIPE, shell=True) def find_path() -> bool: - if platform.system() == 'Windows': - return True + if sys.platform in ["win32", "win64"]: + return _find_edge_win() + else: + return None - return False + +def _find_edge_win(): + import winreg as reg + + reg_path = r"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\msedge.exe" + + for install_type in reg.HKEY_CURRENT_USER, reg.HKEY_LOCAL_MACHINE: + try: + reg_key = reg.OpenKey(install_type, reg_path, 0, reg.KEY_READ) + edge_path = reg.QueryValue(reg_key, None) + reg_key.Close() + if not os.path.isfile(edge_path): + continue + except WindowsError: + edge_path = "edge_legacy" + else: + break + + return edge_path