diff --git a/README.md b/README.md index efc15450..574e2dae 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,7 @@ Key features - `snapd`: Snaps support - `python3-lxml`, `python3-bs4`: Web apps support - `python3-venv`: [isolated installation](#inst_iso) +- `xdg-utils`: to open URLs in the browsers (`xdg-open`) ##### Updating bauh @@ -125,8 +126,9 @@ makepkg -si - `aria2`: multi-threaded downloads - `axel`: multi-threaded downloads alternative - `libappindicator-gtk2`: tray-mode (GTK2 desktop environments) -- `libappindicator-gtk3`: tray-mode (GTK3 desktop environments) -- `wget`, `sqlite`, `fuse2`, `fuse3`: AppImage support +- `libappindicator-gtk3`: tray-mode (GTK3 desktop environments) +- `xdg-utils`: to open URLs in the browser (`xdg-open`) +- `sqlite`, `fuse2`, `fuse3`: AppImage support - `flatpak`: Flatpak support - `snapd`: Snap support - `pacman`: ArchLinux package management support diff --git a/bauh/view/qt/info.py b/bauh/view/qt/info.py index a0b6153c..01abcacc 100644 --- a/bauh/view/qt/info.py +++ b/bauh/view/qt/info.py @@ -1,6 +1,8 @@ +import shutil import subprocess from collections.abc import Iterable from subprocess import Popen +from typing import Optional from PyQt5.QtCore import Qt from PyQt5.QtGui import QIcon, QCursor @@ -19,10 +21,11 @@ IGNORED_ATTRS = {'name', '__app__'} class InfoDialog(QDialog): - def __init__(self, pkg_info: dict, icon_cache: MemoryCache, i18n: I18n): + def __init__(self, pkg_info: dict, icon_cache: MemoryCache, i18n: I18n, can_open_url: bool): super(InfoDialog, self).__init__() self.setWindowTitle(str(pkg_info['__app__'])) self.i18n = i18n + self._can_open_url = can_open_url layout = QVBoxLayout() self.setLayout(layout) @@ -129,7 +132,7 @@ class InfoDialog(QDialog): def _gen_show_button(self, idx: int, val: str): - is_url = bool(RE_URL.match(val)) if val else False + is_url = self._can_open_url and bool(RE_URL.match(val)) if val else False if is_url: bt_label = self.i18n["manage_window.info.open_url"] diff --git a/bauh/view/qt/window.py b/bauh/view/qt/window.py index bceaa3a9..7fb06c86 100755 --- a/bauh/view/qt/window.py +++ b/bauh/view/qt/window.py @@ -1,6 +1,7 @@ import logging import operator import os.path +import shutil import time from pathlib import Path from typing import List, Type, Set, Tuple, Optional, Dict, Any @@ -472,6 +473,7 @@ class ManageWindow(QWidget): self._register_groups() self._screen_geometry: Optional[QRect] = None self.searched_term: Optional[str] = None # last searched term + self._can_open_urls: Optional[bool] = None # whether URLs can be opened in the browser qt_utils.centralize(self) @@ -1368,7 +1370,8 @@ class ManageWindow(QWidget): if pkg_info: if len(pkg_info) > 1: - dialog_info = InfoDialog(pkg_info=pkg_info, icon_cache=self.icon_cache, i18n=self.i18n) + dialog_info = InfoDialog(pkg_info=pkg_info, icon_cache=self.icon_cache, i18n=self.i18n, + can_open_url=self.can_open_urls) dialog_info.exec_() else: dialog.show_message(title=self.i18n['warning'].capitalize(), @@ -1816,3 +1819,10 @@ class ManageWindow(QWidget): def closeEvent(self, event: QCloseEvent) -> None: # needs to be stopped to avoid a Qt exception/crash self.table_apps.stop_file_downloader(wait=True) + + @property + def can_open_urls(self) -> bool: + if self._can_open_urls is None: + self._can_open_urls = shutil.which("xdg-open") + + return self._can_open_urls