Crates.io | tauriless |
lib.rs | tauriless |
version | 0.2.4 |
source | src |
created_at | 2024-02-29 04:50:29.279064 |
updated_at | 2024-03-02 04:31:05.420937 |
description | Run a Tauri-like application without installation. |
homepage | |
repository | https://github.com/JohnScience/tauriless/ |
max_upload_size | |
id | 1157365 |
size | 9,650 |
Run a Tauri-like application without installation.
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
.
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,
_ => (),
}
});
}
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 binary1, but it's a reasonable trade-off for a standalone application.
What's the the size increase? ↩