-
Notifications
You must be signed in to change notification settings - Fork 0
/
systray-updater
executable file
·124 lines (111 loc) · 3.75 KB
/
systray-updater
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env python
# Get needed modules
import sys
import yaml
import webbrowser
import subprocess
from os import path
from functools import partial
from PyQt5.QtCore import QTimer
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QAction, QApplication, QSystemTrayIcon, QMenu
# Use config.yml file to allow for compatibility with
# most terminal emulators possible, custom timer duration and icons
if path.exists(path.expanduser("~/.config/systrayupdater/config.yml")):
config = path.expanduser("~/.config/systrayupdater/config.yml")
else:
config = '/etc/systrayupdater/config.yml'
try:
f = open(config)
except FileNotFoundError:
print("Error: No config file found\n")
sys.exit(1)
conf = yaml.load(f,yaml.FullLoader)
term = str(conf['terminal'])
opt = str(conf['option'])
wait = int(conf['timer']) * 60000
icn = str(conf['icon'])
f.close()
iconDir = '/usr/share/icons/systrayupdater/'
match icn:
case "white":
icon = QIcon(path.join(iconDir,'arch-white-symbolic-24.svg'))
case "blue":
icon = QIcon(path.join(iconDir,'arch-blue-symbolic-24.svg'))
case "red":
icon = QIcon(path.join(iconDir,'arch-red-symbolic-24.svg'))
case "green":
icon = QIcon(path.join(iconDir,'arch-green-symbolic-24.svg'))
case "purple":
icon = QIcon(path.join(iconDir,'arch-purple-symbolic-24.svg'))
case "yellow":
icon = QIcon(path.join(iconDir,'arch-yellow-symbolic-24.svg'))
case "black":
icon = QIcon(path.join(iconDir,'arch-black-symbolic-24.svg'))
case "gray":
icon = QIcon(path.join(iconDir,'arch-gray-symbolic-24.svg'))
case _:
icon = QIcon(path.join(path.expanduser("~/.config/systrayupdater/"),icn))
# Run checkupdates command
# Populates the available updates and count
# Sets the menu options, list and count in proper spots
def count():
cmd = ['checkupdates']
try:
p1 = subprocess.Popen(cmd,stdout=subprocess.PIPE)
outputList = ((p1.communicate()[0]).decode()).rstrip('\n')
outputCount = len(outputList.splitlines())
if outputCount == 0:
tray.setVisible(False)
else:
menu.clear()
menu.addAction(readNews)
menu.addAction(runUpdate)
menu.addAction(quit)
for i in outputList.splitlines():
menu.addAction(i, partial(infos, i))
avail = str(outputCount)+" Updates"
tray.setToolTip(avail)
tray.setVisible(True)
except subprocess.CalledProcessError:
tray.setVisible(False)
wait = 1800000
updateTimer.killTimer
updateTimer.start(wait)
print("Error: \'checkupdates\' command unable to retrieve updates\nSetting timer to 30mins\n")
# Read the News
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)
# Run system update
def update():
cmd = [ term, opt, 'sudo', 'pacman', '-Syu' ]
subprocess.Popen(cmd)
updateTimer.singleShot(1,count)
# Create an app surface
app = QApplication([])
app.setQuitOnLastWindowClosed(False)
# Set up timer
updateTimer = QTimer()
updateTimer.timeout.connect(count)
updateTimer.singleShot(1,count) # Initially populate available updates
updateTimer.start(wait)
# Creating the menu/options
menu = QMenu()
runUpdate = QAction("Run Update")
readNews = QAction("Read the News")
quit = QAction("Quit")
runUpdate.triggered.connect(update)
readNews.triggered.connect(news)
quit.triggered.connect(app.quit)
# Create applet and place menu in it
tray = QSystemTrayIcon()
tray.setIcon(icon)
tray.setVisible(True)
tray.setContextMenu(menu)
app.exec_()