public IPC(PhotinoWindow photinoWindow) { _photinoWindow = photinoWindow ?? throw new ArgumentNullException(nameof(photinoWindow)); _photinoWindow.OnWebMessageReceived += HandleScriptNotify; }
public PhotinoSynchronizationContext(PhotinoWindow window) : this(window, new State()) { }
static void Main(string[] args) { // Window title declared here for visibility string windowTitle = "Photino.Vue Demo App"; // Define the PhotinoWindow options. Some handlers // can only be registered before a PhotinoWindow instance // is initialized. Currently there are three handlers // that must be defined here. Action <PhotinoWindowOptions> windowConfiguration = options => { // Custom scheme handlers can only be registered during // initialization of a PhotinoWindow instance. options.CustomSchemeHandlers.Add("app", (string url, out string contentType) => { contentType = "text/javascript"; return(new MemoryStream(Encoding.UTF8.GetBytes(@" (() =>{ window.setTimeout(() => { alert(`🎉 Dynamically inserted JavaScript.`); }, 1000); })(); "))); }); // Window creating and created handlers can only be // registered during initialization of a PhotinoWindow instance. // These handlers are fired before and after the native constructor // method is called. options.WindowCreatingHandler += (object sender, EventArgs args) => { var window = (PhotinoWindow)sender; // Instance is not initialized at this point. Class properties are not set yet. Console.WriteLine($"Creating new PhotinoWindow instance."); }; options.WindowCreatedHandler += (object sender, EventArgs args) => { var window = (PhotinoWindow)sender; // Instance is initialized. Class properties are now set and can be used. Console.WriteLine($"Created new PhotinoWindow instance with title {window.Title}."); }; }; // Creating a new PhotinoWindow instance with the fluent API var window = new PhotinoWindow(windowTitle, windowConfiguration) // Resize to a percentage of the main monitor work area .Resize(50, 50, "%") // Center window in the middle of the screen .Center() // Users can resize windows by default. // Let's make this one fixed instead. .UserCanResize(false) // Most event handlers can be registered after the // PhotinoWindow was instantiated by calling a registration // method like the following RegisterWebMessageReceivedHandler. // This could be added in the PhotinoWindowOptions if preferred. .RegisterWebMessageReceivedHandler((object sender, string message) => { var window = (PhotinoWindow)sender; // The message argument is coming in from sendMessage. // "window.external.sendMessage(message: string)" string response = $"Received message: \"{message}\""; // Send a message back the to JavaScript event handler. // "window.external.receiveMessage(callback: Function)" window.SendWebMessage(response); }) .Load("wwwroot/index.html"); // Can be used with relative path strings or "new URI()" instance to load a website. window.WaitForClose(); // Starts the application event loop }
private static void MessageReceivedFromWindow(object sender, string message) { Log(sender, $"MessageRecievedFromWindow Callback Fired."); var currentWindow = sender as PhotinoWindow; if (string.Compare(message, "child-window", true) == 0) { var iconFile = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "wwwroot/photino-logo.ico" : "wwwroot/photino-logo.png"; var x = new PhotinoWindow(currentWindow) .SetTitle($"Child Window {_windowNumber++}") //.SetIconFile(iconFile) .Load("wwwroot/main.html") .SetUseOsDefaultLocation(true) .SetHeight(600) .SetWidth(800) .SetGrantBrowserPermissions(false) .RegisterWindowCreatingHandler(WindowCreating) .RegisterWindowCreatedHandler(WindowCreated) .RegisterLocationChangedHandler(WindowLocationChanged) .RegisterSizeChangedHandler(WindowSizeChanged) .RegisterWebMessageReceivedHandler(MessageReceivedFromWindow) .RegisterWindowClosingHandler(WindowIsClosing) .RegisterCustomSchemeHandler("app", AppCustomSchemeUsed) .SetTemporaryFilesPath(currentWindow.TemporaryFilesPath) .SetLogVerbosity(_logEvents ? 2 : 0); x.WaitForClose(); //x.Center(); //WaitForClose() is non-blocking for child windows //x.SetHeight(800); //x.Close(); } else if (string.Compare(message, "zoom-in", true) == 0) { currentWindow.Zoom += 5; Log(sender, $"Zoom: {currentWindow.Zoom}"); } else if (string.Compare(message, "zoom-out", true) == 0) { currentWindow.Zoom -= 5; Log(sender, $"Zoom: {currentWindow.Zoom}"); } else if (string.Compare(message, "center", true) == 0) { currentWindow.Center(); } else if (string.Compare(message, "close", true) == 0) { currentWindow.Close(); } else if (string.Compare(message, "minimize", true) == 0) { currentWindow.SetMinimized(!currentWindow.Minimized); } else if (string.Compare(message, "maximize", true) == 0) { currentWindow.SetMaximized(!currentWindow.Maximized); } else if (string.Compare(message, "setcontextmenuenabled", true) == 0) { currentWindow.SetContextMenuEnabled(!currentWindow.ContextMenuEnabled); } else if (string.Compare(message, "setdevtoolsenabled", true) == 0) { currentWindow.SetDevToolsEnabled(!currentWindow.DevToolsEnabled); } else if (string.Compare(message, "setgrantbrowserpermissions", true) == 0) { currentWindow.SetGrantBrowserPermissions(!currentWindow.GrantBrowserPermissions); } else if (string.Compare(message, "seticonfile", true) == 0) { var iconFile = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "wwwroot/photino-logo.ico" : "wwwroot/photino-logo.png"; currentWindow.SetIconFile(iconFile); } else if (string.Compare(message, "setposition", true) == 0) { currentWindow.SetLeft(currentWindow.Left + 5); currentWindow.SetTop(currentWindow.Top + 5); } else if (string.Compare(message, "setresizable", true) == 0) { currentWindow.SetResizable(!currentWindow.Resizable); } else if (string.Compare(message, "setsize-up", true) == 0) { currentWindow.SetHeight(currentWindow.Height + 5); currentWindow.SetWidth(currentWindow.Width + 5); } else if (string.Compare(message, "setsize-down", true) == 0) { currentWindow.SetHeight(currentWindow.Height - 5); currentWindow.SetWidth(currentWindow.Width - 5); } else if (string.Compare(message, "settitle", true) == 0) { currentWindow.SetTitle(currentWindow.Title + "*"); } else if (string.Compare(message, "settopmost", true) == 0) { currentWindow.SetTopMost(!currentWindow.Topmost); } else if (string.Compare(message, "setfullscreen", true) == 0) { currentWindow.SetFullScreen(!currentWindow.FullScreen); } else if (string.Compare(message, "showproperties", true) == 0) { var properties = GetPropertiesDisplay(currentWindow); currentWindow.OpenAlertWindow("Settings", properties); } else if (string.Compare(message, "sendWebMessage", true) == 0) { currentWindow.SendWebMessage("alert('web message');"); } else if (string.Compare(message, "toastNotification", true) == 0) { currentWindow.SendNotification("Toast Title", " Taoast message!"); } else { throw new Exception($"Unknown message '{message}'"); } }
public static void Run <TStartup>(string windowTitle, string hostHtmlPath, bool fullscreen = false, int x = 0, int y = 0, int width = 800, int height = 600) { photinoWindow = new PhotinoWindow(windowTitle, StandardOptions(hostHtmlPath), width, height, x, y, fullscreen); Run <TStartup>(photinoWindow); }