Skip to content

Commit

Permalink
🐛 Fix Safari executable cannot open a URL directly (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
roniemartinez authored Apr 26, 2022
1 parent 9d03813 commit 04fa25e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
6 changes: 5 additions & 1 deletion browsers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ def _launch(browser: str, path: str, args: Sequence[str], url: str = None) -> su
elif url is not None:
url_arg.append(url)

if sys.platform != "linux":
if browser == "safari":
if args:
logger.warning("Safari does not accept command line arguments. %s will be ignored.", str(args))
command = ["open", "--wait-apps", "--new", "--fresh", "-a", path, *url_arg]
elif sys.platform != "linux":
command = [path, *url_arg, *args]
else:
command = [*shlex.split(path), *url_arg, *args]
Expand Down
4 changes: 3 additions & 1 deletion browsers/osx.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ def browsers() -> Iterator[Tuple[str, Dict]]: # type: ignore[return]
executable = os.path.join(path, "Contents/MacOS", executable_name)
display_name = plist.get("CFBundleDisplayName") or plist.get("CFBundleName", browser)
version = plist[version_string]
yield browser, dict(path=executable, display_name=display_name, version=version)
yield browser, dict(
path=executable if browser != "safari" else path, display_name=display_name, version=version
)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pybrowsers"
version = "0.3.0"
version = "0.3.1"
repository = "https://github.com/roniemartinez/browsers"
description = "Python library for detecting and launching browsers"
authors = ["Ronie Martinez <[email protected]>"]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_get_available_browsers(browser: str) -> None:
"safari",
{
"display_name": "Safari",
"path": "/Applications/Safari.app/Contents/MacOS/Safari",
"path": "/Applications/Safari.app",
"version": ANY,
},
marks=pytest.mark.skipif(sys.platform != "darwin", reason="osx-only"),
Expand Down

0 comments on commit 04fa25e

Please sign in to comment.