#!/usr/bin/env python3 """DaemonControl - System Tray Mode. Usage: python start_tray.py Starts DaemonControl with system tray icon. Daemon runs in background, controllable via tray menu. The tray icon provides a convenient way to: - Start/stop the daemon - Reload job configurations - Access logs quickly - Monitor daemon status """ import sys from PyQt6.QtWidgets import QApplication, QSystemTrayIcon def check_system_tray_available() -> bool: """Check if system tray is available. Returns: True if system tray is supported, False otherwise """ if not QSystemTrayIcon.isSystemTrayAvailable(): print("=" * 70) print("ERROR: System Tray Not Available") print("=" * 70) print() print("Your desktop environment does not support system tray icons.") print() print("Possible solutions:") print(" 1. Install AppIndicator extension (GNOME)") print(" 2. Use KDE Plasma, XFCE, or Cinnamon desktop") print(" 3. Use foreground mode instead:") print(" python3 start_daemon.py") print() return False return True def main(): """Main entry point for tray application.""" # Create QApplication first (needed for system tray check) app = QApplication(sys.argv) # Check if system tray is available if not check_system_tray_available(): sys.exit(1) # Import after Qt app is created from gui import SystemTrayApp # Important: Keep app running even when no windows are open app.setQuitOnLastWindowClosed(False) print("=" * 70) print(" DaemonControl - System Tray Mode") print("=" * 70) print() print("System tray icon started successfully") print() print("Look for the DaemonControl icon in your system tray.") print("Right-click the icon to see the menu.") print() print("Menu options:") print(" • Start Daemon - Start background daemon") print(" • Stop Daemon - Stop daemon gracefully") print(" • Reload Jobs - Reload job configurations") print(" • Open Logs - Open logs folder") print(" • Exit - Close tray and stop daemon") print() print("Press Ctrl+C here or use 'Exit' from menu to quit") print() # Create and show system tray tray_app = SystemTrayApp() tray_app.show() # Run application event loop sys.exit(app.exec()) if __name__ == '__main__': try: main() except KeyboardInterrupt: print("\nShutdown requested by user") sys.exit(0) except Exception as e: print(f"\nERROR: {e}") import traceback traceback.print_exc() sys.exit(1)