From 99551763219e05df83a3174d0a4dafda8ac85919 Mon Sep 17 00:00:00 2001 From: Eric Lay Date: Thu, 7 Dec 2023 18:57:10 -0600 Subject: [PATCH] update --- PKGBUILD | 29 ++++++++++++++++ README.md | 9 +++-- systrayUpdater | 86 +++++++++++++++++++++++++++++++--------------- systrayupdater.yml | 4 +-- 4 files changed, 95 insertions(+), 33 deletions(-) create mode 100644 PKGBUILD diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 0000000..343e0db --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,29 @@ +# Maintainer: Eric Lay +pkgname=systrayupdater +pkgver=0.1 +pkgrel=1 +pkgdesc="PyQt5 system tray applet to notify of available updates" +arch=('x86_64') +url="https://github.com/ericlay/$pkgname" +license=('GPL3') +depends=('python' + 'python-pyqt5' + 'python-yaml' + 'python-jaraco.functools' + 'pacman') +makedepends=('git') +optdepends=() +source=("git+https://github.com/ericlay/fuzzy-pkg-finder.git") +md5sums=('SKIP') + +pkgver(){ + cd "$pkgname" + printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)" +} + +package() { + cd "$srcdir/$pkgname" + install -Dm755 systrayUpdater -t "$pkgdir/usr/bin" + install -Dm666 systrayUpdater.desktop -t "$pkgdir/usr/share/applications" + install -Dm755 ./*.png systrayupdater.yml -t "$pkgdir/$HOME/.config/$pkgname" +} \ No newline at end of file diff --git a/README.md b/README.md index 753f56f..df4642a 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,13 @@ # systrayUpdater -Simple Qt based system tray icon to notify of available updates and then update on click +PyQt5 system tray applet to notify of available updates. For Arch (based) systems only! +Right click to access menu actions: +-Run update +-Read the News +-Display list of packages with updates available (click to search arch website for highlighted package) + To install and use: Place files in appropriate locations and run appropriate commands when doing so Uses config file for options. @@ -14,5 +19,3 @@ Includes: - .desktop file for autostarting - Tray and shortcut icons -TODO -- look into adding option to view news or quick list diff --git a/systrayUpdater b/systrayUpdater index c90e466..0c3cba1 100755 --- a/systrayUpdater +++ b/systrayUpdater @@ -2,14 +2,18 @@ # Get needed modules import yaml +import webbrowser import subprocess from os import path +from time import sleep +from functools import partial from PyQt5.QtCore import QTimer from PyQt5.QtGui import * from PyQt5.QtWidgets import * -# Available Updates count holder +# Available Updates holders avail = "" +outputList = "" # Use config.yml file to allow for compatibility with # most terminal emulators possible & custom icon / timer duration @@ -22,59 +26,85 @@ with open(path.expanduser("~/.config/systrayUpdater/systrayUpdater.yml")) as f: f.close() # Run checkupdates command -# Populates the available updates count holder +# Populates the available updates and count +# Sets the list and count in proper spots def count(): cmd = ['checkupdates'] p1 = subprocess.Popen(cmd, stdout=subprocess.PIPE) - p2 = subprocess.Popen(['wc', '-l'], stdin=p1.stdout, stdout=subprocess.PIPE) - output = ((p2.communicate()[0]).decode()).rstrip('\n') - global avail - avail = str(output)+" Updates" + global outputList + outputList = ((p1.communicate()[0]).decode()).rstrip('\n') + outputCount = len(outputList.splitlines()) + if outputCount == 0: + tray.setVisible(False) + else: + tray.setVisible(True) + for i in outputList.splitlines(): + menu.addAction(i, partial(infos, i)) + global avail + avail = str(outputCount)+" Updates" + tray.setToolTip(avail) -# Run system update +# Read the News +# Get pkg info +def news(): + url = 'https://archlinux.org/news/' + webbrowser.open_new_tab(url) + +# Get pkg info +def infos(pkgString): + pkg = pkgString.split(' ') + url = 'https://archlinux.org/packages/?q='+ pkg[0] + webbrowser.open_new_tab(url) + +# Clear old update list when new list available +def clear(): + menu.clear() + menu.addAction(option1) + menu.addAction(option2) + menu.addAction(quit) + +# Run system updatehttps://archlinux.org/packages/?q='+ pkg[0] def update(): - cmd = [ term, opt, 'sudo', 'pacman', '-Syu'] + cmd = [ term, opt, 'sudo', 'pacman', '-Syu' ] subprocess.Popen(cmd) + clear() -# Sets new text for available updates -def newText(): - count() - option1.setText(avail) - tray.setToolTip(avail) - -# Initially populate available updates -count() - +# Create an app surface app = QApplication([]) app.setQuitOnLastWindowClosed(False) -# Adding an icon -icon = QIcon(icn) +# Set up timer to update count +clearTimer = QTimer() +clearTimer.timeout.connect(clear) +updateTimer = QTimer() +updateTimer.timeout.connect(count) +updateTimer.singleShot(1,count) # Initially populate available updates +clearTimer.start(wait) +sleep(1) +updateTimer.start(wait) -# Adding item on the menu bar +# Adding items to the menu tray = QSystemTrayIcon() +icon = QIcon(icn) tray.setIcon(icon) tray.setToolTip(avail) tray.setVisible(True) # Creating the options menu = QMenu() -option1 = QAction(avail) +option1 = QAction("Run Update") +option2 = QAction("Read the News") option1.triggered.connect(update) -option1.triggered.connect(newText) +option2.triggered.connect(news) menu.addAction(option1) - -# Set up timer to update count -timer = QTimer() -timer.timeout.connect(newText) -timer.start(wait) +menu.addAction(option2) # To quit the app quit = QAction("Quit") quit.triggered.connect(app.quit) menu.addAction(quit) -# Adding options to the System Tray +# Place the app in the System Tray tray.setContextMenu(menu) app.exec_() diff --git a/systrayupdater.yml b/systrayupdater.yml index 4882256..52d76a2 100644 --- a/systrayupdater.yml +++ b/systrayupdater.yml @@ -3,8 +3,8 @@ # ----------------# # Terminal emulator launch command and execute option -terminal: terminator -option: -x +terminal: $TERM +option: -e # timer value is set to minutes timer: 10 # custom icons should follow Arch linux standards