| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- 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<StatumModule>();
- var statum = application.configure_with<StatumConfigurator>();
- // HomePage is generated from home.html; HomeEntrypoint hydrates it and
- // embeds the login/bump action references. Routes come from each page's
- // <pstm-uri>; actions are auto-mapped to GUID endpoints; the Statum
- // client scripts are embedded by default.
- statum.add_page<HomePage, HomeEntrypoint>();
- statum.add_page<DashboardPage, DashboardEntrypoint>();
- statum.action<LoginAction>();
- statum.action<LogoutAction>();
- statum.action<BumpCounterAction>();
- statum.action<UpdateAnnouncementAction>();
- statum.add_resource<StylesResource>();
- // Register a global broadcast slot (deterministic key "global:announcement").
- var announcement = new AnnouncementPublic();
- announcement.text = "Welcome to the Statum demo!";
- statum.global<AnnouncementPublic>("announcement", 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);
- } 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);
- }
- }
|