@@ -7,6 +7,10 @@ use std::env;
77use tauri:: { Manager } ;
88use std:: path:: PathBuf ;
99
10+ use tauri:: { State } ;
11+ use std:: collections:: HashMap ;
12+ use std:: sync:: Mutex ;
13+
1014#[ cfg( target_os = "linux" ) ]
1115use std:: fs:: metadata;
1216#[ cfg( target_os = "linux" ) ]
@@ -91,6 +95,36 @@ fn _get_clipboard_files() -> Option<Vec<String>> {
9195 }
9296}
9397
98+ // this in memory hashmap is used to supplement the LMDB node layer in a multi window environment.
99+ struct Storage {
100+ map : Mutex < HashMap < String , String > > ,
101+ }
102+
103+ #[ tauri:: command]
104+ fn put_item ( state : State < ' _ , Storage > , key : String , value : String ) {
105+ let mut map = state. map . lock ( ) . unwrap ( ) ;
106+ map. insert ( key, value) ;
107+ }
108+
109+ #[ tauri:: command]
110+ fn get_item ( state : State < ' _ , Storage > , key : String ) -> Option < String > {
111+ let map = state. map . lock ( ) . unwrap ( ) ;
112+ map. get ( & key) . cloned ( )
113+ }
114+
115+ #[ tauri:: command]
116+ fn get_all_items ( state : State < ' _ , Storage > ) -> HashMap < String , String > {
117+ let map = state. map . lock ( ) . unwrap ( ) ;
118+ map. clone ( )
119+ }
120+
121+ #[ tauri:: command]
122+ fn delete_item ( state : State < ' _ , Storage > , key : String ) {
123+ let mut map = state. map . lock ( ) . unwrap ( ) ;
124+ map. remove ( & key) ;
125+ }
126+ // in memory hashmap end
127+
94128static mut DEVTOOLS_LOADED : bool = false ;
95129
96130#[ tauri:: command]
@@ -245,6 +279,9 @@ fn main() {
245279 let _ = fix_path_env:: fix ( ) ;
246280
247281 tauri:: Builder :: default ( )
282+ . manage ( Storage {
283+ map : Mutex :: new ( HashMap :: new ( ) ) ,
284+ } )
248285 . register_uri_scheme_protocol ( "phtauri" , move |app, request| { // can't use `tauri` because that's already in use
249286 let path = remove_version_from_url ( request. uri ( ) ) ;
250287 let path = path. strip_prefix ( "phtauri://localhost" ) ;
@@ -302,6 +339,7 @@ fn main() {
302339 get_mac_deep_link_requests,
303340 toggle_devtools, console_log, console_error, _get_commandline_args, get_current_working_dir,
304341 _get_window_labels,
342+ put_item, get_item, get_all_items, delete_item,
305343 _get_windows_drives, _rename_path, show_in_folder, zoom_window, _get_clipboard_files] )
306344 . setup ( |app| {
307345 init:: init_app ( app) ;
0 commit comments