mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-16 02:02:58 -07:00
Refactor Windows system tray code
This commit is contained in:
parent
53cd759422
commit
f8f0717913
2 changed files with 62 additions and 48 deletions
|
@ -244,9 +244,9 @@ def main():
|
||||||
|
|
||||||
# Windows system tray icon
|
# Windows system tray icon
|
||||||
if common.PLATFORM == 'Windows':
|
if common.PLATFORM == 'Windows':
|
||||||
windows.set_startup()
|
|
||||||
if plexpy.CONFIG.WIN_SYS_TRAY:
|
if plexpy.CONFIG.WIN_SYS_TRAY:
|
||||||
windows.win_system_tray()
|
plexpy.WIN_SYS_TRAY_ICON = windows.WindowsSystemTray()
|
||||||
|
windows.set_startup()
|
||||||
elif common.PLATFORM == 'Darwin':
|
elif common.PLATFORM == 'Darwin':
|
||||||
macos.set_startup()
|
macos.set_startup()
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
import os
|
import os
|
||||||
import shlex
|
import shlex
|
||||||
import sys
|
import sys
|
||||||
|
from systray import SysTrayIcon
|
||||||
import winreg
|
import winreg
|
||||||
|
|
||||||
import plexpy
|
import plexpy
|
||||||
|
@ -31,72 +32,85 @@ else:
|
||||||
from plexpy import versioncheck
|
from plexpy import versioncheck
|
||||||
|
|
||||||
|
|
||||||
def win_system_tray():
|
class WindowsSystemTray(object):
|
||||||
from systray import SysTrayIcon
|
def __init__(self):
|
||||||
|
self.image_dir = os.path.join(plexpy.PROG_DIR, 'data/interfaces/', plexpy.CONFIG.INTERFACE, 'images')
|
||||||
|
|
||||||
def tray_open(sysTrayIcon):
|
if plexpy.UPDATE_AVAILABLE:
|
||||||
plexpy.launch_browser(plexpy.CONFIG.HTTP_HOST, plexpy.HTTP_PORT, plexpy.HTTP_ROOT)
|
self.icon = os.path.join(self.image_dir, 'logo-circle-update.ico')
|
||||||
|
self.hover_text = common.PRODUCT + ' - Update Available!'
|
||||||
|
else:
|
||||||
|
self.icon = os.path.join(self.image_dir, 'logo-circle.ico')
|
||||||
|
self.hover_text = common.PRODUCT
|
||||||
|
|
||||||
def tray_startup(sysTrayIcon):
|
|
||||||
plexpy.CONFIG.LAUNCH_STARTUP = not plexpy.CONFIG.LAUNCH_STARTUP
|
|
||||||
if plexpy.CONFIG.LAUNCH_STARTUP:
|
if plexpy.CONFIG.LAUNCH_STARTUP:
|
||||||
start_icon = os.path.join(image_dir, 'check-solid.ico')
|
start_icon = os.path.join(self.image_dir, 'check-solid.ico')
|
||||||
else:
|
else:
|
||||||
start_icon = None
|
start_icon = None
|
||||||
menu_options[2][1] = start_icon
|
|
||||||
plexpy.WIN_SYS_TRAY_ICON.update(menu_options=menu_options)
|
|
||||||
|
|
||||||
def tray_check_update(sysTrayIcon):
|
self.menu_options = [
|
||||||
|
['Open Tautulli', None, self.tray_open, 'default'],
|
||||||
|
['', None, 'separator', None],
|
||||||
|
['Start Tautulli at Login', start_icon, self.tray_startup, None],
|
||||||
|
['', None, 'separator', None],
|
||||||
|
['Check for Updates', None, self.tray_check_update, None],
|
||||||
|
['Update', None, self.tray_update, None],
|
||||||
|
['Restart', None, self.tray_restart, None]
|
||||||
|
]
|
||||||
|
|
||||||
|
self.sys_tray_icon = None
|
||||||
|
self.start()
|
||||||
|
|
||||||
|
def start(self):
|
||||||
|
logger.info("Launching system tray icon.")
|
||||||
|
try:
|
||||||
|
self.sys_tray_icon = SysTrayIcon(self.icon, self.hover_text, self.menu_options, on_quit=self.tray_quit)
|
||||||
|
self.sys_tray_icon.start()
|
||||||
|
except Exception as e:
|
||||||
|
logger.error("Unable to launch system tray icon: %s." % e)
|
||||||
|
|
||||||
|
def shutdown(self):
|
||||||
|
self.sys_tray_icon.shutdown()
|
||||||
|
|
||||||
|
def update(self, **kwargs):
|
||||||
|
self.sys_tray_icon.update(**kwargs)
|
||||||
|
|
||||||
|
def tray_open(self, sysTrayIcon):
|
||||||
|
plexpy.launch_browser(plexpy.CONFIG.HTTP_HOST, plexpy.HTTP_PORT, plexpy.HTTP_ROOT)
|
||||||
|
|
||||||
|
def tray_startup(self, sysTrayIcon):
|
||||||
|
plexpy.CONFIG.LAUNCH_STARTUP = not plexpy.CONFIG.LAUNCH_STARTUP
|
||||||
|
set_startup()
|
||||||
|
|
||||||
|
def tray_check_update(self, sysTrayIcon):
|
||||||
versioncheck.check_update()
|
versioncheck.check_update()
|
||||||
|
|
||||||
def tray_update(sysTrayIcon):
|
def tray_update(self, sysTrayIcon):
|
||||||
if plexpy.UPDATE_AVAILABLE:
|
if plexpy.UPDATE_AVAILABLE:
|
||||||
plexpy.SIGNAL = 'update'
|
plexpy.SIGNAL = 'update'
|
||||||
else:
|
else:
|
||||||
hover_text = common.PRODUCT + ' - No Update Available'
|
hover_text = common.PRODUCT + ' - No Update Available'
|
||||||
plexpy.WIN_SYS_TRAY_ICON.update(hover_text=hover_text)
|
self.update(hover_text=hover_text)
|
||||||
|
|
||||||
def tray_restart(sysTrayIcon):
|
def tray_restart(self, sysTrayIcon):
|
||||||
plexpy.SIGNAL = 'restart'
|
plexpy.SIGNAL = 'restart'
|
||||||
|
|
||||||
def tray_quit(sysTrayIcon):
|
def tray_quit(self, sysTrayIcon):
|
||||||
plexpy.SIGNAL = 'shutdown'
|
plexpy.SIGNAL = 'shutdown'
|
||||||
|
|
||||||
image_dir = os.path.join(plexpy.PROG_DIR, 'data/interfaces/', plexpy.CONFIG.INTERFACE, 'images')
|
def change_tray_startup_icon(self):
|
||||||
|
if plexpy.CONFIG.LAUNCH_STARTUP:
|
||||||
if plexpy.UPDATE_AVAILABLE:
|
start_icon = os.path.join(self.image_dir, 'check-solid.ico')
|
||||||
icon = os.path.join(image_dir, 'logo-circle-update.ico')
|
else:
|
||||||
hover_text = common.PRODUCT + ' - Update Available!'
|
start_icon = None
|
||||||
else:
|
self.menu_options[2][1] = start_icon
|
||||||
icon = os.path.join(image_dir, 'logo-circle.ico')
|
self.update(menu_options=self.menu_options)
|
||||||
hover_text = common.PRODUCT
|
|
||||||
|
|
||||||
if plexpy.CONFIG.LAUNCH_STARTUP:
|
|
||||||
start_icon = os.path.join(image_dir, 'check-solid.ico')
|
|
||||||
else:
|
|
||||||
start_icon = None
|
|
||||||
|
|
||||||
menu_options = [
|
|
||||||
['Open Tautulli', None, tray_open, 'default'],
|
|
||||||
['', None, 'separator', None],
|
|
||||||
['Start Tautulli at Login', start_icon, tray_startup, None],
|
|
||||||
['', None, 'separator', None],
|
|
||||||
['Check for Updates', None, tray_check_update, None],
|
|
||||||
['Update', None, tray_update, None],
|
|
||||||
['Restart', None, tray_restart, None]
|
|
||||||
]
|
|
||||||
|
|
||||||
logger.info("Launching system tray icon.")
|
|
||||||
|
|
||||||
try:
|
|
||||||
plexpy.WIN_SYS_TRAY_ICON = SysTrayIcon(icon, hover_text, menu_options, on_quit=tray_quit)
|
|
||||||
plexpy.WIN_SYS_TRAY_ICON.start()
|
|
||||||
except Exception as e:
|
|
||||||
logger.error("Unable to launch system tray icon: %s." % e)
|
|
||||||
plexpy.WIN_SYS_TRAY_ICON = None
|
|
||||||
|
|
||||||
|
|
||||||
def set_startup():
|
def set_startup():
|
||||||
|
if plexpy.WIN_SYS_TRAY_ICON:
|
||||||
|
plexpy.WIN_SYS_TRAY_ICON.change_tray_startup_icon()
|
||||||
|
|
||||||
startup_reg_path = "Software\\Microsoft\\Windows\\CurrentVersion\\Run"
|
startup_reg_path = "Software\\Microsoft\\Windows\\CurrentVersion\\Run"
|
||||||
|
|
||||||
exe = sys.executable
|
exe = sys.executable
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue