()
| 1157 | |
| 1158 | |
| 1159 | def win_get_default_browser(): |
| 1160 | # Look in the registry for the default system browser on Windows without relying on |
| 1161 | # 'start %1' since that method has an issue, see comment below. |
| 1162 | try: |
| 1163 | with winreg.OpenKey(winreg.HKEY_CURRENT_USER, r"Software\Classes\http\shell\open\command") as key: |
| 1164 | cmd = winreg.QueryValue(key, None) |
| 1165 | if cmd: |
| 1166 | parts = shlex.split(cmd) |
| 1167 | if len(parts): |
| 1168 | return [parts[0]] |
| 1169 | except OSError: |
| 1170 | logv("Unable to find default browser key in Windows registry. Trying fallback.") |
| 1171 | |
| 1172 | # Fall back to 'start "" %1', which we have to treat as if user passed --serve-forever, since |
| 1173 | # for some reason, we are not able to detect when the browser closes when this is passed. |
| 1174 | # |
| 1175 | # If the first argument to 'start' is quoted, then 'start' will create a new cmd.exe window with |
| 1176 | # that quoted string as the title. If the URL contained spaces, it would be quoted by subprocess, |
| 1177 | # and if we did 'start %1', it would create a new cmd.exe window with the URL as title instead of |
| 1178 | # actually launching the browser. Therefore, we must pass a dummy quoted first argument for start |
| 1179 | # to interpret as the title. For this purpose, we use the empty string, which will be quoted |
| 1180 | # as "". See #9253 for details. |
| 1181 | return ['cmd', '/C', 'start', ''] |
| 1182 | |
| 1183 | |
| 1184 | def find_browser(name): |
no test coverage detected