3 unstable releases

0.2.1 Feb 29, 2024
0.2.0 Feb 29, 2024
0.1.0 Feb 27, 2024

#2017 in Procedural macros

Download history 410/week @ 2024-02-25 23/week @ 2024-03-03 9/week @ 2024-03-10 6/week @ 2024-03-17 1/week @ 2024-03-24 35/week @ 2024-03-31 69/week @ 2024-04-07

111 downloads per month
Used in tauriless

MIT/Apache

29KB
370 lines

tauriless_macro

Crates.io Downloads Documentation License

The proc-macro crate for tauriless.

Example

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,
           _ => (),
       }
   });
}

Dependencies

~0.7–1.2MB
~26K SLoC