mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-09 06:24:15 +02:00
[fix][web] some installed apps were not being displayed as installed in the search results
This commit is contained in:
@@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||||||
- Web
|
- Web
|
||||||
- not able to inject javascript fixes ( WhatsApp Web not working) [#74](https://github.com/vinifmor/bauh/issues/74)
|
- not able to inject javascript fixes ( WhatsApp Web not working) [#74](https://github.com/vinifmor/bauh/issues/74)
|
||||||
- not informing StartupWMClass on generated desktop entries ( prevents Gnome to link the Favorite shortcut with the app instance [#76](https://github.com/vinifmor/bauh/issues/76) )
|
- not informing StartupWMClass on generated desktop entries ( prevents Gnome to link the Favorite shortcut with the app instance [#76](https://github.com/vinifmor/bauh/issues/76) )
|
||||||
|
- some installed apps were not being displayed as installed in the search results
|
||||||
|
|
||||||
### Improvements
|
### Improvements
|
||||||
- AUR
|
- AUR
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ from typing import List, Type, Set, Tuple
|
|||||||
import requests
|
import requests
|
||||||
import yaml
|
import yaml
|
||||||
from colorama import Fore
|
from colorama import Fore
|
||||||
from requests import exceptions
|
from requests import exceptions, Response
|
||||||
|
|
||||||
from bauh.api.abstract.context import ApplicationContext
|
from bauh.api.abstract.context import ApplicationContext
|
||||||
from bauh.api.abstract.controller import SoftwareManager, SearchResult
|
from bauh.api.abstract.controller import SoftwareManager, SearchResult
|
||||||
@@ -156,17 +156,18 @@ class WebApplicationManager(SoftwareManager):
|
|||||||
def serialize_to_disk(self, pkg: SoftwarePackage, icon_bytes: bytes, only_icon: bool):
|
def serialize_to_disk(self, pkg: SoftwarePackage, icon_bytes: bytes, only_icon: bool):
|
||||||
super(WebApplicationManager, self).serialize_to_disk(pkg=pkg, icon_bytes=None, only_icon=False)
|
super(WebApplicationManager, self).serialize_to_disk(pkg=pkg, icon_bytes=None, only_icon=False)
|
||||||
|
|
||||||
def _map_url(self, url: str) -> Tuple["BeautifulSoup", requests.Response]:
|
def _request_url(self, url: str) -> Response:
|
||||||
headers = {'Accept-language': self._get_lang_header(), 'User-Agent': UA_CHROME}
|
headers = {'Accept-language': self._get_lang_header(), 'User-Agent': UA_CHROME}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
url_res = self.http_client.get(url, headers=headers, ignore_ssl=True, single_call=True, session=False)
|
return self.http_client.get(url, headers=headers, ignore_ssl=True, single_call=True, session=False, allow_redirects=True)
|
||||||
|
|
||||||
if url_res:
|
|
||||||
return BeautifulSoup(url_res.text, 'lxml', parse_only=SoupStrainer('head')), url_res
|
|
||||||
except exceptions.ConnectionError as e:
|
except exceptions.ConnectionError as e:
|
||||||
self.logger.warning("Could not get {}: {}".format(url, e.__class__.__name__))
|
self.logger.warning("Could not get {}: {}".format(url, e.__class__.__name__))
|
||||||
|
|
||||||
|
def _map_url(self, url: str) -> Tuple["BeautifulSoup", requests.Response]:
|
||||||
|
url_res = self._request_url(url)
|
||||||
|
return BeautifulSoup(url_res.text, 'lxml', parse_only=SoupStrainer('head')), url_res
|
||||||
|
|
||||||
def search(self, words: str, disk_loader: DiskCacheLoader, limit: int = -1, is_url: bool = False) -> SearchResult:
|
def search(self, words: str, disk_loader: DiskCacheLoader, limit: int = -1, is_url: bool = False) -> SearchResult:
|
||||||
local_config = {}
|
local_config = {}
|
||||||
thread_config = Thread(target=self._fill_config_async, args=(local_config,))
|
thread_config = Thread(target=self._fill_config_async, args=(local_config,))
|
||||||
@@ -200,7 +201,7 @@ class WebApplicationManager(SoftwareManager):
|
|||||||
desc = self._get_app_description(final_url, soup)
|
desc = self._get_app_description(final_url, soup)
|
||||||
icon_url = self._get_app_icon_url(final_url, soup)
|
icon_url = self._get_app_icon_url(final_url, soup)
|
||||||
|
|
||||||
app = WebApplication(url=final_url, name=name, description=desc, icon_url=icon_url)
|
app = WebApplication(url=final_url, source_url=url, name=name, description=desc, icon_url=icon_url)
|
||||||
|
|
||||||
if self.env_settings.get('electron') and self.env_settings['electron'].get('version'):
|
if self.env_settings.get('electron') and self.env_settings['electron'].get('version'):
|
||||||
app.version = self.env_settings['electron']['version']
|
app.version = self.env_settings['electron']['version']
|
||||||
@@ -256,7 +257,9 @@ class WebApplicationManager(SoftwareManager):
|
|||||||
# checking if any of the installed matches is one of the matched suggestions
|
# checking if any of the installed matches is one of the matched suggestions
|
||||||
|
|
||||||
for sug in matched_suggestions:
|
for sug in matched_suggestions:
|
||||||
found = [i for i in installed_matches if i.url == sug.get('url')]
|
sug_url = sug['url'][0:-1] if sug['url'].endswith('/') else sug['url']
|
||||||
|
|
||||||
|
found = [i for i in installed_matches if sug_url in {i.url, i.get_source_url()}]
|
||||||
|
|
||||||
if found:
|
if found:
|
||||||
res.installed.extend(found)
|
res.installed.extend(found)
|
||||||
|
|||||||
@@ -13,11 +13,12 @@ class WebApplication(SoftwarePackage):
|
|||||||
def __init__(self, id: str = None, url: str = None, name: str = None, description: str = None, icon_url: str = None,
|
def __init__(self, id: str = None, url: str = None, name: str = None, description: str = None, icon_url: str = None,
|
||||||
installation_dir: str = None, desktop_entry: str = None, installed: bool = False, version: str = None,
|
installation_dir: str = None, desktop_entry: str = None, installed: bool = False, version: str = None,
|
||||||
categories: List[str] = None, custom_icon: str = None, preset_options: List[str] = None, save_icon: bool = True,
|
categories: List[str] = None, custom_icon: str = None, preset_options: List[str] = None, save_icon: bool = True,
|
||||||
options_set: List[str] = None, package_name: str = None):
|
options_set: List[str] = None, package_name: str = None, source_url: str = None):
|
||||||
super(WebApplication, self).__init__(id=id if id else url, name=name, description=description,
|
super(WebApplication, self).__init__(id=id if id else url, name=name, description=description,
|
||||||
icon_url=icon_url, installed=installed, version=version,
|
icon_url=icon_url, installed=installed, version=version,
|
||||||
categories=categories)
|
categories=categories)
|
||||||
self.url = url
|
self.url = url
|
||||||
|
self.source_url = source_url if source_url else url
|
||||||
self.installation_dir = installation_dir
|
self.installation_dir = installation_dir
|
||||||
self.desktop_entry = desktop_entry
|
self.desktop_entry = desktop_entry
|
||||||
self.set_custom_icon(custom_icon)
|
self.set_custom_icon(custom_icon)
|
||||||
@@ -26,6 +27,12 @@ class WebApplication(SoftwarePackage):
|
|||||||
self.options_set = options_set
|
self.options_set = options_set
|
||||||
self.package_name = package_name
|
self.package_name = package_name
|
||||||
|
|
||||||
|
def get_source_url(self):
|
||||||
|
if self.source_url:
|
||||||
|
return self.source_url
|
||||||
|
|
||||||
|
return self.url
|
||||||
|
|
||||||
def set_version(self, version: str):
|
def set_version(self, version: str):
|
||||||
self.version = str(version) if version else None
|
self.version = str(version) if version else None
|
||||||
self.latest_version = version
|
self.latest_version = version
|
||||||
@@ -39,7 +46,7 @@ class WebApplication(SoftwarePackage):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_cached_attrs() -> tuple:
|
def _get_cached_attrs() -> tuple:
|
||||||
return 'id', 'name', 'version', 'url', 'description', 'icon_url', 'installation_dir', \
|
return 'id', 'name', 'version', 'url', 'description', 'icon_url', 'installation_dir', \
|
||||||
'desktop_entry', 'categories', 'custom_icon', 'options_set', 'save_icon', 'package_name'
|
'desktop_entry', 'categories', 'custom_icon', 'options_set', 'save_icon', 'package_name', 'source_url'
|
||||||
|
|
||||||
def can_be_downgraded(self):
|
def can_be_downgraded(self):
|
||||||
return False
|
return False
|
||||||
|
|||||||
Reference in New Issue
Block a user