feat: initial release - mobile-first web terminal with tmux touch toolbar and push notifications
This commit is contained in:
Executable
+37
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Tiny HTTP server for terminal notifications. Serves /api/notifications."""
|
||||
import http.server
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
|
||||
NOTIFY_FILE = "/tmp/kitty-notify"
|
||||
PORT = 7682
|
||||
|
||||
class Handler(http.server.BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
if self.path == "/api/notifications":
|
||||
msg = ""
|
||||
if os.path.exists(NOTIFY_FILE):
|
||||
try:
|
||||
mtime = os.path.getmtime(NOTIFY_FILE)
|
||||
if time.time() - mtime < 30: # only show notifications < 30s old
|
||||
with open(NOTIFY_FILE) as f:
|
||||
msg = f.read().strip()
|
||||
except:
|
||||
pass
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "application/json")
|
||||
self.send_header("Access-Control-Allow-Origin", "*")
|
||||
self.end_headers()
|
||||
self.wfile.write(json.dumps({"message": msg}).encode())
|
||||
else:
|
||||
self.send_response(404)
|
||||
self.end_headers()
|
||||
|
||||
def log_message(self, format, *args):
|
||||
pass # quiet
|
||||
|
||||
if __name__ == "__main__":
|
||||
server = http.server.HTTPServer(("0.0.0.0", PORT), Handler)
|
||||
server.serve_forever()
|
||||
Reference in New Issue
Block a user