ui + config: modals content drawing refactoring, move connections config to separate file

This commit is contained in:
ardocrat
2023-08-03 04:11:25 +03:00
parent b34654ab00
commit ff9fcd38f2
27 changed files with 916 additions and 643 deletions
+22 -14
View File
@@ -45,8 +45,9 @@ impl PeersConfig {
/// Save peers config to the file.
pub fn save(&self) {
let chain_type = AppConfig::chain_type();
let chain_name = Some(chain_type.shortname());
let config_path = Settings::get_config_path(Self::FILE_NAME, chain_name);
let chain_name = chain_type.shortname();
let sub_dir = Some(chain_name.as_str());
let config_path = Settings::get_config_path(Self::FILE_NAME, sub_dir);
Settings::write_to_file(self, config_path);
}
@@ -146,8 +147,9 @@ impl NodeConfig {
// Initialize peers config.
let peers_config = {
let chain_name = Some(chain_type.shortname());
let path = Settings::get_config_path(PeersConfig::FILE_NAME, chain_name);
let chain_name = chain_type.shortname();
let sub_dir = Some(chain_name.as_str());
let path = Settings::get_config_path(PeersConfig::FILE_NAME, sub_dir);
let config = Settings::read_from_file::<PeersConfig>(path.clone());
if !path.exists() || config.is_err() {
Self::save_default_peers_config(chain_type)
@@ -158,8 +160,9 @@ impl NodeConfig {
// Initialize node config.
let node_config = {
let chain_name = Some(chain_type.shortname());
let path = Settings::get_config_path(SERVER_CONFIG_FILE_NAME, chain_name);
let chain_name = chain_type.shortname();
let sub_dir = Some(chain_name.as_str());
let path = Settings::get_config_path(SERVER_CONFIG_FILE_NAME, sub_dir);
let config = Settings::read_from_file::<ConfigMembers>(path.clone());
if !path.exists() || config.is_err() {
Self::save_default_node_server_config(chain_type)
@@ -173,10 +176,11 @@ impl NodeConfig {
/// Save default node config for specified [`ChainTypes`].
fn save_default_node_server_config(chain_type: &ChainTypes) -> ConfigMembers {
let chain_name = Some(chain_type.shortname());
let path = Settings::get_config_path(SERVER_CONFIG_FILE_NAME, chain_name.clone());
let chain_name = chain_type.shortname();
let sub_dir = Some(chain_name.as_str());
let path = Settings::get_config_path(SERVER_CONFIG_FILE_NAME, sub_dir);
let mut default_config = GlobalConfig::for_chain(chain_type);
default_config.update_paths(&Settings::get_base_path(chain_name));
default_config.update_paths(&Settings::get_base_path(sub_dir));
let config = default_config.members.unwrap();
Settings::write_to_file(&config, path);
config
@@ -184,8 +188,9 @@ impl NodeConfig {
/// Save default peers config for specified [`ChainTypes`].
fn save_default_peers_config(chain_type: &ChainTypes) -> PeersConfig {
let chain_name = Some(chain_type.shortname());
let path = Settings::get_config_path(PeersConfig::FILE_NAME, chain_name);
let chain_name = chain_type.shortname();
let sub_dir = Some(chain_name.as_str());
let path = Settings::get_config_path(PeersConfig::FILE_NAME, sub_dir);
let config = PeersConfig::default();
Settings::write_to_file(&config, path);
config
@@ -193,8 +198,9 @@ impl NodeConfig {
/// Save node config to the file.
pub fn save(&self) {
let chain_name = Some(self.node.server.chain_type.shortname());
let config_path = Settings::get_config_path(SERVER_CONFIG_FILE_NAME, chain_name);
let chain_name = self.node.server.chain_type.shortname();
let sub_dir = Some(chain_name.as_str());
let config_path = Settings::get_config_path(SERVER_CONFIG_FILE_NAME, sub_dir);
Settings::write_to_file(&self.node, config_path);
}
@@ -235,7 +241,9 @@ impl NodeConfig {
/// Get path for secret file.
fn get_secret_path(chain_type: &ChainTypes, secret_file_name: &str) -> PathBuf {
let grin_path = Settings::get_base_path(Some(chain_type.shortname()));
let chain_name = chain_type.shortname();
let sub_dir = Some(chain_name.as_str());
let grin_path = Settings::get_base_path(sub_dir);
let mut api_secret_path = grin_path;
api_secret_path.push(secret_file_name);
api_secret_path