Merge branch 'staging' into modules

# Conflicts:
#	fpakman/core/controller.py
#	fpakman/util/memory.py
This commit is contained in:
Vinicius Moreira
2019-08-07 18:54:08 -03:00
6 changed files with 50 additions and 19 deletions

View File

@@ -11,7 +11,6 @@ from fpakman.core import resource, extensions
from fpakman.core.controller import GenericApplicationManager
from fpakman.util import util
from fpakman.util.memory import CacheCleaner
from fpakman.view.qt import dialog
from fpakman.view.qt.systray import TrayIcon
from fpakman.view.qt.window import ManageWindow
@@ -54,18 +53,11 @@ if args.tray:
manage_window=manage_window,
check_interval=args.check_interval,
update_notification=bool(args.update_notification))
manage_window.tray_icon = trayIcon
trayIcon.show()
else:
manage_window.refresh_apps()
manage_window.show()
warnings = manager.list_warnings()
if warnings:
for warning in warnings:
dialog.show_warning(title=locale_keys['warning'].capitalize(), body=warning)
CacheCleaner(caches).start()
sys.exit(app.exec_())

View File

@@ -63,6 +63,8 @@ class GenericApplicationManager(ApplicationManager):
res['new'].extend(apps_found['new'])
def search(self, word: str, disk_loader: DiskCacheLoader = None) -> Dict[str, List[Application]]:
self._wait_to_be_ready()
res = {'installed': [], 'new': []}
norm_word = word.strip().lower()
@@ -89,6 +91,8 @@ class GenericApplicationManager(ApplicationManager):
return res
def read_installed(self, disk_loader: DiskCacheLoader = None) -> List[Application]:
self._wait_to_be_ready()
installed = []
disk_loader = None
@@ -180,18 +184,26 @@ class GenericApplicationManager(ApplicationManager):
return man.requires_root(action, app)
def refresh(self, app: Application, root_password: str) -> FpakmanProcess:
self._wait_to_be_ready()
man = self._get_manager_for(app)
if man:
return man.refresh(app, root_password)
def prepare(self):
def _prepare(self):
if self.managers:
for man in self.managers:
if self._is_enabled(man):
man.prepare()
def prepare(self):
self.thread_prepare = Thread(target=self._prepare)
self.thread_prepare.start()
def list_updates(self) -> List[ApplicationUpdate]:
self._wait_to_be_ready()
updates = []
if self.managers:
@@ -220,15 +232,16 @@ class GenericApplicationManager(ApplicationManager):
def _fill_suggestions(self, suggestions: list, man: ApplicationManager, limit: int):
if self._is_enabled(man):
man_suges = man.list_suggestions(limit)
if man_suges:
suggestions.extend(man_suges)
man_sugs = man.list_suggestions(limit)
if man_sugs:
suggestions.extend(man_sugs)
def list_suggestions(self, limit: int) -> List[Application]:
if self.managers:
suggestions, threads = [], []
for man in self.managers:
t = Thread(target=self._fill_suggestions, args=(suggestions, man, limit))
t = Thread(target=self._fill_suggestions, args=(suggestions, man, SUGGESTIONS_LIMIT))
t.start()
threads.append(t)

View File

@@ -3,7 +3,6 @@ from threading import Thread
from typing import List
from fpakman_api.util.cache import Cache
import gc
class CacheCleaner(Thread):
@@ -20,6 +19,5 @@ class CacheCleaner(Thread):
for cache in self.caches:
cache.clean_expired()
gc.collect()
time.sleep(self.check_interval)

View File

@@ -346,4 +346,18 @@ class FindSuggestions(AsyncAction):
def run(self):
self.signal_finished.emit(self.man.list_suggestions(limit=-1))
class ListWarnings(QThread):
signal_warnings = pyqtSignal(list)
def __init__(self, man: ApplicationManager, locale_keys: dict):
super(QThread, self).__init__()
self.locale_keys = locale_keys
self.man = man
def run(self):
warnings = self.man.list_warnings()
if warnings:
self.signal_warnings.emit(warnings)

View File

@@ -19,7 +19,7 @@ from fpakman.view.qt.history import HistoryDialog
from fpakman.view.qt.info import InfoDialog
from fpakman.view.qt.root import is_root, ask_root_password
from fpakman.view.qt.thread import UpdateSelectedApps, RefreshApps, UninstallApp, DowngradeApp, GetAppInfo, \
GetAppHistory, SearchApps, InstallApp, AnimateProgress, VerifyModels, RefreshApp, FindSuggestions
GetAppHistory, SearchApps, InstallApp, AnimateProgress, VerifyModels, RefreshApp, FindSuggestions, ListWarnings
from fpakman.view.qt.view_model import ApplicationView
DARK_ORANGE = '#FF4500'
@@ -214,6 +214,19 @@ class ManageWindow(QWidget):
self.dialog_about = None
self.first_refresh = suggestions
self.thread_warnings = ListWarnings(man=manager, locale_keys=locale_keys)
self.thread_warnings.signal_warnings.connect(self._show_warnings)
def _show_warnings(self, warnings: List[str]):
if warnings:
for warning in warnings:
dialog.show_warning(title=self.locale_keys['warning'].capitalize(), body=warning)
def show(self):
super(ManageWindow, self).show()
if not self.thread_warnings.isFinished():
self.thread_warnings.start()
def _show_about(self):
if self.dialog_about is None:
self.dialog_about = AboutDialog(self.locale_keys)