-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* π Alpha version - π¨ Refactor - β¨ Make url parameter optional * Fix lint * Fix lint for windows
- Loading branch information
1 parent
c49ddea
commit a74ea94
Showing
8 changed files
with
287 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import os | ||
import subprocess | ||
import sys | ||
from typing import Dict, Iterator, Tuple | ||
|
||
LINUX_DESKTOP_ENTRY_LIST = ( | ||
# desktop entry name can be "firefox.desktop" or "firefox_firefox.desktop" | ||
("chrome", ("google-chrome",)), | ||
("chromium", ("chromium", "chromium_chromium")), | ||
("firefox", ("firefox", "firefox_firefox")), | ||
("msedge", ("microsoft-edge",)), | ||
("opera", ("opera_opera",)), | ||
("opera-beta", ("opera-beta_opera-beta",)), | ||
("opera-developer", ("opera-developer_opera-developer",)), | ||
("brave", ("brave-browser", "brave_brave")), | ||
("brave-beta", ("brave-browser-beta",)), | ||
("brave-nightly", ("brave-browser-nightly",)), | ||
) | ||
|
||
# $XDG_DATA_HOME and $XDG_DATA_DIRS are not always set | ||
XDG_DATA_LOCATIONS = ( | ||
"~/.local/share/applications", | ||
"/usr/share/applications", | ||
"/var/lib/snapd/desktop/applications", | ||
) | ||
|
||
|
||
def browsers() -> Iterator[Tuple[str, Dict]]: # type: ignore[return] | ||
if sys.platform == "linux": | ||
from xdg.DesktopEntry import DesktopEntry | ||
|
||
for browser, desktop_entries in LINUX_DESKTOP_ENTRY_LIST: | ||
for application_dir in XDG_DATA_LOCATIONS: | ||
for desktop_entry in desktop_entries: | ||
path = os.path.join(application_dir, f"{desktop_entry}.desktop") | ||
if not os.path.isfile(path): | ||
continue | ||
entry = DesktopEntry(path) | ||
executable_path = entry.getExec() | ||
if executable_path.lower().endswith(" %u"): | ||
executable_path = executable_path[:-3].strip() | ||
# FIXME: --version includes the name for most browsers | ||
version = subprocess.getoutput(f"{executable_path} --version") | ||
info = dict(path=executable_path, display_name=entry.getName(), version=version) | ||
yield browser, info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import os | ||
import plistlib | ||
import subprocess | ||
import sys | ||
from typing import Dict, Iterator, Tuple | ||
|
||
OSX_BROWSER_BUNDLE_LIST = ( | ||
# browser name, bundle ID, version string | ||
("chrome", "com.google.Chrome", "KSVersion"), | ||
("chrome-canary", "com.google.Chrome.canary", "KSVersion"), | ||
("chromium", "org.chromium.Chromium", "CFBundleShortVersionString"), | ||
("firefox", "org.mozilla.firefox", "CFBundleShortVersionString"), | ||
("firefox-developer", "org.mozilla.firefoxdeveloperedition", "CFBundleShortVersionString"), | ||
("firefox-nightly", "org.mozilla.nightly", "CFBundleShortVersionString"), | ||
("safari", "com.apple.Safari", "CFBundleShortVersionString"), | ||
("opera", "com.operasoftware.Opera", "CFBundleVersion"), | ||
("opera-beta", "com.operasoftware.OperaNext", "CFBundleVersion"), | ||
("opera-developer", "com.operasoftware.OperaDeveloper", "CFBundleVersion"), | ||
("msedge", "com.microsoft.edgemac", "CFBundleVersion"), | ||
("msedge-beta", "com.microsoft.edgemac.Beta", "CFBundleVersion"), | ||
("msedge-dev", "com.microsoft.edgemac.Dev", "CFBundleVersion"), | ||
("msedge-canary", "com.microsoft.edgemac.Canary", "CFBundleVersion"), | ||
("brave", "com.brave.Browser", "CFBundleVersion"), | ||
("brave-beta", "com.brave.Browser.beta", "CFBundleVersion"), | ||
("brave-dev", "com.brave.Browser.dev", "CFBundleVersion"), | ||
("brave-nightly", "com.brave.Browser.nightly", "CFBundleVersion"), | ||
) | ||
|
||
|
||
def browsers() -> Iterator[Tuple[str, Dict]]: # type: ignore[return] | ||
if sys.platform == "darwin": | ||
for browser, bundle_id, version_string in OSX_BROWSER_BUNDLE_LIST: | ||
paths = subprocess.getoutput(f'mdfind "kMDItemCFBundleIdentifier == {bundle_id}"').splitlines() | ||
for path in paths: | ||
with open(os.path.join(path, "Contents/Info.plist"), "rb") as f: | ||
plist = plistlib.load(f) | ||
display_name = plist.get("CFBundleDisplayName") or plist.get("CFBundleName", browser) | ||
version = plist[version_string] | ||
yield browser, dict(path=path, display_name=display_name, version=version) |
Oops, something went wrong.