A library for creating desktop applications using Crystal and web technologies. It uses a lightweight web view for rendering HTML and CSS, and features a utility for ergonomic calls to Crystal from Javascript and vice-versa.
-
(Linux/BSD only) Install
webkit2gtk
from your package manager:OS Package name Notes Arch/Manjaro webkit2gtk Ubuntu webkit2gtk-4.0-dev OpenSUSE webkit2gtk3-devel Fedora webkit2gtk3-devel Alpine webkit2gtk-dev Debian libwebkit2gtk-4.0-dev OpenBSD/FreeBSD webkit2-gtk3 requires wxallowed mount(8) option -
Add the dependency to your
shard.yml
:
dependencies:
webview:
github: dscottboggs/webview
- Run
shards install
require "webview.cr"
class SimpleWebWindow < Webview::Window
def script
<<-JS
console.log("hello, there")
some_callback("Hello to Crystal from Javascript")
JS
end
@[Webview::Callback]
def some_callback(text : String)
puts text
end
def run
run do
puts "running"
go_to "https://crystal-lang.org/reference"
sleep 1
eval <<-JS
console.log("evaluating arbitrary code")
JS
some_callback "can also be called from Crystal!"
end
puts "done"
end
end
SimpleWebWindow.new.run
There is a runnable version of this example in the samples
directory. All
samples can be built by running make
from the project directory.
make
sample/simple
sample/render
Contributions are welcome. Since this a graphical tool, and the results are usually visual as opposed to something that can be tested in code, please write a runnable example which exercises any new code paths. See the samples directory.
Of course, if your contributions can be tested with crystal spec
, those tests
are more than welcome.
- Webpack integration
- Scripts for bootstrapping the
yarn
environment and having a smooth and defined process for integrating complicated environments that come with web projects. - Integration with existing Crystal web frameworks like Lucky, Athena, or Amber.
- Fork it (https://github.com/dscottboggs/webview/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
- D. Scott Boggs - creator and maintainer