mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 17:34:14 +02:00
notifying only new updates
This commit is contained in:
@@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||||||
- Allowing to specify a custom app translation with the environment variable **FPAKMAN_LOCALE**
|
- Allowing to specify a custom app translation with the environment variable **FPAKMAN_LOCALE**
|
||||||
- Adding expiration time for cached app data. Default to 1 hour. The environment variable **FPAKMAN_CACHE_EXPIRATION** can change this value.
|
- Adding expiration time for cached app data. Default to 1 hour. The environment variable **FPAKMAN_CACHE_EXPIRATION** can change this value.
|
||||||
- Minor GUI improvements
|
- Minor GUI improvements
|
||||||
|
- Notifying only new updates
|
||||||
|
|
||||||
## [0.2.1] - 2019-06-24
|
## [0.2.1] - 2019-06-24
|
||||||
### Features
|
### Features
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
import os
|
|
||||||
import time
|
import time
|
||||||
|
from typing import List
|
||||||
|
|
||||||
from PyQt5.QtCore import QThread, pyqtSignal, QCoreApplication
|
from PyQt5.QtCore import QThread, pyqtSignal, QCoreApplication
|
||||||
from PyQt5.QtGui import QIcon
|
from PyQt5.QtGui import QIcon
|
||||||
from PyQt5.QtWidgets import QSystemTrayIcon, QMenu
|
from PyQt5.QtWidgets import QSystemTrayIcon, QMenu
|
||||||
from fpakman.core.controller import FlatpakManager
|
|
||||||
|
|
||||||
from fpakman.core import resource, system
|
from fpakman.core import resource, system
|
||||||
|
from fpakman.core.controller import FlatpakManager
|
||||||
from fpakman.view.qt.about import AboutDialog
|
from fpakman.view.qt.about import AboutDialog
|
||||||
from fpakman.view.qt.window import ManageWindow
|
from fpakman.view.qt.window import ManageWindow
|
||||||
|
|
||||||
|
|
||||||
class UpdateCheck(QThread):
|
class UpdateCheck(QThread):
|
||||||
|
|
||||||
signal = pyqtSignal(int)
|
signal = pyqtSignal(list)
|
||||||
|
|
||||||
def __init__(self, manager: FlatpakManager, check_interval: int, parent=None):
|
def __init__(self, manager: FlatpakManager, check_interval: int, parent=None):
|
||||||
super(UpdateCheck, self).__init__(parent)
|
super(UpdateCheck, self).__init__(parent)
|
||||||
@@ -26,9 +26,10 @@ class UpdateCheck(QThread):
|
|||||||
|
|
||||||
apps = self.manager.read_installed()
|
apps = self.manager.read_installed()
|
||||||
|
|
||||||
updates = len([app for app in apps if app['update']])
|
updates = [app for app in apps if app['update']]
|
||||||
|
|
||||||
self.signal.emit(updates)
|
if updates:
|
||||||
|
self.signal.emit(updates)
|
||||||
|
|
||||||
time.sleep(self.check_interval)
|
time.sleep(self.check_interval)
|
||||||
|
|
||||||
@@ -83,6 +84,7 @@ class TrayIcon(QSystemTrayIcon):
|
|||||||
|
|
||||||
self.thread_database = LoadDatabase(manager)
|
self.thread_database = LoadDatabase(manager)
|
||||||
self.thread_database.signal_finished.connect(self._update_menu)
|
self.thread_database.signal_finished.connect(self._update_menu)
|
||||||
|
self.last_updates = set()
|
||||||
|
|
||||||
def load_database(self):
|
def load_database(self):
|
||||||
self.thread_database.start()
|
self.thread_database.start()
|
||||||
@@ -91,20 +93,27 @@ class TrayIcon(QSystemTrayIcon):
|
|||||||
self.action_refreshing.setVisible(False)
|
self.action_refreshing.setVisible(False)
|
||||||
self.action_manage.setVisible(True)
|
self.action_manage.setVisible(True)
|
||||||
|
|
||||||
def notify_updates(self, updates: int):
|
def notify_updates(self, updates: List[dict]):
|
||||||
if updates > 0:
|
|
||||||
if self.icon().cacheKey() != self.icon_update.cacheKey():
|
|
||||||
self.setIcon(self.icon_update)
|
|
||||||
|
|
||||||
msg = '{}: {}'.format(self.locale_keys['notification.new_updates'], updates)
|
if len(updates) > 0:
|
||||||
|
|
||||||
|
update_keys = {'{}:{}'.format(app['id'], app['latest_version']) for app in updates}
|
||||||
|
|
||||||
|
new_icon = self.icon_update
|
||||||
|
|
||||||
|
if update_keys.difference(self.last_updates):
|
||||||
|
self.last_updates = update_keys
|
||||||
|
msg = '{}: {}'.format(self.locale_keys['notification.new_updates'], len(updates))
|
||||||
self.setToolTip(msg)
|
self.setToolTip(msg)
|
||||||
|
|
||||||
system.notify_user(msg)
|
system.notify_user(msg)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.setIcon(self.icon_default)
|
new_icon = self.icon_default
|
||||||
self.setToolTip(None)
|
self.setToolTip(None)
|
||||||
|
|
||||||
|
if self.icon().cacheKey() != new_icon.cacheKey(): # changes the icon if needed
|
||||||
|
self.setIcon(new_icon)
|
||||||
|
|
||||||
def show_manage_window(self):
|
def show_manage_window(self):
|
||||||
|
|
||||||
if not self.manage_window:
|
if not self.manage_window:
|
||||||
|
|||||||
@@ -297,8 +297,7 @@ class ManageWindow(QWidget):
|
|||||||
break
|
break
|
||||||
|
|
||||||
self.bt_upgrade.setEnabled(enable_bt_update)
|
self.bt_upgrade.setEnabled(enable_bt_update)
|
||||||
|
self.tray_icon.notify_updates([app['model'] for app in self.apps if app['model']['update']])
|
||||||
self.tray_icon.notify_updates(total_updates)
|
|
||||||
|
|
||||||
def centralize(self):
|
def centralize(self):
|
||||||
geo = self.frameGeometry()
|
geo = self.frameGeometry()
|
||||||
|
|||||||
Reference in New Issue
Block a user