-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(vpnapp): node location logic (#4223)
* refactor node location logic fontend: remove app local data from state remove node config from state use only country location state backend: add node location in state add set_node_location command * call backend to update node location * clean code
- Loading branch information
Showing
21 changed files
with
136 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod app_data; | ||
pub mod connection; | ||
pub mod node_location; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use tauri::State; | ||
use tracing::{debug, instrument}; | ||
use ts_rs::TS; | ||
|
||
use crate::{ | ||
error::{CmdError, CmdErrorSource}, | ||
states::{app::Country, SharedAppData, SharedAppState}, | ||
}; | ||
|
||
#[derive(Debug, Serialize, Deserialize, TS, Clone)] | ||
pub enum NodeType { | ||
Entry, | ||
Exit, | ||
} | ||
|
||
#[instrument(skip(app_state, data_state))] | ||
#[tauri::command] | ||
pub async fn set_node_location( | ||
app_state: State<'_, SharedAppState>, | ||
data_state: State<'_, SharedAppData>, | ||
node_type: NodeType, | ||
country: Country, | ||
) -> Result<(), CmdError> { | ||
debug!("set_node_location"); | ||
let mut state = app_state.lock().await; | ||
match node_type { | ||
NodeType::Entry => { | ||
state.entry_node_location = Some(country.clone()); | ||
} | ||
NodeType::Exit => { | ||
state.exit_node_location = Some(country.clone()); | ||
} | ||
} | ||
// TODO pick a node according to the selected country | ||
|
||
// save the location on disk | ||
let mut app_data_store = data_state.lock().await; | ||
let mut app_data = app_data_store | ||
.read() | ||
.await | ||
.map_err(|e| CmdError::new(CmdErrorSource::InternalError, e.to_string()))?; | ||
|
||
match node_type { | ||
NodeType::Entry => { | ||
app_data.entry_node_location = Some(country); | ||
} | ||
NodeType::Exit => { | ||
app_data.exit_node_location = Some(country); | ||
} | ||
} | ||
app_data_store.data = app_data; | ||
app_data_store | ||
.write() | ||
.await | ||
.map_err(|e| CmdError::new(CmdErrorSource::InternalError, e.to_string()))?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.