mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-08 00:24:15 +02:00
improving initialization time and reducing async overload
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
import time
|
||||
from datetime import datetime, timedelta
|
||||
from typing import List
|
||||
|
||||
from PyQt5.QtCore import QThread, pyqtSignal
|
||||
|
||||
from fpakman.core import flatpak
|
||||
from fpakman.core.controller import FlatpakManager
|
||||
from fpakman.core.model import ApplicationStatus, FlatpakApplication
|
||||
from fpakman.util.cache import Cache
|
||||
from fpakman.view.qt import dialog
|
||||
from fpakman.view.qt.view_model import ApplicationView, ApplicationViewStatus
|
||||
|
||||
|
||||
class UpdateSelectedApps(QThread):
|
||||
@@ -43,17 +48,21 @@ class UninstallApp(QThread):
|
||||
signal_finished = pyqtSignal()
|
||||
signal_output = pyqtSignal(str)
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, manager: FlatpakManager, icon_cache: Cache, app: ApplicationView = None):
|
||||
super(UninstallApp, self).__init__()
|
||||
self.app_ref = None
|
||||
self.app = app
|
||||
self.manager = manager
|
||||
self.icon_cache = icon_cache
|
||||
|
||||
def run(self):
|
||||
if self.app_ref:
|
||||
for output in flatpak.uninstall_and_stream(self.app_ref):
|
||||
if self.app and isinstance(self.app.model, FlatpakApplication):
|
||||
for output in flatpak.uninstall_and_stream(self.app.model.ref):
|
||||
line = output.decode().strip()
|
||||
if line:
|
||||
self.signal_output.emit(line)
|
||||
|
||||
self.icon_cache.delete(self.app.model.base_data.icon_url)
|
||||
self.manager.clean_cache_for(self.app.model.base_data.id)
|
||||
self.signal_finished.emit()
|
||||
|
||||
|
||||
@@ -61,23 +70,23 @@ class DowngradeApp(QThread):
|
||||
signal_finished = pyqtSignal()
|
||||
signal_output = pyqtSignal(str)
|
||||
|
||||
def __init__(self, manager: FlatpakManager, locale_keys: dict):
|
||||
def __init__(self, manager: FlatpakManager, locale_keys: dict, app: ApplicationView = None):
|
||||
super(DowngradeApp, self).__init__()
|
||||
self.manager = manager
|
||||
self.app = None
|
||||
self.root_password = None
|
||||
self.app = app
|
||||
self.locale_keys = locale_keys
|
||||
self.root_password = None
|
||||
|
||||
def run(self):
|
||||
if self.app:
|
||||
if self.app and isinstance(self.app.model, FlatpakApplication):
|
||||
|
||||
stream = self.manager.downgrade_app(self.app['model'], self.root_password)
|
||||
stream = self.manager.downgrade_app(self.app.model, self.root_password)
|
||||
|
||||
if stream is None:
|
||||
dialog.show_error(title=self.locale_keys['popup.downgrade.impossible.title'],
|
||||
body=self.locale_keys['popup.downgrade.impossible.body'])
|
||||
else:
|
||||
for output in self.manager.downgrade_app(self.app['model'], self.root_password):
|
||||
for output in self.manager.downgrade_app(self.app.model, self.root_password):
|
||||
line = output.decode().strip()
|
||||
if line:
|
||||
self.signal_output.emit(line)
|
||||
@@ -90,16 +99,16 @@ class DowngradeApp(QThread):
|
||||
class GetAppInfo(QThread):
|
||||
signal_finished = pyqtSignal(dict)
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, app: ApplicationView = None):
|
||||
super(GetAppInfo, self).__init__()
|
||||
self.app = None
|
||||
self.app = app
|
||||
|
||||
def run(self):
|
||||
if self.app:
|
||||
app_info = flatpak.get_app_info_fields(self.app['model']['id'], self.app['model']['branch'])
|
||||
app_info['name'] = self.app['model']['name']
|
||||
app_info['type'] = 'runtime' if self.app['model']['runtime'] else 'app'
|
||||
app_info['description'] = self.app['model']['description']
|
||||
if self.app and isinstance(self.app.model, FlatpakApplication):
|
||||
app_info = flatpak.get_app_info_fields(self.app.model.base_data.id, self.app.model.branch)
|
||||
app_info['name'] = self.app.model.base_data.name
|
||||
app_info['type'] = 'runtime' if self.app.model.runtime else 'app'
|
||||
app_info['description'] = self.app.model.base_data.description
|
||||
self.signal_finished.emit(app_info)
|
||||
self.app = None
|
||||
|
||||
@@ -107,14 +116,14 @@ class GetAppInfo(QThread):
|
||||
class GetAppHistory(QThread):
|
||||
signal_finished = pyqtSignal(dict)
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, app: ApplicationView = None):
|
||||
super(GetAppHistory, self).__init__()
|
||||
self.app = None
|
||||
self.app = app
|
||||
|
||||
def run(self):
|
||||
if self.app:
|
||||
commits = flatpak.get_app_commits_data(self.app['model']['ref'], self.app['model']['origin'])
|
||||
self.signal_finished.emit({'model': self.app['model'], 'commits': commits})
|
||||
if self.app and isinstance(self.app.model, FlatpakApplication):
|
||||
commits = flatpak.get_app_commits_data(self.app.model.ref, self.app.model.origin)
|
||||
self.signal_finished.emit({'model': self.app.model, 'commits': commits})
|
||||
self.app = None
|
||||
|
||||
|
||||
@@ -141,14 +150,14 @@ class InstallApp(QThread):
|
||||
signal_finished = pyqtSignal()
|
||||
signal_output = pyqtSignal(str)
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, app: ApplicationView = None):
|
||||
super(InstallApp, self).__init__()
|
||||
self.app = None
|
||||
self.app = app
|
||||
|
||||
def run(self):
|
||||
|
||||
if self.app:
|
||||
for output in flatpak.install_and_stream(self.app['model']['id'], self.app['model']['origin']):
|
||||
if self.app and isinstance(self.app.model, FlatpakApplication):
|
||||
for output in flatpak.install_and_stream(self.app.model.base_data.id, self.app.model.origin):
|
||||
line = output.decode().strip()
|
||||
if line:
|
||||
self.signal_output.emit(line)
|
||||
@@ -184,3 +193,36 @@ class AnimateProgress(QThread):
|
||||
time.sleep(0.05)
|
||||
|
||||
self.progress_value = 0
|
||||
|
||||
|
||||
class VerifyModels(QThread):
|
||||
|
||||
signal_updates = pyqtSignal()
|
||||
|
||||
def __init__(self, apps: List[ApplicationView] = None):
|
||||
super(VerifyModels, self).__init__()
|
||||
self.apps = apps
|
||||
|
||||
def run(self):
|
||||
|
||||
if self.apps:
|
||||
|
||||
stop_at = datetime.utcnow() + timedelta(seconds=30)
|
||||
last_ready = 0
|
||||
|
||||
while True:
|
||||
current_ready = 0
|
||||
|
||||
for app in self.apps:
|
||||
current_ready += 1 if app.model.status == ApplicationStatus.READY else 0
|
||||
|
||||
if current_ready > last_ready:
|
||||
last_ready = current_ready
|
||||
self.signal_updates.emit()
|
||||
|
||||
if current_ready == len(self.apps):
|
||||
self.signal_updates.emit()
|
||||
break
|
||||
|
||||
if stop_at <= datetime.utcnow():
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user