lib.rs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //! Raw FFI bindings to tauri UI.
  2. #[macro_use]
  3. extern crate bitflags;
  4. use std::os::raw::*;
  5. // https://doc.rust-lang.org/nomicon/ffi.html#representing-opaque-structs
  6. #[repr(C)]
  7. pub struct CWebView {
  8. _private: [u8; 0],
  9. }
  10. type ErasedExternalInvokeFn = extern "C" fn(webview: *mut CWebView, arg: *const c_char);
  11. type ErasedDispatchFn = extern "C" fn(webview: *mut CWebView, arg: *mut c_void);
  12. #[repr(C)]
  13. pub enum DialogType {
  14. Open = 0,
  15. Save = 1,
  16. Alert = 2,
  17. }
  18. bitflags! {
  19. #[repr(C)]
  20. pub struct DialogFlags: u32 {
  21. const FILE = 0b0000;
  22. const DIRECTORY = 0b0001;
  23. const INFO = 0b0010;
  24. const WARNING = 0b0100;
  25. const ERROR = 0b0110;
  26. }
  27. }
  28. extern "C" {
  29. pub fn wrapper_webview_free(this: *mut CWebView);
  30. pub fn wrapper_webview_new(
  31. title: *const c_char,
  32. url: *const c_char,
  33. width: c_int,
  34. height: c_int,
  35. resizable: c_int,
  36. debug: c_int,
  37. external_invoke_cb: Option<ErasedExternalInvokeFn>,
  38. userdata: *mut c_void,
  39. ) -> *mut CWebView;
  40. pub fn webview_loop(this: *mut CWebView, blocking: c_int) -> c_int;
  41. pub fn webview_terminate(this: *mut CWebView);
  42. pub fn webview_exit(this: *mut CWebView);
  43. pub fn wrapper_webview_get_userdata(this: *mut CWebView) -> *mut c_void;
  44. pub fn webview_dispatch(this: *mut CWebView, f: Option<ErasedDispatchFn>, arg: *mut c_void);
  45. pub fn webview_eval(this: *mut CWebView, js: *const c_char) -> c_int;
  46. pub fn webview_inject_css(this: *mut CWebView, css: *const c_char) -> c_int;
  47. pub fn webview_set_title(this: *mut CWebView, title: *const c_char);
  48. pub fn webview_set_fullscreen(this: *mut CWebView, fullscreen: c_int);
  49. pub fn webview_set_color(this: *mut CWebView, red: u8, green: u8, blue: u8, alpha: u8);
  50. pub fn webview_dialog(
  51. this: *mut CWebView,
  52. dialog_type: DialogType,
  53. flags: DialogFlags,
  54. title: *const c_char,
  55. arg: *const c_char,
  56. result: *mut c_char,
  57. result_size: usize,
  58. );
  59. }