Skip to content

Commit af13586

Browse files
committed
Start tray icon as soon as possible for selected platforms
1 parent 3f5a29b commit af13586

File tree

9 files changed

+33
-15
lines changed

9 files changed

+33
-15
lines changed

library/stats.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@
1919
if HW_SENSORS == "PYTHON":
2020
import library.sensors.sensors_python as sensors
2121
elif HW_SENSORS == "LHM":
22-
import library.sensors.sensors_librehardwaremonitor as sensors
22+
if platform.system() == 'Windows':
23+
import library.sensors.sensors_librehardwaremonitor as sensors
24+
else:
25+
logger.error("LibreHardwareMonitor integration is only available on Windows")
26+
try:
27+
sys.exit(0)
28+
except:
29+
os._exit(0)
2330
elif HW_SENSORS == "STUB":
2431
import library.sensors.sensors_stub as sensors
2532
elif HW_SENSORS == "AUTO":

main.py

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# https://github.com/mathoudebine/turing-smart-screen-python
44
import locale
55
import os
6+
import platform
67
import signal
78
import sys
89
import time
@@ -47,7 +48,7 @@ def clean_stop(tray_icon=None):
4748

4849
logger.debug("(%.1fs)" % (5 - wait_time))
4950

50-
# Remove icon just before the exit
51+
# Remove tray icon just before exit
5152
if tray_icon:
5253
tray_icon.visible = False
5354

@@ -68,6 +69,26 @@ def on_exit_tray(tray_icon, item):
6869
clean_stop(tray_icon)
6970

7071

72+
# Create a tray icon for the program, with an Exit entry in menu
73+
try:
74+
tray_icon = pystray.Icon(
75+
name='Turing System Monitor',
76+
title='Turing System Monitor',
77+
icon=Image.open("res/icons/monitor-icon-17865/64.png"),
78+
menu=pystray.Menu(
79+
pystray.MenuItem(
80+
'Exit',
81+
on_exit_tray))
82+
)
83+
84+
# For platforms != macOS, display the tray icon now with non-blocking function
85+
if platform.system() != "Darwin":
86+
tray_icon.run_detached()
87+
logger.info("Tray icon has been displayed")
88+
except:
89+
tray_icon = None
90+
logger.warning("Tray icon is not supported on your platform")
91+
7192
# Set the signal handlers, to send a complete frame to the LCD before exit
7293
signal.signal(signal.SIGINT, sighandler)
7394
signal.signal(signal.SIGTERM, sighandler)
@@ -102,16 +123,6 @@ def on_exit_tray(tray_icon, item):
102123
scheduler.DateStats()
103124
scheduler.QueueHandler()
104125

105-
# Create a tray icon for the program, with an Exit entry in menu
106-
try:
107-
tray_icon = pystray.Icon(
108-
name='Turing System Monitor',
109-
title='Turing System Monitor',
110-
icon=Image.open("res/icons/724873501557740364-64.png"),
111-
menu=pystray.Menu(
112-
pystray.MenuItem(
113-
'Exit',
114-
on_exit_tray))
115-
).run()
116-
except:
117-
logger.warning("Tray icon is not supported on your platform")
126+
if tray_icon and platform.system() == "Darwin":
127+
# For macOS: display the tray icon now with blocking function
128+
tray_icon.run()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)