tauri_dialog_sys/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//! This crate is no longer maintained. Tauri now uses [rfd](https://github.com/PolyMeilex/rfd).

use std::ffi::CString;

#[repr(C)]
pub enum DialogStyle {
  Info,
  Warning,
  Error,
  Question,
}

#[repr(C)]
pub enum DialogButtons {
  Ok,
  OkCancel,
  YesNo,
  Quit,
}

#[repr(C)]
#[derive(PartialEq)]
pub enum DialogSelection {
  Ok,
  Cancel,
  Yes,
  No,
  Quit,
  None,
  Error,
}

mod ffi {
  use crate::{DialogButtons, DialogSelection, DialogStyle};
  use std::os::raw::*;

  extern "C" {
    pub fn boxerShow(
      message: *const c_char,
      title: *const c_char,
      style: DialogStyle,
      buttons: DialogButtons,
    ) -> DialogSelection;
  }
}

pub fn show_dialog(
  message: &str,
  title: &str,
  style: DialogStyle,
  buttons: DialogButtons,
) -> DialogSelection {
  let c_message = CString::new(message).expect("No nul bytes in parameter message");
  let c_title = CString::new(title).expect("No nul bytes in parameter title");
  unsafe { ffi::boxerShow(c_message.as_ptr(), c_title.as_ptr(), style, buttons) }
}