├── .gitignore
├── .gitmodules
├── .travis.yml
├── Cargo.toml
├── LICENSE
├── README.md
├── examples
├── README.md
├── minimal.rs
├── pageload.rs
├── timer.rs
├── todo-ps
│ ├── .gitignore
│ ├── dist
│ │ └── bundle.html
│ ├── entry.js
│ ├── index.html
│ ├── package.json
│ ├── psc-package.json
│ ├── src
│ │ ├── Component
│ │ │ └── Todo.purs
│ │ └── Main.purs
│ └── styles.css
├── todo-purescript.rs
├── todo.rs
└── todo
│ ├── app.js
│ ├── picodom.js
│ └── styles.css
├── src
└── lib.rs
└── webview-sys
├── Cargo.toml
├── build.rs
├── lib.rs
└── webview.c
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | target/
3 | **/*.rs.bk
4 | Cargo.lock
5 | TODO.md
6 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "webview-sys/webview"]
2 | path = webview-sys/webview
3 | url = https://github.com/huytd/webview
4 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | sudo: required
2 | language: rust
3 | cache: cargo
4 |
5 | os:
6 | - linux
7 | - osx
8 |
9 | rust:
10 | - stable
11 | - beta
12 | - nightly
13 |
14 | matrix:
15 | allow_failures:
16 | - rust: nightly
17 |
18 | addons:
19 | apt:
20 | packages:
21 | - libwebkit2gtk-4.0-dev
22 | sources:
23 | - sourceline: 'ppa:webkit-team/ppa'
24 |
--------------------------------------------------------------------------------
/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "web-view"
3 | version = "0.1.3"
4 | authors = ["Boscop"]
5 | readme = "README.md"
6 | license = "MIT"
7 | repository = "https://github.com/Boscop/web-view"
8 | description = "Rust bindings for webview, a tiny cross-platform library to render web-based GUIs for desktop applications"
9 | keywords = ["web", "gui", "desktop", "electron", "webkit"]
10 | categories = ["gui", "web-programming", "api-bindings", "rendering", "visualization"]
11 | exclude = ["examples/todo-ps/dist/**/*"]
12 |
13 | [dependencies]
14 | urlencoding = "1.0"
15 | fnv = "1.0"
16 | webview-sys = { path = "webview-sys", version = "0.1.0" }
17 |
18 | [dev-dependencies]
19 | serde = "1.0"
20 | serde_derive = "1.0"
21 | serde_json = "1.0"
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Boscop
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # web-view [![Build Status]][travis] [![Latest Version]][crates.io]
2 |
3 | [Build Status]: https://api.travis-ci.org/Boscop/web-view.svg?branch=master
4 | [travis]: https://travis-ci.org/Boscop/web-view
5 | [Latest Version]: https://img.shields.io/crates/v/web-view.svg
6 | [crates.io]: https://crates.io/crates/web-view
7 |
8 | This library provides Rust bindings for the [webview](https://github.com/zserge/webview) library to allow easy creation of cross-platform Rust desktop apps with GUIs based on web technologies.
9 |
10 | It supports two-way bindings for communication between the Rust backend and JavaScript frontend.
11 |
12 | It uses Cocoa/WebKit on macOS, gtk-webkit2 on Linux and MSHTML (IE10/11) on Windows, so your app will be **much** leaner than with Electron.
13 |
14 | For usage info please check out [the examples](../../tree/master/examples) and the [original readme](https://github.com/zserge/webview/blob/master/README.md).
15 |
16 | Contributions and feedback welcome :)
17 |
18 |
19 |
20 | ## Suggestions:
21 | - If you like type safety, write your frontend in [Elm](http://elm-lang.org/) or [PureScript](http://www.purescript.org/)[*](#n1), or use a Rust frontend framework that compiles to asm.js, like [yew](https://github.com/DenisKolodin/yew).
22 | - Use [parcel](https://parceljs.org/) to bundle & minify your frontend code.
23 | - Use [inline-assets](https://www.npmjs.com/package/inline-assets) to inline all your assets (css, js, html) into one index.html file and embed it in your Rust app using `include_str!()`.
24 | - If your app runs on windows, [add an icon](https://github.com/mxre/winres) to your Rust executable to make it look more professional™
25 | - Use custom npm scripts or [just](https://github.com/casey/just) or [cargo-make](https://github.com/sagiegurari/cargo-make) to automate the build steps.
26 | - Make your app state persistent between sessions using localStorage in the frontend or [rustbreak](https://crates.io/crates/rustbreak) in the backend.
27 | - Btw, instead of injecting app resources via the js api, you can also serve them from a local http server (e.g. bound to an ephemeral port).
28 | - Happy coding :)
29 |
30 | * The free [PureScript By Example](https://leanpub.com/purescript/read) book contains several practical projects for PureScript beginners.
31 |
32 | ---
33 |
34 | ## Contribution opportunities:
35 | - Create an issue for any question you have
36 | - Docs
37 | - Feedback on this library's API and code
38 | - Some functions don't have FFI yet, e.g. `webview_dialog`
39 | - Test it on non-windows platforms, report any issues you find
40 | - Showcase your app
41 | - Add an example that uses Elm or Rust compiled to asm.js
42 | - Add a PureScript example that does two-way communication with the backend
43 | - Contribute to the original webview library: E.g. [add HDPI support on Windows](https://github.com/zserge/webview/issues/54)
44 | - Make it possible to create the webview window as a child window of a given parent window. This would allow webview to be used for the GUIs of [VST audio plugins in Rust](https://github.com/rust-dsp/rust-vst).
45 |
46 | ---
47 |
48 | ### Ideas for apps:
49 | - Rust IDE (by porting [xi-electron](https://github.com/acheronfail/xi-electron) to web-view)
50 | - Data visualization / plotting lib for Rust, to make Rust more useful for data science
51 | - Crypto coin wallet
52 | - IRC client, or client for other chat protocols
53 | - Midi song editor, VJ controller
54 | - Rust project template wizard: Generate new Rust projects from templates with user-friendly steps
55 | - GUI for [pijul](https://pijul.org/)
56 |
57 | ---
58 |
59 | Note: The API can still change. Currently there is only one function (`run()`) that takes all args, but maybe a builder would be better..
60 |
--------------------------------------------------------------------------------
/examples/README.md:
--------------------------------------------------------------------------------
1 | # web-view examples
2 |
3 | ## minimal
4 | Just displays the wikipedia homepage.
5 |
6 | ## pageload
7 | Loads a custom url-encoded html page (hello world).
8 |
9 | ## timer
10 | Uses two-way communication with the web app to render the state of a timer and reset the timer on the click of a button. Shows basic usage of `userdata` and shared state between threads.
11 |
12 | ## todo
13 | Uses picodom.js to render a basic Todo App. Demonstrates how to embed the frontend into the Rust executable and how to use `userdata` to store app state.
14 |
15 | ## todo-purescript
16 | This is a port of the todo example to PureScript.
17 | To be able to build this, first install purescript and bundling tools:
18 | ```
19 | $ npm install -g purescript pulp psc-package parcel-bundler inline-assets
20 | ```
21 | Next, install the dependencies:
22 | ```
23 | $ psc-package update
24 | ```
25 | Now build the frontend and bundle it into `dist/bundle.html`:
26 | ```
27 | $ npm run prod
28 | ```
29 | Finally use cargo to build the rust executable, which includes `bundle.html` using `include_str!()`.
30 |
31 | ---
32 |
33 | Note: For some reason (at least on Windows), if I try to `cargo run` the examples directly, they don't show the window, but it works with `cargo build --example && target\debug\examples\`
34 |
--------------------------------------------------------------------------------
/examples/minimal.rs:
--------------------------------------------------------------------------------
1 | // #![windows_subsystem = "windows"]
2 |
3 | extern crate web_view;
4 |
5 | use web_view::*;
6 |
7 | fn main() {
8 | let size = (800, 600);
9 | let resizable = true;
10 | let debug = true;
11 | let init_cb = |_webview| {};
12 | let frontend_cb = |_webview: &mut _, _arg: &_, _userdata: &mut _| {};
13 | let userdata = ();
14 | run(
15 | "Minimal webview example",
16 | Content::Url("https://en.m.wikipedia.org/wiki/Main_Page"),
17 | Some(size),
18 | resizable,
19 | debug,
20 | init_cb,
21 | frontend_cb,
22 | userdata
23 | );
24 | }
--------------------------------------------------------------------------------
/examples/pageload.rs:
--------------------------------------------------------------------------------
1 | // #![windows_subsystem = "windows"]
2 |
3 | extern crate web_view;
4 |
5 | use web_view::*;
6 |
7 | fn main() {
8 | let size = (800, 600);
9 | let resizable = true;
10 | let debug = true;
11 | let init_cb = |_webview| {};
12 | let frontend_cb = |_webview: &mut _, _arg: &_, _userdata: &mut _| {};
13 | let userdata = ();
14 | run("pageload example", Content::Html(HTML), Some(size), resizable, debug, init_cb, frontend_cb, userdata);
15 | }
16 |
17 | const HTML: &'static str = r#"
18 |
19 |
20 |
21 |