|
4 | 4 | import threading |
5 | 5 | import sys |
6 | 6 | import os |
| 7 | +import argparse |
7 | 8 | from pathlib import Path |
8 | 9 |
|
9 | 10 | # Import modules |
|
28 | 29 | class Application: |
29 | 30 | """Main application class""" |
30 | 31 |
|
31 | | - def __init__(self): |
| 32 | + def __init__(self, headless=False): |
32 | 33 | self.server_thread = None |
33 | 34 | self.tray = None |
34 | 35 | self.qt_app = None |
35 | 36 | self._missing_dependencies = None |
| 37 | + self.headless = headless |
36 | 38 |
|
37 | 39 | def start_server(self): |
38 | 40 | """Start the Flask server in a separate thread""" |
@@ -98,37 +100,60 @@ def run(self): |
98 | 100 | missing = download_manager.get_missing_dependencies() |
99 | 101 | if missing: |
100 | 102 | print(f"Warning: Missing dependencies: {', '.join(missing)}") |
101 | | - # Store missing dependencies to show dialog after Qt app is initialized |
102 | | - self._missing_dependencies = missing |
| 103 | + if not self.headless: |
| 104 | + # Store missing dependencies to show dialog after Qt app is initialized |
| 105 | + self._missing_dependencies = missing |
| 106 | + else: |
| 107 | + print("Running in headless mode - dependency warnings will not be shown in GUI") |
103 | 108 | else: |
104 | 109 | self._missing_dependencies = None |
105 | 110 |
|
106 | 111 | # Start server |
107 | 112 | self.start_server() |
108 | 113 |
|
109 | | - # Start system tray (if available) - this will run the Qt event loop |
110 | | - if TRAY_AVAILABLE: |
111 | | - self.start_tray() |
112 | | - else: |
113 | | - # If no tray, just wait for keyboard interrupt |
| 114 | + # In headless mode, skip GUI and tray |
| 115 | + if self.headless: |
| 116 | + print("Running in headless mode - no GUI will be displayed") |
114 | 117 | try: |
115 | 118 | while True: |
116 | 119 | import time |
117 | 120 | time.sleep(1) |
118 | 121 | except KeyboardInterrupt: |
119 | 122 | print("\nShutting down...") |
120 | 123 | sys.exit(0) |
| 124 | + else: |
| 125 | + # Start system tray (if available) - this will run the Qt event loop |
| 126 | + if TRAY_AVAILABLE: |
| 127 | + self.start_tray() |
| 128 | + else: |
| 129 | + # If no tray, just wait for keyboard interrupt |
| 130 | + try: |
| 131 | + while True: |
| 132 | + import time |
| 133 | + time.sleep(1) |
| 134 | + except KeyboardInterrupt: |
| 135 | + print("\nShutting down...") |
| 136 | + sys.exit(0) |
121 | 137 |
|
122 | 138 |
|
123 | 139 | def main(): |
124 | 140 | """Main entry point""" |
| 141 | + # Parse command line arguments |
| 142 | + parser = argparse.ArgumentParser(description="SpiceDL API Server") |
| 143 | + parser.add_argument( |
| 144 | + "--headless", |
| 145 | + action="store_true", |
| 146 | + help="Run in headless mode without GUI or system tray" |
| 147 | + ) |
| 148 | + args = parser.parse_args() |
| 149 | + |
125 | 150 | # Check if running on Windows (hide console if needed) |
126 | 151 | if sys.platform == "win32": |
127 | 152 | # On Windows, we might want to hide the console |
128 | 153 | # But for debugging, we'll keep it visible |
129 | 154 | pass |
130 | 155 |
|
131 | | - app_instance = Application() |
| 156 | + app_instance = Application(headless=args.headless) |
132 | 157 | app_instance.run() |
133 | 158 |
|
134 | 159 |
|
|
0 commit comments