mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-08 21:14:15 +02:00
loading flatpak db in a different thread
This commit is contained in:
@@ -4,7 +4,6 @@ Wriiten in Python for QT5.
|
|||||||
|
|
||||||
### Roadmap
|
### Roadmap
|
||||||
- Test installer for Ubuntu
|
- Test installer for Ubuntu
|
||||||
- Load the database in a thread when the application starts. It will prevent the delay of showing the icon.
|
|
||||||
- Locales
|
- Locales
|
||||||
- System notification whe new updates
|
- System notification whe new updates
|
||||||
- Search and install applications.
|
- Search and install applications.
|
||||||
7
app.py
7
app.py
@@ -1,4 +1,5 @@
|
|||||||
#!env/bin/python
|
#!env/bin/python
|
||||||
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from PyQt5.QtWidgets import QApplication, QWidget
|
from PyQt5.QtWidgets import QApplication, QWidget
|
||||||
@@ -6,9 +7,15 @@ from PyQt5.QtWidgets import QApplication, QWidget
|
|||||||
from core.controller import FlatpakController
|
from core.controller import FlatpakController
|
||||||
from core.model import FlatpakManager
|
from core.model import FlatpakManager
|
||||||
from view.qt.systray import TrayIcon
|
from view.qt.systray import TrayIcon
|
||||||
|
from core import __version__
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(prog='fpakman', description="GUI for Flatpak applications management")
|
||||||
|
parser.add_argument('-v', '--version', action='version', version='%(prog)s {}'.format(__version__))
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
manager = FlatpakManager()
|
manager = FlatpakManager()
|
||||||
|
manager.load_database_async()
|
||||||
controller = FlatpakController(manager)
|
controller = FlatpakController(manager)
|
||||||
hidden_widget = QWidget()
|
hidden_widget = QWidget()
|
||||||
trayIcon = TrayIcon(parent=hidden_widget, controller=controller, check_interval=30)
|
trayIcon = TrayIcon(parent=hidden_widget, controller=controller, check_interval=30)
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from threading import Lock, Thread
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
@@ -17,15 +18,23 @@ class FlatpakManager:
|
|||||||
self.apps = []
|
self.apps = []
|
||||||
self.apps_db = {}
|
self.apps_db = {}
|
||||||
self.http_session = requests.Session()
|
self.http_session = requests.Session()
|
||||||
self._load_database()
|
self.lock_db_read = Lock()
|
||||||
|
|
||||||
def _load_database(self):
|
def load_database_async(self):
|
||||||
|
Thread(target=self.load_database).start()
|
||||||
|
|
||||||
res = self.http_session.get(__FLATHUB_API_URL__ + '/apps')
|
def load_database(self):
|
||||||
|
|
||||||
if res.status_code == 200:
|
self.lock_db_read.acquire()
|
||||||
for app in res.json():
|
|
||||||
self.apps_db[app['flatpakAppId']] = app
|
try:
|
||||||
|
res = self.http_session.get(__FLATHUB_API_URL__ + '/apps')
|
||||||
|
|
||||||
|
if res.status_code == 200:
|
||||||
|
for app in res.json():
|
||||||
|
self.apps_db[app['flatpakAppId']] = app
|
||||||
|
finally:
|
||||||
|
self.lock_db_read.release()
|
||||||
|
|
||||||
def get_version(self):
|
def get_version(self):
|
||||||
return flatpak.get_version()
|
return flatpak.get_version()
|
||||||
@@ -41,6 +50,9 @@ class FlatpakManager:
|
|||||||
|
|
||||||
for app in installed:
|
for app in installed:
|
||||||
|
|
||||||
|
if not self.apps_db:
|
||||||
|
self.load_database()
|
||||||
|
|
||||||
if self.apps_db:
|
if self.apps_db:
|
||||||
app_data = self.apps_db.get(app['id'], None)
|
app_data = self.apps_db.get(app['id'], None)
|
||||||
else:
|
else:
|
||||||
|
|||||||
2
run.sh
2
run.sh
@@ -1,2 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
/home/dafiti/workspace/fpakman/env/bin/python /home/dafiti/workspace/fpakman/app.py
|
|
||||||
@@ -3,8 +3,8 @@ from functools import reduce
|
|||||||
from threading import Lock
|
from threading import Lock
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from PyQt5.QtCore import Qt, QThread, pyqtSignal, QUrl
|
from PyQt5.QtCore import Qt, QThread, pyqtSignal, QUrl, QEvent
|
||||||
from PyQt5.QtGui import QIcon, QColor, QPixmap
|
from PyQt5.QtGui import QIcon, QColor, QPixmap, QWindowStateChangeEvent
|
||||||
from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkRequest
|
from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkRequest
|
||||||
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QApplication, QTableWidget, \
|
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QApplication, QTableWidget, \
|
||||||
QTableWidgetItem, QTableView, QCheckBox, QHeaderView, QToolButton, QToolBar, \
|
QTableWidgetItem, QTableView, QCheckBox, QHeaderView, QToolButton, QToolBar, \
|
||||||
@@ -105,9 +105,7 @@ class ManageWindow(QWidget):
|
|||||||
self.table_apps.setHorizontalHeaderLabels(ManageWindow.__COLUMNS__)
|
self.table_apps.setHorizontalHeaderLabels(ManageWindow.__COLUMNS__)
|
||||||
self.table_apps.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
self.table_apps.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
||||||
|
|
||||||
header_horizontal = self.table_apps.horizontalHeader()
|
self._change_table_headers_policy()
|
||||||
for i in range(0, len(ManageWindow.__COLUMNS__)):
|
|
||||||
header_horizontal.setSectionResizeMode(i, QHeaderView.Stretch + QHeaderView.AdjustToContents)
|
|
||||||
|
|
||||||
self.layout.addWidget(self.table_apps)
|
self.layout.addWidget(self.table_apps)
|
||||||
|
|
||||||
@@ -130,6 +128,16 @@ class ManageWindow(QWidget):
|
|||||||
|
|
||||||
self.centralize()
|
self.centralize()
|
||||||
|
|
||||||
|
def _change_table_headers_policy(self, policy: QHeaderView = QHeaderView.ResizeToContents):
|
||||||
|
header_horizontal = self.table_apps.horizontalHeader()
|
||||||
|
for i in range(0, len(ManageWindow.__COLUMNS__)):
|
||||||
|
header_horizontal.setSectionResizeMode(i, policy)
|
||||||
|
|
||||||
|
def changeEvent(self, e: QEvent):
|
||||||
|
|
||||||
|
if isinstance(e, QWindowStateChangeEvent):
|
||||||
|
self._change_table_headers_policy(QHeaderView.Stretch if self.isMaximized() else QHeaderView.ResizeToContents)
|
||||||
|
|
||||||
def closeEvent(self, event):
|
def closeEvent(self, event):
|
||||||
|
|
||||||
if self.tray_icon:
|
if self.tray_icon:
|
||||||
|
|||||||
Reference in New Issue
Block a user