5 releases

0.2.4 Mar 2, 2024
0.2.3 Feb 29, 2024
0.2.2 Feb 29, 2024
0.2.1 Feb 29, 2024
0.2.0 Feb 29, 2024

#820 in GUI

Download history 4/week @ 2024-07-22 3/week @ 2024-09-30

177 downloads per month

MIT/Apache

22KB
189 lines

tauriless

Crates.io Downloads Documentation License

Run a Tauri-like application without installation.

Warning

This crate is a temporary solution to the problem of running Tauri-like applications without installation. It is not a replacement for Tauri, and it is not a long-term solution. It is a workaround for the time being.

Also, the library was tested only for Windows and is not guaranteed to work on other platforms. If you want to help with testing on other platforms, please open an issue.

Currently, the library can't even guarantee that the binary will work on desktop machines of the majority of the users because of runtime dependencies on WebView2 and vcredist. While WebView2 comes pre-installed on Windows 10, it is not the case for vcredist. The dependency on the latter can be resolved by using target-feature=+crt-static.

Usage

use tao::{
   event::{Event, StartCause, WindowEvent},
   event_loop::{ControlFlow, EventLoop},
   window::WindowBuilder,
};
use wry::WebViewBuilder;
use tauriless::{command, commands, WebViewBuilderExt};

#[command]
fn argsless_sync_command() {}

#[command]
async fn async_command_with_args(n: i32) -> i32 {
  // some async code
  n * 2
}

fn main() -> wry::Result<()>     {
  let rt = tokio::runtime::Builder::new_multi_thread()
      .enable_all()
      .build()
      .unwrap();
  // This allows us to use tokio::spawn inside wry asynchronous custom protocol handlers.
  // Since wry doesn't allow us to pass a runtime to the WebViewBuilder, we have to use a global runtime.
  let _rt_guard = rt.enter();

  let event_loop = EventLoop::new();
  let window = WindowBuilder::new()
      .with_title("My Tauriless App")
      .build(&event_loop)
      .unwrap();

   // ...
   
   let _webview = WebViewBuilder::new(&window)
       // ...
       .with_tauriless_commands(commands![argsless_sync_command, async_command_with_args])
       .build()?;

   event_loop.run(move |event, _, control_flow| {
       *control_flow = ControlFlow::Wait;

       match event {
           Event::NewEvents(StartCause::Init) => (),
           Event::WindowEvent {
               event: WindowEvent::CloseRequested,
               ..
           } => *control_flow = ControlFlow::Exit,
           _ => (),
       }
   });
}

Eliminating the dependency on vcredist on Windows

Usually, to run a Rust executable on a Windows machine, the user must have vcredist installed. See https://stackoverflow.com/questions/52153676/what-is-the-requirements-for-running-a-rust-compiled-program-on-another-windows.

In order to avoid the problem it's recommended to add .cargo/config.toml with the following content:

[target.x86_64-pc-windows-msvc]
rustflags = ["-Ctarget-feature=+crt-static"]

[target.i686-pc-windows-msvc]
rustflags = ["-Ctarget-feature=+crt-static"]

[target.i586-pc-windows-msvc]
rustflags = ["-Ctarget-feature=+crt-static"]

It will ensure that the Rust compiler links the C runtime statically, so the user won't need to install vcredist. It increases the size of the binary[^1], but it's a reasonable trade-off for a standalone application.

[^1]: What's the the size increase?

Dependencies

~4–39MB
~546K SLoC