Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
56 lines (53 loc) · 2.32 KB
/
Copy pathProgram.cs
File metadata and controls
56 lines (53 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// ---------------------------------------------------------------------------------------------------------------------
// Imports
// ---------------------------------------------------------------------------------------------------------------------
using InfiniFrame;
using System.Drawing;
using InfiniFrame.Application;
using InfiniFrame.WebServer;
namespace InfiniFrameExample.WebApp.React;
// ---------------------------------------------------------------------------------------------------------------------
// Code
// ---------------------------------------------------------------------------------------------------------------------
public static class Program {
private sealed class WebMessageCounter {
private int _count;
public int Increment() => Interlocked.Increment(ref _count);
}
[STAThread]
public static void Main(string[] args) {
InfiniFrameApplicationBuilder rootBuilder = InfiniFrameApplication.CreateBuilder(args);
rootBuilder.Services.AddSingleton<WebMessageCounter>();
InfiniFrameApplication application = rootBuilder
.WithWindow(window => window
.UseOsDefaultSize(false)
.SetResizable()
.CenteredOnMainMonitor()
.SetTitle("InfiniLore InfiniFrame.NET REACT Sample")
.SetSize(new Size(800, 600))
.RegisterCustomSchemeHandler("app", handler: (_, _) => (
new MemoryStream([
.. """
(() =>{
window.setTimeout(() => {
alert(`🎉 Dynamically inserted JavaScript.`);
}, 1000);
})();
"""u8
])
, "text/javascript")
)
.RegisterWebMessageReceivedHandler((IInfiniFrameWindow infiniFrameWindow, string message, WebMessageCounter counter) => {
int count = counter.Increment();
string response = $"[{count}] Received message: \"{message}\"";
infiniFrameWindow.SendWebMessage(response);
}))
.UseWebServer(builder => {
builder.ConfigureWebApplication(webApp => {
webApp.MapStaticAssets();
});
})
.Build();
application.Run();
}
}