Files
notification-service/Sources/NotificationService/main.swift
T
2026-07-06 01:17:30 +08:00

55 lines
1.4 KiB
Swift

import Foundation
import AppKit
// MARK: - Entry point
let args = CommandLine.arguments
let command = args.count > 1 ? args[1] : "run"
switch command {
case "install":
LaunchAgent.install()
case "uninstall":
LaunchAgent.uninstall()
case "run":
runService()
case "-h", "--help", "help":
printUsage()
default:
FileHandle.standardError.write(("Unknown command: \(command)\n").data(using: .utf8)!)
printUsage()
exit(2)
}
func runService() {
let app = NSApplication.shared
// Accessory = no Dock icon, no menu bar app; just a background listener
// that can surface modal windows.
app.setActivationPolicy(.accessory)
let delegate = AppDelegate()
app.delegate = delegate
app.run()
}
func printUsage() {
let prog = (CommandLine.arguments[0] as NSString).lastPathComponent
print("""
notification-service — local modal-notification HTTP server
Usage:
\(prog) run Start the server (listens on http://127.0.0.1:11270)
\(prog) install Install as a per-user LaunchAgent (starts at login)
\(prog) uninstall Remove the LaunchAgent and binary
\(prog) help Show this help
API:
POST /api/v1/show
{ "title": "Window title", "content": "Body text" }
Example:
curl -X POST http://127.0.0.1:11270/api/v1/show \\
-H 'Content-Type: application/json' \\
-d '{"title":"Hello","content":"World"}'
""")
}