Skip to content

Commit

Permalink
Add first backend implementation of storing strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
NiklasHeneka committed Jun 5, 2024
1 parent d9dee1a commit d4a70fc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
31 changes: 20 additions & 11 deletions src-tauri/src/commands/search_string_storage.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
use crate::state::cnl_state::CNLState;
use std::{collections::HashMap, sync::Mutex};
use tauri::State;

pub(crate) struct SearchStringStorage {
pub(crate) store: Mutex<HashMap<String, String>>,
}


#[tauri::command]
pub async fn get_stored_search_string(
state: tauri::State<'_, CNLState>,
pub fn get_stored_search_string(
page: String,
storage: State<SearchStringStorage>
) -> Result<String, ()> {
/* TODO return string from lookup table with key page.
If present delete entry else return empty string.
*/
Ok("".parse().unwrap())
let str = storage.store.lock().unwrap().remove(&page);
if str.is_none() {
Ok("".parse().unwrap())
}
else {
Ok("".parse().unwrap()) // TODO return string
}
}

#[tauri::command]
pub async fn store_search_string(
state: tauri::State<'_, CNLState>,
pub fn store_search_string(
page: String,
string: String
string: String,
storage: State<SearchStringStorage>
) -> Result<(), ()> {
// TODO save page: string in a lookup table
storage.store.lock().unwrap().insert(page, string);
Ok(())
}
7 changes: 6 additions & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

use std::sync::Mutex;
use canzero_cli::run_cli;
use tauri::Manager;

use crate::{
commands::{connection_status, network_information, object_entry_commands},
commands::{connection_status, network_information, object_entry_commands, search_string_storage::SearchStringStorage},
state::startup::StartupState,
};
use crate::commands::search_string_storage;

mod cnl;
mod commands;
Expand All @@ -19,6 +22,7 @@ async fn main() {

// setup tauri
tauri::Builder::default()
.manage(SearchStringStorage { store: Default::default() })
.setup(|app| {
let handle = app.handle();
tokio::spawn(async move {
Expand Down Expand Up @@ -84,6 +88,7 @@ async fn main() {
commands::settings::set_frontend_lvl,
commands::settings::set_deadlock_lvl,
commands::search_string_storage::get_stored_search_string,
commands::search_string_storage::store_search_string,
])
.run(tauri::generate_context!())
.expect("Error while running tauri application");
Expand Down

0 comments on commit d4a70fc

Please sign in to comment.