51 lines
1.5 KiB
C#
51 lines
1.5 KiB
C#
using System.Text.Json;
|
|
using Photino.NET;
|
|
|
|
namespace Ecluse.Host;
|
|
|
|
internal static class Program
|
|
{
|
|
[STAThread]
|
|
private static void Main(string[] args)
|
|
{
|
|
// Mode dev : `dotnet run -- --dev` pointe la fenêtre sur le serveur Vite
|
|
// (hot reload). Sans l'argument : charge le build local depuis wwwroot.
|
|
#if DEBUG
|
|
bool dev = true;
|
|
#else
|
|
bool dev = args.Contains("--dev");
|
|
#endif
|
|
|
|
var window = new PhotinoWindow()
|
|
.SetTitle("Écluse")
|
|
.SetMaximized(true)
|
|
.Center()
|
|
.SetResizable(true)
|
|
// Handler du pont : tout message JS -> C# arrive ici.
|
|
.RegisterWebMessageReceivedHandler(OnWebMessage);
|
|
|
|
if (dev)
|
|
window.Load("http://localhost:5173/");
|
|
else
|
|
// Résolu relativement à l'exe (wwwroot copié à côté). Nécessite base:'./' dans Vite.
|
|
window.Load("wwwroot/index.html");
|
|
|
|
window.WaitForClose();
|
|
}
|
|
|
|
// Écho minimal pour prouver le pont dans les deux sens. Le vrai routage
|
|
// (RunPreflight, DecryptBitLocker, ...) viendra avec le contrat du pont.
|
|
private static void OnWebMessage(object? sender, string message)
|
|
{
|
|
var window = (PhotinoWindow)sender!;
|
|
|
|
var reponse = JsonSerializer.Serialize(new
|
|
{
|
|
type = "echo",
|
|
recu = message,
|
|
os = OperatingSystem.IsWindows() ? "windows" : "linux",
|
|
});
|
|
|
|
window.SendWebMessage(reponse);
|
|
}
|
|
}
|