export class HubHeadlessMode {
    deps;
    resolveRun;
    stopped = false;
    constructor(deps) {
        this.deps = deps;
    }
    async run() {
        const view = this.deps.getView();
        console.log(`D-Pi hub listening on ${view.address}`);
        console.log(`Public org dashboard: ${view.address}/`);
        console.log(`Agent Web UI: ${view.address}/agents/root`);
        if (view.rootToken) {
            console.warn(`Root token: ${view.rootToken}`);
            console.warn("Root token is shown once; store it securely.");
        }
        this.registerSignals();
        return new Promise((resolve) => {
            this.resolveRun = resolve;
        });
    }
    async stop() {
        if (this.stopped) {
            return;
        }
        this.stopped = true;
        this.unregisterSignals();
        this.resolveRun?.(0);
    }
    handleSignal = () => {
        void this.stop();
    };
    registerSignals() {
        process.once("SIGINT", this.handleSignal);
        process.once("SIGTERM", this.handleSignal);
    }
    unregisterSignals() {
        process.off("SIGINT", this.handleSignal);
        process.off("SIGTERM", this.handleSignal);
    }
}
//# sourceMappingURL=hub-headless-mode.js.map