Crates.io | tauriless_macro |
lib.rs | tauriless_macro |
version | 0.2.1 |
source | src |
created_at | 2024-02-27 06:08:24.573061 |
updated_at | 2024-02-29 20:19:02.307291 |
description | The proc-macro crate for tauriless |
homepage | |
repository | https://github.com/JohnScience/tauriless/ |
max_upload_size | |
id | 1154576 |
size | 27,144 |
The proc-macro crate for tauriless
.
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,
_ => (),
}
});
}