mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 01:14:15 +02:00
[flatpak] Formatting the API categories to the same format provided by the other packaging technologies
This commit is contained in:
@@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||
- showing an error popup when **AppImageLauncher** messes up with an application installation
|
||||
- Flatpak:
|
||||
- Runtimes now are categorized as "runtime"
|
||||
- Formatting the API categories to the same format provided by the other packaging technologies
|
||||
- AUR:
|
||||
- showing a "user-friendly" popup when there are integrity issues with the source-files of a building package
|
||||
- not waiting for the categories file to be retrieved from the cloud during application boot ( reduces boot time )
|
||||
|
||||
@@ -25,6 +25,7 @@ class FlatpakManager(SoftwareManager):
|
||||
super(FlatpakManager, self).__init__(context=context)
|
||||
self.i18n = context.i18n
|
||||
self.api_cache = context.cache_factory.new()
|
||||
self.category_cache = context.cache_factory.new()
|
||||
context.disk_loader_factory.map(FlatpakApplication, self.api_cache)
|
||||
self.enabled = True
|
||||
self.http_client = context.http_client
|
||||
@@ -46,7 +47,8 @@ class FlatpakManager(SoftwareManager):
|
||||
disk_loader.fill(app) # preloading cached disk data
|
||||
|
||||
if internet:
|
||||
FlatpakAsyncDataLoader(app=app, api_cache=self.api_cache, manager=self, context=self.context).start()
|
||||
FlatpakAsyncDataLoader(app=app, api_cache=self.api_cache, manager=self,
|
||||
context=self.context, category_cache=self.category_cache).start()
|
||||
|
||||
else:
|
||||
app.fill_cached_data(api_data)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import re
|
||||
import traceback
|
||||
from threading import Thread
|
||||
|
||||
@@ -9,10 +10,12 @@ from bauh.api.http import HttpClient
|
||||
from bauh.gems.flatpak.constants import FLATHUB_API_URL, FLATHUB_URL
|
||||
from bauh.gems.flatpak.model import FlatpakApplication
|
||||
|
||||
RE_SPLIT_UPPER = re.compile(r'[A-Z][a-z]*')
|
||||
|
||||
|
||||
class FlatpakAsyncDataLoader(Thread):
|
||||
|
||||
def __init__(self, app: FlatpakApplication, manager: SoftwareManager, context: ApplicationContext, api_cache: MemoryCache):
|
||||
def __init__(self, app: FlatpakApplication, manager: SoftwareManager, context: ApplicationContext, api_cache: MemoryCache, category_cache: MemoryCache):
|
||||
super(FlatpakAsyncDataLoader, self).__init__(daemon=True)
|
||||
self.app = app
|
||||
self.manager = manager
|
||||
@@ -20,6 +23,7 @@ class FlatpakAsyncDataLoader(Thread):
|
||||
self.api_cache = api_cache
|
||||
self.persist = False
|
||||
self.logger = context.logger
|
||||
self.category_cache = category_cache
|
||||
|
||||
def run(self):
|
||||
if self.app:
|
||||
@@ -51,7 +55,17 @@ class FlatpakAsyncDataLoader(Thread):
|
||||
self.app.icon_url = FLATHUB_URL + self.app.icon_url
|
||||
|
||||
if data.get('categories'):
|
||||
self.app.categories = [c['name'] for c in data['categories']]
|
||||
cats = []
|
||||
for c in data['categories']:
|
||||
cached = self.category_cache.get(c['name'])
|
||||
|
||||
if not cached:
|
||||
cached = ' '.join(RE_SPLIT_UPPER.findall(c['name'])).lower()
|
||||
self.category_cache.add_non_existing(c['name'], cached)
|
||||
|
||||
cats.append(cached)
|
||||
|
||||
self.app.categories = cats
|
||||
|
||||
loaded_data = self.app.get_data_to_cache()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user