Exemplo n.º 1
0
        static void Main(string[] args)
        {
            // For a better startup expierience
            // I recommend to init the HostedContent in advance
            var hostedContent = new HostedContent();

            // Wrap the usage of the webview into a using block
            // Otherwise the native window will not get disposed correctly.
            // By setting the second parameter to true, sharpWebview intercepts
            // all external links and opens them in the system browser.
            using (var webview = new Webview(true, true))
            {
                webview
                // Set the title of the application window
                .SetTitle("The Lost Hitchhicker")
                // Set the start size of the window
                .SetSize(1024, 768, WebviewHint.None)
                // Set the minimum size of the window
                .SetSize(800, 600, WebviewHint.Min)
                // Bind a c# function to the webview - Accessible with the name "evalTest"
                .Bind("evalTest", (id, req) =>
                {
                    // Req contains the parameters of the javascript call
                    Console.WriteLine(req);
                    // And returns a successful promise result to the javascript function, which executed the 'evalTest'
                    webview.Return(id, RPCResult.Success, "{ result: 42 }");
                })
                // Navigate to this url on start
                .Navigate(hostedContent)
                // Run the webview loop
                .Run();
            }
        }
Exemplo n.º 2
0
 static void Main(string[] args)
 {
     // Wrap the usage of the webview into a using block
     // Otherwise the native window will not get disposed correctly
     using (var webview = new Webview(true))
     {
         webview
         // Set the title of the application window
         .SetTitle("The Hitchhicker")
         // Set the start size of the window
         .SetSize(1024, 768, WebviewHint.None)
         // Set the minimum size of the window
         .SetSize(800, 600, WebviewHint.Min)
         // This script gets executed after navigating to the url
         .InitScript("window.x = 42;")
         // Bind a c# function to the webview - Accessible with the name "evalTest"
         .Bind("evalTest", (id, req) =>
         {
             // Executes the javascript on the webview
             webview.Evaluate("console.log('The anwser is ' + window.x);");
             // And returns a successful promise result to the javascript function, which executed the 'evalTest'
             webview.Return(id, RPCResult.Success, "{ result: 'We always knew it!' }");
         })
         // Navigate to this url on start
         .Navigate(new UrlContent("https://en.wikipedia.org/wiki/The_Hitchhiker%27s_Guide_to_the_Galaxy_(novel)"))
         // Run the webview loop
         .Run();
     }
 }
Exemplo n.º 3
0
        private void DropCallback(string id, string req)
        {
            ClearCreateExtractionPath();

            var trimmedJsDataUrl = req.Trim(new char[] { '[', ']', '"' });
            var model3mf         = Model3MF.FromBase64DataUrl(trimmedJsDataUrl);

            model3mf.ExtractPrintProject(_extractionPath);

            _webview.Return(id, RPCResult.Success, "{ projectFolderUrl: '/extracted' }");
        }