Esempio 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();
            }
        }
 public List <DesignablePropertyDescriptor> GetDesignProperties()
 {
     if (null != HostedContent)
     {
         return(HostedContent.GetDesignProperties());
     }
     return(null);
 }
Esempio n. 3
0
        public void Run(FileInfo model)
        {
            var is3MF = model?.Extension.ToUpper() == ".3MF";

            if (model == null || is3MF)
            {
                // System.CommandLine parses and executes the CLI arguments
                // in a new Task. Because of this, it is necessary to execute
                // a new STA Thread to run the webview. Will throw exceptions otherwise.
                Thread thread = new Thread(() =>
                {
                    var initScript =
                        @"window.printProject = {};
                        window.printProject.dropCallback = dropCallback;";
                    if (is3MF)
                    {
                        ClearCreateExtractionPath();
                        var model3mf = new Model3MF(model.FullName);
                        model3mf.ExtractPrintProject(_extractionPath);
                        initScript += "window.printProject.projectFolderUrl='/extracted';";
                    }

                    var hostedContent = new HostedContent();
                    using (_webview = new Webview(false, true))
                    {
                        _webview
                        .SetTitle("3D2P")
                        .SetSize(1024, 800, WebviewHint.None)
                        .SetSize(800, 800, WebviewHint.Min)
                        .Bind("dropCallback", DropCallback)
                        .InitScript(initScript)
                        .Navigate(hostedContent)
                        .Run();
                    }
                });
                #if Windows
                thread.SetApartmentState(ApartmentState.STA);
                #endif
                thread.Start();
                thread.Join();
            }
            else
            {
                Console.WriteLine("This is a 3MF viewer. Please provide a '.3mf' file! Or use '-h' for help.");
            }
        }