22//! This example demonstrates multiple WebUI features working together
33const std = @import ("std" );
44const webui = @import ("webui" );
5+ const compat = @import ("compat" );
56
67const html = @embedFile ("index.html" );
78
@@ -148,7 +149,7 @@ fn getAppStatus(e: *webui.Event) void {
148149 var buffer : [1024 ]u8 = undefined ;
149150 const json = std .fmt .bufPrintZ (buffer [0.. ],
150151 \\{{"status":"running","users":{},"messages":{},"files":{},"port":{},"url":"{s}","clientId":{},"timestamp":{}}}
151- , .{ app_state .users_online , app_state .messages_sent , app_state .files_uploaded , port , url , e .client_id , std . time .timestamp () }) catch "{\" error\" :\" format_error\" }" ;
152+ , .{ app_state .users_online , app_state .messages_sent , app_state .files_uploaded , port , url , e .client_id , compat .timestamp () }) catch "{\" error\" :\" format_error\" }" ;
152153
153154 std .debug .print ("App Status - Users: {}, Messages: {}, Files: {}\n " , .{ app_state .users_online , app_state .messages_sent , app_state .files_uploaded });
154155
@@ -262,15 +263,15 @@ fn executeCommand(e: *webui.Event, command: [:0]const u8, args: [:0]const u8) vo
262263 if (std .mem .eql (u8 , command , "echo" )) {
263264 result = std .fmt .bufPrintZ (response [0.. ], "Echo: {s}" , .{args }) catch "Error" ;
264265 } else if (std .mem .eql (u8 , command , "time" )) {
265- const timestamp = std . time .timestamp ();
266+ const timestamp = compat .timestamp ();
266267 result = std .fmt .bufPrintZ (response [0.. ], "Current time: {}" , .{timestamp }) catch "Error" ;
267268 } else if (std .mem .eql (u8 , command , "random" )) {
268- var prng = std .Random .DefaultPrng .init (@intCast (std . time .timestamp ()));
269+ var prng = std .Random .DefaultPrng .init (@intCast (compat .timestamp ()));
269270 const random_num = prng .random ().int (u32 );
270271 result = std .fmt .bufPrintZ (response [0.. ], "Random number: {}" , .{random_num }) catch "Error" ;
271272 } else if (std .mem .eql (u8 , command , "memory" )) {
272273 // Simple memory info (simulated)
273- result = std .fmt .bufPrintZ (response [0.. ], "Memory usage: {}MB" , .{50 + @rem (std . time .timestamp (), 100 )}) catch "Error" ;
274+ result = std .fmt .bufPrintZ (response [0.. ], "Memory usage: {}MB" , .{50 + @rem (compat .timestamp (), 100 )}) catch "Error" ;
274275 } else {
275276 result = "Unknown command" ;
276277 }
@@ -282,15 +283,15 @@ fn getSystemInfo(e: *webui.Event) void {
282283 const builtin = @import ("builtin" );
283284
284285 var buffer : [1024 ]u8 = undefined ;
285- const info = std .fmt .bufPrintZ (buffer [0.. ],
286+ const info = std .fmt .bufPrintZ (buffer [0.. ],
286287 \\{{"os":"{s}","arch":"{s}","zigVersion":"{s}","webuiVersion":"2.5.0","timestamp":{}}}
287- , .{ @tagName (builtin .os .tag ), @tagName (builtin .cpu .arch ), @import ("builtin" ).zig_version_string , std . time .timestamp () }) catch "{}" ;
288+ , .{ @tagName (builtin .os .tag ), @tagName (builtin .cpu .arch ), @import ("builtin" ).zig_version_string , compat .timestamp () }) catch "{}" ;
288289
289290 e .returnString (info );
290291}
291292
292293fn testPerformance (e : * webui.Event , iterations : i64 , operation : [:0 ]const u8 ) void {
293- const start_time = std . time .nanoTimestamp ();
294+ const start_time = compat .nanoTimestamp ();
294295
295296 var i : i64 = 0 ;
296297 var result : u64 = 0 ;
@@ -306,7 +307,7 @@ fn testPerformance(e: *webui.Event, iterations: i64, operation: [:0]const u8) vo
306307 }
307308 }
308309
309- const end_time = std . time .nanoTimestamp ();
310+ const end_time = compat .nanoTimestamp ();
310311 const duration_ms = @as (f64 , @floatFromInt (end_time - start_time )) / 1_000_000.0 ;
311312
312313 var response : [256 ]u8 = undefined ;
0 commit comments