Skip to content

congzhangzh/Webview.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

webview_julia

Build Status License: MIT

Julia bindings for the webview library, allowing you to create desktop applications with web technologies.

Installation

using Pkg
Pkg.add("Webview")

Usage

Open a website

using Webview

wv = WebviewObj()
wv.navigate("https://julialang.org")
wv.run()

Do something in webview scope

using Webview

run_webview() do w
    w.set_title("Test")
    w.navigate("https://example.com")
end

Display Inline HTML:

using HTTP
using Webview

html = """
<!DOCTYPE html>
<html>
    <body>
        <h1>Hello from Julia Webview!</h1>
    </body>
</html>
"""

wv = WebviewObj()
wv.navigate("data:text/html," * HTTP.escapeuri(html))
wv.run()

Load Remote URL:

using Webview

wv = WebviewObj()
wv.navigate("https://julialang.org")
wv.run()

Julia-JavaScript Bindings:

#!/usr/bin/env julia

using Webview
using JSON
using HTTP

    # 创建HTML内容
    html = raw"""
    <!DOCTYPE html>
    <html>
    <body>
        <h1>Julia-JavaScript Binding Demo</h1>
        <button onclick="callJulia()">Call Julia</button>
        <button onclick="callJuliaWithArgs(10, 20)">Add Numbers</button>
        <div id="result"></div>

        <script>
            async function callJulia() {
                const result = await window.hello();
                document.getElementById('result').innerHTML = result;
            }

            async function callJuliaWithArgs(a, b) {
                const result = await window.add(a, b);
                document.getElementById('result').innerHTML = `Result: ${result}`;
            }

            function updateFromJulia(message) {
                document.getElementById('result').innerHTML = message;
            }
        </script>
    </body>
    </html>
    """
    # TODO
    # 创建webview实例
    w = WebviewObj(true)

    # 定义要从JavaScript调用的Julia函数
    function hello()
        w.eval("console.log('Hello from Julia!')")
        return "Hello from Julia!"
    end

    function add(a,b)
        return a + b
    end

    # 绑定Julia函数
    w.bind("hello", hello)
    w.bind("add", add)

    # 设置窗口属性
    w.set_title("Julia-JavaScript Binding Demo")
    w.set_size(640, 480)

    # 加载HTML内容
    w.navigate("data:text/html," * HTTP.escapeuri(html))

    # 运行webview
    w.run()

# Configure window
wv.set_title("Binding Demo")
wv.set_size(800, 600)

wv.navigate("data:text/html," * HTTP.escapeuri(html))
wv.run()

Creating Standalone Executable:

using PackageCompiler

create_app(".", "compiled_app/bind_example";
    force=true,
    include_lazy_artifacts=true,
    executables=["bind_example.jl" => "bind_example"])

Features

  • 🚀 Create desktop applications using HTML, CSS, and JavaScript
  • 📂 Load local HTML files or remote URLs
  • 🔄 Bidirectional Julia-JavaScript communication
  • 🖼️ Window size and title customization
  • 🐛 Debug mode for development
  • 💻 Cross-platform support (Windows, macOS, Linux)
  • 📦 Standalone executable creation

Development

Project Structure

WebView.jl/
├── src/
│   ├── WebView.jl    # Main implementation
│   └── ffi.jl        # Foreign Function Interface
├── examples/         # Example applications
├── test/            # Unit tests
└── README.md        # Documentation

Running Tests

] test WebView

Release Process

  1. Test
# Run tests
julia -e 'using Pkg; Pkg.test("webview_julia")'

# Build documentation
# julia --project=docs/ docs/make.jl
  1. Update Version in Project.toml
version = "x.y.z"
  1. Trigger register bot by commit:
git commit -m "release: vx.y.z

@JuliaRegistrator register"
git push

Examples

Check the examples/ directory for more examples:

  • Basic window creation
  • JavaScript interaction
  • Custom HTML content
  • Standalone application
  • Window management

Roadmap

  • Basic webview functionality
  • Julia-JavaScript bindings
  • Standalone executable support
  • Prebuilt binaries for all platforms
  • More comprehensive examples
  • Documentation website
  • Hot reload support
  • Custom window decorations

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

a webview julia binding inspired by webview_deno

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages