-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
Copy pathmain.rs
47 lines (38 loc) · 1.04 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
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use std::sync::Mutex;
use tauri::State;
struct Counter(Mutex<usize>);
#[tauri::command]
fn increment(counter: State<'_, Counter>) -> usize {
let mut c = counter.0.lock().unwrap();
*c += 1;
*c
}
#[tauri::command]
fn decrement(counter: State<'_, Counter>) -> usize {
let mut c = counter.0.lock().unwrap();
*c -= 1;
*c
}
#[tauri::command]
fn reset(counter: State<'_, Counter>) -> usize {
let mut c = counter.0.lock().unwrap();
*c = 0;
*c
}
#[tauri::command]
fn get(counter: State<'_, Counter>) -> usize {
*counter.0.lock().unwrap()
}
fn main() {
tauri::Builder::default()
.manage(Counter(Mutex::new(0)))
.invoke_handler(tauri::generate_handler![increment, decrement, reset, get])
.run(tauri::generate_context!(
"../../examples/state/tauri.conf.json"
))
.expect("error while running tauri application");
}