11mod tray;
22
33use enigo:: { Direction , Enigo , Key , Keyboard , Settings } ;
4- use tauri:: { AppHandle , Manager } ;
4+ use tauri:: { AppHandle , Manager , Runtime } ;
55use tauri_plugin_autostart:: MacosLauncher ;
6+ use tauri_plugin_store:: StoreExt ;
67use window_vibrancy:: { apply_acrylic, apply_mica} ;
78
9+ use serde_json:: json;
10+
811#[ tauri:: command]
912async fn input_text ( text : & str ) -> Result < ( ) , String > {
1013 let mut enigo = Enigo :: new ( & Settings :: default ( ) ) . unwrap ( ) ;
@@ -21,6 +24,45 @@ async fn simulate_paste() -> Result<(), String> {
2124 Ok ( ( ) )
2225}
2326
27+ #[ tauri:: command]
28+ async fn get_key_from_store < R : Runtime > (
29+ app : tauri:: AppHandle < R > ,
30+ _window : tauri:: Window < R > ,
31+ key : String ,
32+ fallback : serde_json:: Value ,
33+ ) -> Result < serde_json:: Value , String > {
34+ let stores = app. store ( "store.bin" ) ;
35+ let store = match stores {
36+ Ok ( store) => store,
37+ Err ( _) => return Ok ( fallback) ,
38+ } ;
39+ if store. has ( key. clone ( ) ) {
40+ let value = store
41+ . get ( key. clone ( ) )
42+ . expect ( "Failed to get value from store" ) ;
43+ Ok ( value)
44+ } else {
45+ Ok ( fallback)
46+ }
47+ }
48+
49+ #[ tauri:: command]
50+ async fn set_key_to_store < R : Runtime > (
51+ app : tauri:: AppHandle < R > ,
52+ _window : tauri:: Window < R > ,
53+ key : String ,
54+ value : serde_json:: Value ,
55+ ) -> Result < ( ) , String > {
56+ let stores = app. store ( "store.bin" ) ;
57+ let store = match stores {
58+ Ok ( store) => store,
59+ Err ( _) => return Err ( "Failed to get store" . to_string ( ) ) ,
60+ } ;
61+ store. set ( key. clone ( ) , json ! ( value) ) ;
62+ store. save ( ) . expect ( "Failed to save store" ) ;
63+ Ok ( ( ) )
64+ }
65+
2466fn show_window ( app : & AppHandle ) {
2567 let windows = app. webview_windows ( ) ;
2668
@@ -65,7 +107,9 @@ pub fn run() {
65107 . plugin ( tauri_plugin_opener:: init ( ) )
66108 . invoke_handler ( tauri:: generate_handler![
67109 input_text,
68- simulate_paste
110+ simulate_paste,
111+ get_key_from_store,
112+ set_key_to_store
69113 ] )
70114 . run ( tauri:: generate_context!( ) )
71115 . expect ( "error while running tauri application" ) ;
0 commit comments