Skip to content

Commit ec90caf

Browse files
committed
fix: improvement: menu bar title
1 parent 74a7b60 commit ec90caf

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

airq/app.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def update_status(self, data):
6363
# sensor values
6464
values = data[0]
6565
formatted_values = {}
66+
warning_values = []
6667
for key, label in consts.LABELS.items():
6768
warningColor = None
6869
if key == consts.KEY_SEPARATOR:
@@ -84,13 +85,14 @@ def update_status(self, data):
8485
self.menu[key].title = new_title
8586
formatted_values[key] = new_title
8687

87-
# if key in self.warns:
8888
if warningColor == 'yellow':
8989
color = NSColor.colorWithCalibratedRed_green_blue_alpha_(204/255, 204/255, 0, 1)
9090
font = NSFont.fontWithName_size_("Courier-Bold", 14.0)
91+
warning_values = warning_values + [new_title]
9192
elif warningColor == 'red':
9293
color = NSColor.colorWithCalibratedRed_green_blue_alpha_(1, 0, 0, 1)
9394
font = NSFont.fontWithName_size_("Courier-Bold", 14.0)
95+
warning_values = [new_title] + warning_values
9496
else:
9597
color = NSColor.colorWithCalibratedRed_green_blue_alpha_(0, 186.0/255, 44.0/255, 1)
9698
font = NSFont.fontWithName_size_("Courier", 14.0)
@@ -102,11 +104,16 @@ def update_status(self, data):
102104
string = NSAttributedString.alloc().initWithString_attributes_(new_title, attributes)
103105
self.menu[key]._menuitem.setAttributedTitle_(string)
104106

107+
# use the major changers as the second info
108+
warned_sensor = ''
109+
if warning_values:
110+
warned_sensor = self.strip_sensor_name(warning_values[0])
111+
105112
title_format = consts.DEFAULT_TITLE_FORMAT
106113
self.title = title_format.format(
107114
icon=new_icon,
108-
temp=self.strip_sensor_name(formatted_values[consts.KEY_TEMP]),
109-
co2=self.strip_sensor_name(formatted_values[consts.KEY_CO2])
115+
temp=self.strip_sensor_name(formatted_values[consts.KEY_TEMP].replace(" ", "").split("/")[0]),
116+
hisensor=self.strip_sensor_name(warned_sensor)
110117
)
111118

112119
@rumps.clicked("Debug")
@@ -118,4 +125,4 @@ def debug(self, sender):
118125
).run()
119126

120127
def strip_sensor_name(self, formatted_value):
121-
return " ".join(formatted_value.split(" ")[-2:])
128+
return (" ".join(formatted_value.split(" ")[-2:])).replace(" ", "")

airq/consts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
KEY_LASTFETCH = "lastfetch"
1313
KEY_SEPARATOR = "separator"
1414

15-
DEFAULT_TITLE_FORMAT = "{icon} {temp} / {co2}"
15+
DEFAULT_TITLE_FORMAT = "{icon} {temp} {hisensor}"
1616

1717
LABELS = {
1818
KEY_CO: " CO: {} ppm",

airq/storage

386 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)