Introduction
Greenhorn is a rust library for building desktop applications with web technologies in (almost) pure rust.
This is accomplished by separating the application into a server-side process (the backend) and web view implemented in javascript (the frontend). While most HTML-based desktop applications leave state synchronization between frontend and backend up to the application logic, this library synchronizes its state at DOM-level. Thus, the user may implement the application logic purely in the backend using rust and the DOM is automatically synchronized with the frontend. This facilitates the integration of a desktop GUI with system services and simplifies application development considerably.
Deploying
The greenhorn library is not opinionated on how to deploy applications. However, the projects ships additional facilities to deploy applications to common targets.
-
Desktop applications may be deployed using Boscop's WebView. The
greenhorn_web_view
crates serves as an adapter for it. This is the easiest deployment method for desktop operating systems. Refer to this page for details. -
greenhorn application may be deployed in a webbrowser. Refer to this page for details and check out this example.
-
Desktop applications may also be deployed with electron. Currently, this the recommended and best tested method.
Examples
A todomvc
example is presented in the repository at examples/todomvc
:
- The core application logic is located in the
lib
crate - A deployment example for WebView is given in the
webview
crate - An example of how to deploy with Electron in the
electron
directory - A browser version of the application in the
wasm
directory
Quickstart
Use the following repository to quick-start development of an electron based application: https://github.com/raffber/greenhorn-electron-quickstart
Getting Started
It is recommended to split the application and it's deployment into different crates. This has the advantage that the same application can be easily deployed with several different methods but the structure of the repository can be kept clean. However to simplify the setup of this tutorial, we will skip this step.
Futhermore, we will use electron to deploy a desktop application.
Currently, this is the recommended method to deploy greenhorn
applications.
To simplify the project setup, start by cloning the quickstart repository:
git clone https://github.com/raffber/greenhorn-electron-quickstart
This quickstart repo makes us of the following tools:
- neon to compile rust modules for nodejs
- webpack to bundle JS and CSS assets
- electron as browser frontend
- electron-builder to package the app into an installer
Then, setup the nodejs environment (make sure you have nodejs
and npm
installed):
npm install
Compiling and running the application can be achieved using npm
:
npm run start
This will compile the application in debug mode and run electron. Finally, if you want to package the application, use:
npm run package
That's it for the project setup. You are now ready to start developping you app.