/
main.rs
65 lines (57 loc) · 1.87 KB
/
main.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
57
58
59
60
61
62
63
64
65
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use tauri::{Monitor, async_runtime::TokioRuntime, Manager, Menu};
use tauri_runtime::Dispatch;
#[tauri::command]
fn greet(name: &str) -> String {
format!("Hello, {}! You've been greeted from Rust!", name)
}
fn create_app<R: tauri::Runtime>(mut builder: tauri::Builder<R>) -> tauri::App<R> {
builder
.setup(|app| {
// do something
Ok(())
})
.invoke_handler(tauri::generate_handler![greet])
// remove the string argument on your app
.build(tauri::generate_context!())
.expect("failed to build app")
}
fn main() {
let menu = Menu::new(); // configure the menu
tauri::Builder::default()
.menu(menu)
.setup(|app| {
println!("{}", app.package_info().version.to_string());
Ok(())
})
.invoke_handler(tauri::generate_handler![greet])
.run(tauri::generate_context!())
.unwrap();
}
#[cfg(test)]
mod tests {
use tauri::Manager;
#[test]
fn something() {
let data = r#"{"name": "the test"}"#;
let app = super::create_app(tauri::test::mock_builder());
let window = app.get_window("main").unwrap();
// do something with the app and window
// in this case we'll run the my_cmd command with no arguments
tauri::test::assert_ipc_response(
&window,
tauri::InvokePayload {
cmd: "greet".into(),
tauri_module: None,
callback: tauri::api::ipc::CallbackFn(0),
error: tauri::api::ipc::CallbackFn(1),
inner: serde_json::from_str(data).unwrap(),
},
Ok("Hello, the test! You've been greeted from Rust!"),
);
}
#[test]
fn test_get_monitor_ids() {
}
}