mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 00:04:15 +02:00
Refactoring
This commit is contained in:
@@ -12,7 +12,7 @@ class FlatpakController:
|
||||
return self.model.read_installed()
|
||||
|
||||
def update(self, package_refs: List[str]) -> List[dict]:
|
||||
return self.model.update_packages(package_refs)
|
||||
return self.model.update_apps(package_refs)
|
||||
|
||||
def check_installed(self) -> bool:
|
||||
version = self.model.get_version()
|
||||
|
||||
@@ -3,7 +3,7 @@ import subprocess
|
||||
from typing import List
|
||||
|
||||
|
||||
def _package_str_to_json(line: str, version: str) -> dict:
|
||||
def app_str_to_json(line: str, version: str) -> dict:
|
||||
|
||||
app_array = line.split('\t')
|
||||
|
||||
@@ -24,7 +24,7 @@ def _package_str_to_json(line: str, version: str) -> dict:
|
||||
else:
|
||||
raise Exception('Unsupported version')
|
||||
|
||||
info = re.findall('\w+:\s.+', get_info(app['id']))
|
||||
info = re.findall('\w+:\s.+', get_app_info(app['id']))
|
||||
fields_to_get = ['origin', 'arch', 'ref']
|
||||
|
||||
for field in info:
|
||||
@@ -50,29 +50,24 @@ def get_version():
|
||||
return res.split(' ')[1].strip() if res else None
|
||||
|
||||
|
||||
def get_info(app_id: str):
|
||||
def get_app_info(app_id: str):
|
||||
return _run_cmd('flatpak info ' + app_id)
|
||||
|
||||
|
||||
def list_installed() -> List[str]:
|
||||
def list_installed() -> List[dict]:
|
||||
apps_str = _run_cmd('flatpak list')
|
||||
|
||||
if apps_str:
|
||||
version = get_version()
|
||||
app_lines = apps_str.split('\n')
|
||||
return [_package_str_to_json(line, version) for line in app_lines if line]
|
||||
return [app_str_to_json(line, version) for line in app_lines if line]
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def check_update(pak_id: dict) -> bool:
|
||||
res = _run_cmd('flatpak update ' + pak_id)
|
||||
return 'Updating in system' in res
|
||||
|
||||
|
||||
def update(ref: str):
|
||||
return bool(_run_cmd('flatpak update -y ' + ref))
|
||||
|
||||
|
||||
def list_updates():
|
||||
def list_updates_as_str():
|
||||
return _run_cmd('flatpak update', ignore_return_code=True)
|
||||
|
||||
@@ -14,8 +14,8 @@ __FLATHUB_API_URL__ = __FLATHUB_URL__ + '/api/v1'
|
||||
class FlatpakManager:
|
||||
|
||||
def __init__(self):
|
||||
self.packages = []
|
||||
self.packages_db = {}
|
||||
self.apps = []
|
||||
self.apps_db = {}
|
||||
self.http_session = requests.Session()
|
||||
self._load_database()
|
||||
|
||||
@@ -25,48 +25,48 @@ class FlatpakManager:
|
||||
|
||||
if res.status_code == 200:
|
||||
for app in res.json():
|
||||
self.packages_db[app['flatpakAppId']] = app
|
||||
self.apps_db[app['flatpakAppId']] = app
|
||||
|
||||
def get_version(self):
|
||||
return flatpak.get_version()
|
||||
|
||||
def read_installed(self) -> List[dict]:
|
||||
|
||||
packages = flatpak.list_installed()
|
||||
installed = flatpak.list_installed()
|
||||
|
||||
if packages:
|
||||
packages.sort(key=lambda p: p['name'].lower())
|
||||
if installed:
|
||||
installed.sort(key=lambda p: p['name'].lower())
|
||||
|
||||
available_updates = flatpak.list_updates()
|
||||
available_updates = flatpak.list_updates_as_str()
|
||||
|
||||
for pak in packages:
|
||||
for app in installed:
|
||||
|
||||
if self.packages_db:
|
||||
pak_data = self.packages_db.get(pak['id'], None)
|
||||
if self.apps_db:
|
||||
app_data = self.apps_db.get(app['id'], None)
|
||||
else:
|
||||
pak_data = None
|
||||
app_data = None
|
||||
|
||||
if not pak_data:
|
||||
pak['latest_version'] = None
|
||||
pak['icon'] = None
|
||||
if not app_data:
|
||||
app['latest_version'] = None
|
||||
app['icon'] = None
|
||||
else:
|
||||
pak['latest_version'] = pak_data['currentReleaseVersion']
|
||||
pak['icon'] = pak_data['iconDesktopUrl']
|
||||
app['latest_version'] = app_data['currentReleaseVersion']
|
||||
app['icon'] = app_data['iconMobileUrl']
|
||||
|
||||
if pak['icon'].startswith('/'):
|
||||
pak['icon'] = __FLATHUB_URL__ + pak['icon']
|
||||
if app['icon'].startswith('/'):
|
||||
app['icon'] = __FLATHUB_URL__ + app['icon']
|
||||
|
||||
pak['update'] = pak['id'] in available_updates
|
||||
app['update'] = app['id'] in available_updates
|
||||
|
||||
self.packages = packages
|
||||
return [*self.packages]
|
||||
self.apps = installed
|
||||
return [*self.apps]
|
||||
|
||||
def update_packages(self, refs: List[str]) -> List[dict]:
|
||||
def update_apps(self, refs: List[str]) -> List[dict]:
|
||||
|
||||
if self.packages:
|
||||
if self.apps:
|
||||
|
||||
for ref in refs:
|
||||
package_found = [pak for pak in self.packages if pak['ref'] == ref]
|
||||
package_found = [app for app in self.apps if app['ref'] == ref]
|
||||
|
||||
if package_found:
|
||||
package_found = package_found[0]
|
||||
@@ -75,6 +75,6 @@ class FlatpakManager:
|
||||
if updated:
|
||||
package_found['update'] = not updated
|
||||
|
||||
return [*self.packages]
|
||||
return [*self.apps]
|
||||
|
||||
return []
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
from model import flatpak
|
||||
|
||||
|
||||
def list_packages():
|
||||
packages = flatpak.list_installed()
|
||||
|
||||
if packages:
|
||||
packages = [pak for pak in packages if not pak['runtime']]
|
||||
|
||||
if packages:
|
||||
packages.sort(key=lambda p: p['name'].lower())
|
||||
|
||||
for pak in packages:
|
||||
pak['update'] = flatpak.check_update(pak['ref'])
|
||||
|
||||
return packages
|
||||
179
resources/img/flathub_25.svg
Normal file
179
resources/img/flathub_25.svg
Normal file
@@ -0,0 +1,179 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
width="24.856121"
|
||||
height="24.071226"
|
||||
viewBox="0 0 6.5765152 6.3688453"
|
||||
version="1.1"
|
||||
id="svg3871"
|
||||
inkscape:version="0.92.4 5da689c313, 2019-01-14"
|
||||
sodipodi:docname="flathub_25.svg">
|
||||
<defs
|
||||
id="defs3865" />
|
||||
<sodipodi:namedview
|
||||
id="base"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="0.35"
|
||||
inkscape:cx="354.15266"
|
||||
inkscape:cy="118.12208"
|
||||
inkscape:document-units="px"
|
||||
inkscape:current-layer="layer1"
|
||||
showgrid="false"
|
||||
showborder="false"
|
||||
inkscape:window-width="1360"
|
||||
inkscape:window-height="707"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="0"
|
||||
inkscape:window-maximized="1"
|
||||
fit-margin-bottom="-0.2"
|
||||
fit-margin-top="0"
|
||||
fit-margin-left="0"
|
||||
fit-margin-right="0"
|
||||
units="px" />
|
||||
<metadata
|
||||
id="metadata3868">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title></dc:title>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1"
|
||||
transform="translate(-12.13044,-173.71761)">
|
||||
<g
|
||||
transform="matrix(0.04603777,0,0,0.05772962,-23.990227,126.11012)"
|
||||
id="g10674"
|
||||
style="stroke-width:0.77710575">
|
||||
<path
|
||||
sodipodi:nodetypes="ccccccccccc"
|
||||
inkscape:connector-curvature="0"
|
||||
id="path10642"
|
||||
d="m 856.01397,830.22631 -66.76365,43.44891 v 34.93973 l 33.38182,21.72315 33.37926,-21.72315 v -0.005 l 0.003,0.003 33.38183,21.72574 33.37925,-21.72315 v -34.93979 z"
|
||||
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#204a87;fill-opacity:1;fill-rule:nonzero;stroke:#204a87;stroke-width:9.3252697;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;marker-start:none;marker-mid:none;marker-end:none;paint-order:normal;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" />
|
||||
<g
|
||||
style="stroke-width:0.58728963"
|
||||
transform="matrix(0.50221552,0,0,0.50636711,429.63205,432.90461)"
|
||||
id="g10652">
|
||||
<rect
|
||||
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#204a87;fill-opacity:1;fill-rule:nonzero;stroke:#204a87;stroke-width:2.4608953;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;marker-start:none;marker-mid:none;marker-end:none;paint-order:normal;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
|
||||
id="rect10644"
|
||||
width="79.110413"
|
||||
height="79.110413"
|
||||
x="1289.9076"
|
||||
y="279.42584"
|
||||
rx="0"
|
||||
ry="0"
|
||||
transform="matrix(0.84019328,0.54228706,-0.84019328,0.54228706,0,0)" />
|
||||
<path
|
||||
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#204a87;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:2.34915853;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;marker-start:none;marker-mid:none;marker-end:none;paint-order:normal;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
|
||||
d="m 915.46811,824.92983 -5e-5,68.99997 -66.46803,42.90055 5e-5,-68.99997 z"
|
||||
id="path10648"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
id="path10650"
|
||||
d="m 783.00003,824.92983 5e-5,68.99997 66.46803,42.90055 -5e-5,-68.99997 z"
|
||||
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:2.34915853;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;marker-start:none;marker-mid:none;marker-end:none;paint-order:normal;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" />
|
||||
<rect
|
||||
transform="matrix(0.84019328,0.54228706,-0.84019328,0.54228706,0,0)"
|
||||
ry="0"
|
||||
rx="0"
|
||||
y="215.8064"
|
||||
x="1226.2882"
|
||||
height="79.110413"
|
||||
width="79.110413"
|
||||
id="rect10646"
|
||||
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:#204a87;stroke-width:2.4608953;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;marker-start:none;marker-mid:none;marker-end:none;paint-order:normal;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" />
|
||||
</g>
|
||||
<g
|
||||
style="stroke-width:0.58728963"
|
||||
transform="matrix(0.50221552,0,0,0.50636711,463.01368,454.62849)"
|
||||
id="g10662">
|
||||
<rect
|
||||
transform="matrix(0.84019328,0.54228706,-0.84019328,0.54228706,0,0)"
|
||||
ry="0"
|
||||
rx="0"
|
||||
y="279.42584"
|
||||
x="1289.9076"
|
||||
height="79.110413"
|
||||
width="79.110413"
|
||||
id="rect10654"
|
||||
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#204a87;fill-opacity:1;fill-rule:nonzero;stroke:#204a87;stroke-width:2.4608953;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;marker-start:none;marker-mid:none;marker-end:none;paint-order:normal;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" />
|
||||
<rect
|
||||
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:#204a87;stroke-width:2.4608953;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;marker-start:none;marker-mid:none;marker-end:none;paint-order:normal;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
|
||||
id="rect10656"
|
||||
width="79.110413"
|
||||
height="79.110413"
|
||||
x="1226.2882"
|
||||
y="215.8064"
|
||||
rx="0"
|
||||
ry="0"
|
||||
transform="matrix(0.84019328,0.54228706,-0.84019328,0.54228706,0,0)" />
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
id="path10658"
|
||||
d="m 915.46811,824.92983 -5e-5,68.99997 -66.46803,42.90055 5e-5,-68.99997 z"
|
||||
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#204a87;fill-opacity:1;fill-rule:nonzero;stroke:#204a87;stroke-width:2.34915853;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;marker-start:none;marker-mid:none;marker-end:none;paint-order:normal;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" />
|
||||
<path
|
||||
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:#204a87;stroke-width:2.34915853;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;marker-start:none;marker-mid:none;marker-end:none;paint-order:normal;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
|
||||
d="m 783.00003,826.54445 5e-5,68.99997 66.46803,42.90055 -5e-5,-68.99997 z"
|
||||
id="path10660"
|
||||
inkscape:connector-curvature="0" />
|
||||
</g>
|
||||
<g
|
||||
style="stroke-width:0.58728963"
|
||||
id="g10672"
|
||||
transform="matrix(0.50221552,0,0,0.50636711,396.25042,454.62849)">
|
||||
<rect
|
||||
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#204a87;fill-opacity:1;fill-rule:nonzero;stroke:#204a87;stroke-width:2.4608953;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;marker-start:none;marker-mid:none;marker-end:none;paint-order:normal;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
|
||||
id="rect10664"
|
||||
width="79.110413"
|
||||
height="79.110413"
|
||||
x="1289.9076"
|
||||
y="279.42584"
|
||||
rx="0"
|
||||
ry="0"
|
||||
transform="matrix(0.84019328,0.54228706,-0.84019328,0.54228706,0,0)" />
|
||||
<rect
|
||||
transform="matrix(0.84019328,0.54228706,-0.84019328,0.54228706,0,0)"
|
||||
ry="0"
|
||||
rx="0"
|
||||
y="215.8064"
|
||||
x="1226.2882"
|
||||
height="79.110413"
|
||||
width="79.110413"
|
||||
id="rect10666"
|
||||
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:#204a87;stroke-width:2.4608953;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;marker-start:none;marker-mid:none;marker-end:none;paint-order:normal;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" />
|
||||
<path
|
||||
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#204a87;fill-opacity:1;fill-rule:nonzero;stroke:#204a87;stroke-width:2.34915853;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;marker-start:none;marker-mid:none;marker-end:none;paint-order:normal;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
|
||||
d="m 915.46811,824.92983 -5e-5,68.99997 -66.46803,42.90055 5e-5,-68.99997 z"
|
||||
id="path10668"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
id="path10670"
|
||||
d="m 783.00003,824.92983 5e-5,68.99997 66.46803,42.90055 -5e-5,-68.99997 z"
|
||||
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:#204a87;stroke-width:2.34915853;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;marker-start:none;marker-mid:none;marker-end:none;paint-order:normal;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" />
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
@@ -1,4 +1,3 @@
|
||||
import sys
|
||||
import time
|
||||
|
||||
from PyQt5.QtCore import QThread, pyqtSignal, QCoreApplication
|
||||
@@ -38,24 +37,25 @@ class UpdateCheck(QThread):
|
||||
class TrayIcon(QSystemTrayIcon):
|
||||
|
||||
def __init__(self, controller: FlatpakController, check_interval: int = 60, parent=None):
|
||||
self.icon_default = QIcon(resource.get_path('img/flathub_logo.svg'))
|
||||
self.controller = controller
|
||||
|
||||
self.icon_default = QIcon(resource.get_path('img/flathub_45.svg'))
|
||||
self.icon_update = QIcon(resource.get_path('img/update_logo.svg'))
|
||||
QSystemTrayIcon.__init__(self, self.icon_default, parent)
|
||||
self.menu = QMenu(parent)
|
||||
|
||||
self.menu = QMenu(parent)
|
||||
self.action_manage = self.menu.addAction("Manage applications")
|
||||
self.action_manage.triggered.connect(self.show_manage_window)
|
||||
|
||||
self.action_exit = self.menu.addAction("Exit")
|
||||
self.action_exit.triggered.connect(lambda: QCoreApplication.exit())
|
||||
self.setContextMenu(self.menu)
|
||||
self.controller = controller
|
||||
self.check_thread = UpdateCheck(check_interval=check_interval, controller=self.controller)
|
||||
self.check_thread.signal.connect(self.notify_update)
|
||||
self.check_thread.start()
|
||||
self.manage_window = ManageWindow(controller=controller, tray_icon=self)
|
||||
|
||||
def notify_update(self, updates: int):
|
||||
self.manage_window = ManageWindow(controller=controller, tray_icon=self)
|
||||
self.check_thread = UpdateCheck(check_interval=check_interval, controller=self.controller)
|
||||
self.check_thread.signal.connect(self.notify_updates)
|
||||
self.check_thread.start()
|
||||
|
||||
def notify_updates(self, updates: int):
|
||||
if updates > 0:
|
||||
if self.icon() != self.icon_update:
|
||||
self.setIcon(self.icon_update)
|
||||
|
||||
@@ -38,7 +38,7 @@ class UpdateToggleButton(QToolButton):
|
||||
|
||||
class ManageWindow(QWidget):
|
||||
|
||||
__COLUMNS__ = ['Package', 'Version', 'Latest Version', 'Branch', 'Arch', 'Ref', 'Origin', 'Update ?']
|
||||
__COLUMNS__ = ['Name', 'Version', 'Latest Version', 'Branch', 'Arch', 'Ref', 'Origin', 'Update ?']
|
||||
__BASE_HEIGHT__ = 400
|
||||
|
||||
def __init__(self, controller: FlatpakController, tray_icon = None):
|
||||
@@ -46,11 +46,15 @@ class ManageWindow(QWidget):
|
||||
self.controller = controller
|
||||
self.icon_cache = {}
|
||||
self.tray_icon = tray_icon
|
||||
self.thread_lock = Lock()
|
||||
self.working = False # restrict the number of threaded actions
|
||||
self.apps = []
|
||||
self.label_flatpak = None
|
||||
|
||||
self.network_man = QNetworkAccessManager()
|
||||
self.network_man.finished.connect(self._load_icon)
|
||||
|
||||
self.icon_flathub = QIcon(resource.get_path('img/flathub_logo.svg'))
|
||||
self.icon_flathub = QIcon(resource.get_path('img/flathub_45.svg'))
|
||||
self._check_flatpak_installed()
|
||||
self.resize(ManageWindow.__BASE_HEIGHT__, ManageWindow.__BASE_HEIGHT__)
|
||||
self.setWindowTitle('fpakman ({})'.format(__version__))
|
||||
@@ -67,17 +71,17 @@ class ManageWindow(QWidget):
|
||||
toolbar = QToolBar()
|
||||
toolbar.addWidget(self.checkbox_only_apps)
|
||||
|
||||
spacer_1 = QWidget()
|
||||
spacer_1.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
|
||||
toolbar.addWidget(spacer_1)
|
||||
spacer = QWidget()
|
||||
spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
|
||||
toolbar.addWidget(spacer)
|
||||
|
||||
self.label_status = QLabel()
|
||||
self.label_status.setText('')
|
||||
toolbar.addWidget(self.label_status)
|
||||
|
||||
spacer_2 = QWidget()
|
||||
spacer_2.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
|
||||
toolbar.addWidget(spacer_2)
|
||||
spacer = QWidget()
|
||||
spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
|
||||
toolbar.addWidget(spacer)
|
||||
|
||||
self.bt_refresh = QToolButton()
|
||||
self.bt_refresh.setIcon(QIcon(resource.get_path('img/refresh_orange.svg')))
|
||||
@@ -107,14 +111,11 @@ class ManageWindow(QWidget):
|
||||
|
||||
self.layout.addWidget(self.table_apps)
|
||||
|
||||
self.apps = []
|
||||
self.centralize()
|
||||
self.thread_update = UpdateSelectedApps(self.controller)
|
||||
self.thread_update.signal.connect(self._finish_update_selected)
|
||||
|
||||
self.update_thread = UpdateSelectedPackages(self.controller)
|
||||
self.update_thread.signal.connect(self._finish_update_selected)
|
||||
|
||||
self.refresh_thread = RefreshPackages(self.controller)
|
||||
self.refresh_thread.signal.connect(self._finish_refresh)
|
||||
self.thread_refresh = RefreshApps(self.controller)
|
||||
self.thread_refresh.signal.connect(self._finish_refresh)
|
||||
|
||||
self.toolbar_bottom = QToolBar()
|
||||
self.label_updates = QLabel('')
|
||||
@@ -123,11 +124,11 @@ class ManageWindow(QWidget):
|
||||
spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
|
||||
self.toolbar_bottom.addWidget(spacer)
|
||||
|
||||
self.toolbar_bottom.addWidget(QLabel('flatpak: ' + self.controller.get_version()))
|
||||
self.label_flatpak = QLabel(self._get_flatpak_label())
|
||||
self.toolbar_bottom.addWidget(self.label_flatpak)
|
||||
self.layout.addWidget(self.toolbar_bottom)
|
||||
|
||||
self.thread_lock = Lock()
|
||||
self.working = False # restrict the number of threaded actions
|
||||
self.centralize()
|
||||
|
||||
def closeEvent(self, event):
|
||||
|
||||
@@ -159,6 +160,12 @@ class ManageWindow(QWidget):
|
||||
error_msg.exec_()
|
||||
exit(1)
|
||||
|
||||
if self.label_flatpak:
|
||||
self.label_flatpak.setText(self._get_flatpak_label())
|
||||
|
||||
def _get_flatpak_label(self):
|
||||
return 'flatpak: ' + self.controller.get_version()
|
||||
|
||||
def _acquire_lock(self):
|
||||
|
||||
self.thread_lock.acquire()
|
||||
@@ -183,11 +190,11 @@ class ManageWindow(QWidget):
|
||||
if self._acquire_lock():
|
||||
self._check_flatpak_installed()
|
||||
self._begin_action('Refreshing...')
|
||||
self.refresh_thread.start()
|
||||
self.thread_refresh.start()
|
||||
|
||||
def _finish_refresh(self):
|
||||
|
||||
self.update_packages(self.refresh_thread.apps)
|
||||
self.update_apps(self.thread_refresh.apps)
|
||||
self.finish_action()
|
||||
self._release_lock()
|
||||
|
||||
@@ -228,7 +235,7 @@ class ManageWindow(QWidget):
|
||||
geo.moveCenter(center_point)
|
||||
self.move(geo.topLeft())
|
||||
|
||||
def update_packages(self, apps: List[dict]):
|
||||
def update_apps(self, apps: List[dict]):
|
||||
self._check_flatpak_installed()
|
||||
|
||||
self.table_apps.setEnabled(True)
|
||||
@@ -315,15 +322,15 @@ class ManageWindow(QWidget):
|
||||
|
||||
if to_update:
|
||||
self._begin_action('Updating...')
|
||||
self.update_thread.refs_to_update = to_update
|
||||
self.update_thread.start()
|
||||
self.thread_update.refs_to_update = to_update
|
||||
self.thread_update.start()
|
||||
|
||||
def _finish_update_selected(self):
|
||||
self.update_packages(self.update_thread.updated_apps)
|
||||
self.update_apps(self.thread_update.updated_apps)
|
||||
self.finish_action()
|
||||
|
||||
if self.tray_icon and self.update_thread.updated_apps:
|
||||
self.tray_icon.notify_update(len([app for app in self.update_thread.updated_apps if app['update']]))
|
||||
if self.tray_icon and self.thread_update.updated_apps:
|
||||
self.tray_icon.notify_updates(len([app for app in self.thread_update.updated_apps if app['update']]))
|
||||
|
||||
self._release_lock()
|
||||
|
||||
@@ -343,12 +350,12 @@ class ManageWindow(QWidget):
|
||||
|
||||
# Threaded actions
|
||||
|
||||
class UpdateSelectedPackages(QThread):
|
||||
class UpdateSelectedApps(QThread):
|
||||
|
||||
signal = pyqtSignal()
|
||||
|
||||
def __init__(self, controller: FlatpakController):
|
||||
super(UpdateSelectedPackages, self).__init__()
|
||||
super(UpdateSelectedApps, self).__init__()
|
||||
self.controller = controller
|
||||
self.refs_to_update = []
|
||||
self.updated_apps = None
|
||||
@@ -358,12 +365,12 @@ class UpdateSelectedPackages(QThread):
|
||||
self.signal.emit()
|
||||
|
||||
|
||||
class RefreshPackages(QThread):
|
||||
class RefreshApps(QThread):
|
||||
|
||||
signal = pyqtSignal()
|
||||
|
||||
def __init__(self, controller: FlatpakController):
|
||||
super(RefreshPackages, self).__init__()
|
||||
super(RefreshApps, self).__init__()
|
||||
self.controller = controller
|
||||
self.apps = None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user