settings: move to separate module
This commit is contained in:
parent
a93b040b83
commit
5a77bc0759
5 changed files with 30 additions and 13 deletions
10
src/lib.rs
10
src/lib.rs
|
@ -20,9 +20,8 @@ use egui::{Context, Stroke};
|
|||
#[cfg(target_os = "android")]
|
||||
use winit::platform::android::activity::AndroidApp;
|
||||
|
||||
pub use config::AppConfig;
|
||||
pub use settings::AppConfig;
|
||||
pub use settings::Settings;
|
||||
use crate::config::DEFAULT_LOCALE;
|
||||
|
||||
use crate::gui::{Colors, PlatformApp};
|
||||
use crate::gui::platform::PlatformCallbacks;
|
||||
|
@ -35,7 +34,6 @@ mod node;
|
|||
mod wallet;
|
||||
|
||||
mod settings;
|
||||
mod config;
|
||||
pub mod gui;
|
||||
|
||||
// Include build information.
|
||||
|
@ -212,9 +210,9 @@ fn setup_i18n() {
|
|||
rust_i18n::set_locale(lang.as_str());
|
||||
}
|
||||
} else {
|
||||
let locale = sys_locale::get_locale().unwrap_or(String::from(DEFAULT_LOCALE));
|
||||
let locale = sys_locale::get_locale().unwrap_or(String::from(AppConfig::DEFAULT_LOCALE));
|
||||
let locale_str = if locale.contains("-") {
|
||||
locale.split("-").next().unwrap_or(DEFAULT_LOCALE)
|
||||
locale.split("-").next().unwrap_or(AppConfig::DEFAULT_LOCALE)
|
||||
} else {
|
||||
locale.as_str()
|
||||
};
|
||||
|
@ -223,7 +221,7 @@ fn setup_i18n() {
|
|||
if rust_i18n::available_locales!().contains(&locale_str) {
|
||||
rust_i18n::set_locale(locale_str);
|
||||
} else {
|
||||
rust_i18n::set_locale(DEFAULT_LOCALE);
|
||||
rust_i18n::set_locale(AppConfig::DEFAULT_LOCALE);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -43,10 +43,8 @@ pub struct AppConfig {
|
|||
lang: Option<String>
|
||||
}
|
||||
|
||||
pub const DEFAULT_LOCALE: &str = "en";
|
||||
|
||||
pub const DEFAULT_WIDTH: f32 = 1200.0;
|
||||
pub const DEFAULT_HEIGHT: f32 = 720.0;
|
||||
const DEFAULT_WIDTH: f32 = 1200.0;
|
||||
const DEFAULT_HEIGHT: f32 = 720.0;
|
||||
|
||||
impl Default for AppConfig {
|
||||
fn default() -> Self {
|
||||
|
@ -68,6 +66,9 @@ impl AppConfig {
|
|||
/// Application configuration file name.
|
||||
pub const FILE_NAME: &'static str = "app.toml";
|
||||
|
||||
/// Default i18n locale.
|
||||
pub const DEFAULT_LOCALE: &'static str = "en";
|
||||
|
||||
/// Save application configuration to the file.
|
||||
pub fn save(&self) {
|
||||
Settings::write_to_file(self, Settings::get_config_path(Self::FILE_NAME, None));
|
19
src/settings/mod.rs
Normal file
19
src/settings/mod.rs
Normal file
|
@ -0,0 +1,19 @@
|
|||
// Copyright 2024 The Grim Developers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
mod settings;
|
||||
pub use settings::Settings;
|
||||
|
||||
mod config;
|
||||
pub use config::AppConfig;
|
|
@ -22,8 +22,8 @@ use lazy_static::lazy_static;
|
|||
use serde::de::DeserializeOwned;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::config::AppConfig;
|
||||
use crate::node::NodeConfig;
|
||||
use crate::settings::AppConfig;
|
||||
use crate::wallet::ConnectionsConfig;
|
||||
|
||||
lazy_static! {
|
|
@ -15,8 +15,7 @@
|
|||
use grin_core::global::ChainTypes;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
use crate::config::AppConfig;
|
||||
use crate::Settings;
|
||||
use crate::{AppConfig, Settings};
|
||||
use crate::wallet::ExternalConnection;
|
||||
|
||||
/// Wallet connections configuration.
|
||||
|
|
Loading…
Reference in a new issue