Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Text;
- using System.Drawing;
- using System.Threading;
- using System.Runtime.InteropServices;
- using PhotinoNET;
- using static System.Threading.Thread;
- using static System.Runtime.InteropServices.RuntimeInformation;
- // ===== You really only need this part =====
- if (IsOSPlatform(OSPlatform.Windows)
- && CurrentThread.GetApartmentState() != ApartmentState.STA)
- {
- if (!CurrentThread.TrySetApartmentState(ApartmentState.Unknown)
- || !CurrentThread.TrySetApartmentState(ApartmentState.STA))
- {
- throw new Exception("Unable to set ApartmentState.STA");
- }
- }
- // ==========================================
- PhotinoWindow window = new PhotinoWindow()
- {
- Title = "Photino for .NET Demo App",
- UseOsDefaultSize = false,
- Size = new Size(1280, 720),
- Centered = true,
- Resizable = true,
- }
- .RegisterCustomSchemeHandler("app", (object sender, string scheme, string url, out string contentType) =>
- {
- contentType = "text/javascript";
- return new MemoryStream(
- Encoding.UTF8.GetBytes(
- @"(() => window.setTimeout(() => alert(`🎉 Dynamically inserted JavaScript.`), 1000))();"));
- })
- .RegisterWebMessageReceivedHandler((object sender, string message) =>
- {
- PhotinoWindow window = sender as PhotinoWindow;
- string response = $"Received message: \"{message}\"";
- window.SendWebMessage(response);
- })
- .Load("wwwroot/index.html");
- window.WaitForClose();
Advertisement