using Astralis; using Invercargill.DataStructures; using Inversion; using Statum; using Example; void main(string[] args) { int port = args.length > 1 ? int.parse(args[1]) : 8080; try { var application = new WebApplication(port); application.use_compression(); application.add_module(); var statum = application.configure_with(); // HomePage is generated from home.html; HomeEntrypoint hydrates it and // embeds the login/bump action references. Routes come from each page's // ; actions are auto-mapped to GUID endpoints; the Statum // client scripts are embedded by default. statum.add_page(); statum.add_page(); statum.action(); statum.action(); statum.action(); statum.action(); statum.add_resource(); // Register a global broadcast slot (deterministic key "global:announcement"). var announcement = new AnnouncementPublic(); announcement.text = "Welcome to the Statum demo!"; statum.global("announcement", announcement); // Register a topic + modifier: when triggered, derives a short preview // from the current announcement and pushes it to watching clients. statum.topic("announcement"); statum.topic_modifier("announcement"); // Background timer: cycle the announcement every 10 seconds. Every // subscribed tab receives the update via the SSE push — open two tabs // side by side to see the broadcast in action. string[] messages = { "Welcome to the Statum demo!", "Slots are client-carried and signed.", "Try logging in as \"admin\".", "Global slots use deterministic keys for broadcast.", "The counter uses typed models with action references." }; int msg_index = 0; Timeout.add_seconds(10, () => { msg_index = (msg_index + 1) % messages.length; try { var model = new AnnouncementPublic(); model.text = messages[msg_index]; var state = new State() { type_name = "announcement", public_data = GObjectMapping.to_properties(model), private_data = new PropertyDictionary() }; statum.state_service.update_global.begin("announcement", state); // Trigger the topic so derived "preview" slots update too. statum.topic_registry.trigger.begin("announcement:latest", () => { stderr.printf("[topic] trigger completed\n"); }); } catch (GLib.Error e) { warning("Failed to update announcement: %s", e.message); } return true; }); application.run(); } catch (Error e) { printerr("Error: %s\n", e.message); Process.exit(1); } }