mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-09 17:54:14 +02:00
[improvement][flathub] automatically adds Flathub as the default remote at the user level
This commit is contained in:
@@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||||||
- Flatpak:
|
- Flatpak:
|
||||||
- the application name tooltip now displays the installation level. e.g: **gedit ( system )**
|
- the application name tooltip now displays the installation level. e.g: **gedit ( system )**
|
||||||
- info window displaying the installation level
|
- info window displaying the installation level
|
||||||
|
- "remote not set" warning dropped in favor of the new behavior: automatically adds Flathub as the default remote at the user level
|
||||||
- Web:
|
- Web:
|
||||||
- not using HTTP sessions anymore to perform the searches. It seems to avoid URLs not being found after an internet drop event.
|
- not using HTTP sessions anymore to perform the searches. It seems to avoid URLs not being found after an internet drop event.
|
||||||
- supporting JPEG images as custom icons
|
- supporting JPEG images as custom icons
|
||||||
|
|||||||
@@ -58,12 +58,27 @@ class FlatpakManager(SoftwareManager):
|
|||||||
|
|
||||||
return app
|
return app
|
||||||
|
|
||||||
|
def _get_search_remote(self) -> str:
|
||||||
|
remotes = flatpak.list_remotes()
|
||||||
|
|
||||||
|
if remotes['system']:
|
||||||
|
remote_level = 'system'
|
||||||
|
elif remotes['user']:
|
||||||
|
remote_level = 'user'
|
||||||
|
else:
|
||||||
|
remote_level = 'user'
|
||||||
|
flatpak.set_default_remotes(remote_level)
|
||||||
|
|
||||||
|
return remote_level
|
||||||
|
|
||||||
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:
|
||||||
if is_url:
|
if is_url:
|
||||||
return SearchResult([], [], 0)
|
return SearchResult([], [], 0)
|
||||||
|
|
||||||
|
remote_level = self._get_search_remote()
|
||||||
|
|
||||||
res = SearchResult([], [], 0)
|
res = SearchResult([], [], 0)
|
||||||
apps_found = flatpak.search(flatpak.get_version(), words)
|
apps_found = flatpak.search(flatpak.get_version(), words, remote_level)
|
||||||
|
|
||||||
if apps_found:
|
if apps_found:
|
||||||
already_read = set()
|
already_read = set()
|
||||||
@@ -310,10 +325,7 @@ class FlatpakManager(SoftwareManager):
|
|||||||
return updates
|
return updates
|
||||||
|
|
||||||
def list_warnings(self, internet_available: bool) -> List[str]:
|
def list_warnings(self, internet_available: bool) -> List[str]:
|
||||||
if flatpak.is_installed():
|
return []
|
||||||
if not flatpak.has_remotes_set():
|
|
||||||
return [self.i18n['flatpak.notification.no_remotes'],
|
|
||||||
self.i18n['flatpak.notification.disable'].format(bold('Flatpak'), bold(self.i18n['manage_window.settings.gems']))]
|
|
||||||
|
|
||||||
def list_suggestions(self, limit: int, filter_installed: bool) -> List[PackageSuggestion]:
|
def list_suggestions(self, limit: int, filter_installed: bool) -> List[PackageSuggestion]:
|
||||||
cli_version = flatpak.get_version()
|
cli_version = flatpak.get_version()
|
||||||
@@ -327,6 +339,7 @@ class FlatpakManager(SoftwareManager):
|
|||||||
return res
|
return res
|
||||||
else:
|
else:
|
||||||
self.logger.info("Mapping suggestions")
|
self.logger.info("Mapping suggestions")
|
||||||
|
remote_level = self._get_search_remote()
|
||||||
installed = {i.id for i in self.read_installed(disk_loader=None).installed} if filter_installed else None
|
installed = {i.id for i in self.read_installed(disk_loader=None).installed} if filter_installed else None
|
||||||
|
|
||||||
for line in file.text.split('\n'):
|
for line in file.text.split('\n'):
|
||||||
@@ -345,7 +358,7 @@ class FlatpakManager(SoftwareManager):
|
|||||||
if cached_sug:
|
if cached_sug:
|
||||||
res.append(cached_sug)
|
res.append(cached_sug)
|
||||||
else:
|
else:
|
||||||
app_json = flatpak.search(cli_version, appid, app_id=True)
|
app_json = flatpak.search(cli_version, appid, remote_level, app_id=True)
|
||||||
|
|
||||||
if app_json:
|
if app_json:
|
||||||
model = PackageSuggestion(self._map_to_model(app_json[0], False, None), priority)
|
model = PackageSuggestion(self._map_to_model(app_json[0], False, None), priority)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import subprocess
|
|||||||
import traceback
|
import traceback
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
from typing import List, Dict
|
from typing import List, Dict, Set
|
||||||
|
|
||||||
from bauh.api.exception import NoInternetException
|
from bauh.api.exception import NoInternetException
|
||||||
from bauh.commons.system import new_subprocess, run_cmd, new_root_subprocess, SimpleProcess
|
from bauh.commons.system import new_subprocess, run_cmd, new_root_subprocess, SimpleProcess
|
||||||
@@ -260,9 +260,9 @@ def get_app_commits_data(app_ref: str, origin: str, installation: str) -> List[d
|
|||||||
return commits
|
return commits
|
||||||
|
|
||||||
|
|
||||||
def search(version: str, word: str, app_id: bool = False) -> List[dict]:
|
def search(version: str, word: str, installation: str, app_id: bool = False) -> List[dict]:
|
||||||
|
|
||||||
res = run_cmd('{} search {}'.format(BASE_CMD, word))
|
res = run_cmd('{} search {} --{}'.format(BASE_CMD, word, installation))
|
||||||
|
|
||||||
found = []
|
found = []
|
||||||
|
|
||||||
@@ -343,13 +343,31 @@ def install(app_id: str, origin: str, installation: str):
|
|||||||
return new_subprocess([BASE_CMD, 'install', origin, app_id, '-y', '--{}'.format(installation)])
|
return new_subprocess([BASE_CMD, 'install', origin, app_id, '-y', '--{}'.format(installation)])
|
||||||
|
|
||||||
|
|
||||||
def set_default_remotes():
|
def set_default_remotes(installation: str):
|
||||||
run_cmd('{} remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo'.format(BASE_CMD))
|
run_cmd('{} remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo --{}'.format(BASE_CMD, installation))
|
||||||
|
|
||||||
|
|
||||||
def has_remotes_set() -> bool:
|
def has_remotes_set() -> bool:
|
||||||
return bool(run_cmd('{} remotes'.format(BASE_CMD)).strip())
|
return bool(run_cmd('{} remotes'.format(BASE_CMD)).strip())
|
||||||
|
|
||||||
|
|
||||||
|
def list_remotes() -> Dict[str, Set[str]]:
|
||||||
|
res = {'system': set(), 'user': set()}
|
||||||
|
output = run_cmd('{} remotes'.format(BASE_CMD)).strip()
|
||||||
|
|
||||||
|
if output:
|
||||||
|
lines = output.split('\n')
|
||||||
|
|
||||||
|
for line in lines:
|
||||||
|
remote = line.split('\t')
|
||||||
|
|
||||||
|
if 'system' in remote[1]:
|
||||||
|
res['system'].add(remote[0].strip())
|
||||||
|
elif 'user' in remote[1]:
|
||||||
|
res['user'].add(remote[0].strip())
|
||||||
|
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
def run(app_id: str):
|
def run(app_id: str):
|
||||||
subprocess.Popen([BASE_CMD, 'run', app_id])
|
subprocess.Popen([BASE_CMD, 'run', app_id])
|
||||||
|
|||||||
Reference in New Issue
Block a user