예제 #1
0
        private void LoadHtmlInWebview()
        {
#if DEBUG
            // NavigateToString uses a data URI and so the JavaScript source is not available in the developer tools panel
            // when errors occur. Writing to a real file on disk avoids this problem in Debug builds.
            string tempDir       = Environment.GetEnvironmentVariable("TEMP");
            string debugHtmlFile = System.IO.Path.Combine(tempDir, "u3-debug.html");
            System.IO.File.WriteAllText(debugHtmlFile, JsResourceUtil.GetU3Source());
            this.webview.CoreWebView2.Navigate("file:///" + debugHtmlFile.Replace('\\', '/'));
#else
            this.webview.NavigateToString(JsResourceUtil.GetU3Source());
#endif
        }
예제 #2
0
        internal override async Task <string> CreateAndShowWindowImpl(
            string title,
            byte[] nullableIcon,
            int width,
            int height,
            Func <string, string, bool> handleVmBoundMessage)
        {
            System.Net.Sockets.Socket socket = new System.Net.Sockets.Socket(
                System.Net.Sockets.AddressFamily.Unix,
                System.Net.Sockets.SocketType.Stream,
                System.Net.Sockets.ProtocolType.Unspecified);
            socket.Bind(new System.Net.Sockets.UnixDomainSocketEndPoint(this.filePath + "_us"));
            socket.Listen(1);
            System.ComponentModel.BackgroundWorker bgworker = new System.ComponentModel.BackgroundWorker();
            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            bgworker.DoWork += async(e, sender) =>
            {
                System.Net.Sockets.Socket s = socket.Accept();
                SocketReader sr             = new SocketReader(s);
                while (true)
                {
                    int    length  = sr.ReadLength();
                    string data    = sr.ReadString(length);
                    int    colon   = data.IndexOf(':');
                    string type    = colon == -1 ? data : data.Substring(0, colon);
                    string payload = colon == -1 ? "" : data.Substring(colon + 1);

                    if (type == "READY")
                    {
                        StartSocketClient();
                        await this.SendString("SRC", JsResourceUtil.GetU3Source());
                    }
                    else if (type == "VMJSON")
                    {
                        IDictionary <string, object> jsonPayload = new Wax.Util.JsonParser(payload.Substring(1, payload.Length - 2)).ParseAsDictionary();
                        handleVmBoundMessage((string)jsonPayload["type"], (string)jsonPayload["message"]);
                    }
                    else
                    {
                        throw new Exception("Unknown message type: " + type);
                    }
                }
            };

            bgworker.RunWorkerAsync();

            await Task.Delay(TimeSpan.FromMilliseconds(10));

            return(await RunProcess(title, width, height)); // Process ends when window is closed.
        }