Skip to content

Commit 5c88b08

Browse files
committed
headless mode
1 parent 3daa607 commit 5c88b08

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

api/app.py

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import threading
55
import sys
66
import os
7+
import argparse
78
from pathlib import Path
89

910
# Import modules
@@ -28,11 +29,12 @@
2829
class Application:
2930
"""Main application class"""
3031

31-
def __init__(self):
32+
def __init__(self, headless=False):
3233
self.server_thread = None
3334
self.tray = None
3435
self.qt_app = None
3536
self._missing_dependencies = None
37+
self.headless = headless
3638

3739
def start_server(self):
3840
"""Start the Flask server in a separate thread"""
@@ -98,37 +100,60 @@ def run(self):
98100
missing = download_manager.get_missing_dependencies()
99101
if missing:
100102
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")
103108
else:
104109
self._missing_dependencies = None
105110

106111
# Start server
107112
self.start_server()
108113

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")
114117
try:
115118
while True:
116119
import time
117120
time.sleep(1)
118121
except KeyboardInterrupt:
119122
print("\nShutting down...")
120123
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)
121137

122138

123139
def main():
124140
"""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+
125150
# Check if running on Windows (hide console if needed)
126151
if sys.platform == "win32":
127152
# On Windows, we might want to hide the console
128153
# But for debugging, we'll keep it visible
129154
pass
130155

131-
app_instance = Application()
156+
app_instance = Application(headless=args.headless)
132157
app_instance.run()
133158

134159

0 commit comments

Comments
 (0)