Skip to content

Commit

Permalink
Work on config saving and also localize
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Honeycutt committed May 24, 2024
1 parent 64d0f50 commit 0ed0f1f
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 8 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ vergen = { version = "8", features = ["git", "gitcl"] }
[dependencies]
i18n-embed-fl = "0.8"
once_cell = "1.19.0"
env_logger = "0.11"
rust-embed = "8.3.0"
log = "0.4"
open = "5.0.2"
Expand Down
3 changes: 3 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use crate::app::config::{AppTheme, Repository};
use crate::fl;

use cosmic::app::{Command, Core};
use cosmic::iced::alignment::{Horizontal, Vertical};
use cosmic::iced::window;
Expand All @@ -23,6 +24,8 @@ use std::{env, process};

pub mod config;
pub mod menu;
// pub mod localize;
pub mod settings;

/// This is the struct that represents your application.
/// It is used to define the data that will be used by your application.
Expand Down
14 changes: 7 additions & 7 deletions src/core/localization.rs → src/app/localize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ use rust_embed::RustEmbed;
#[folder = "i18n/"]
struct Localizations;

pub static LANGUAGE_LOADER: Lazy<FluentLanguageLoader> = Lazy::new(|| {
let loader: FluentLanguageLoader = fluent_language_loader!();
// pub static LANGUAGE_LOADER: Lazy<FluentLanguageLoader> = Lazy::new(|| {
// let loader: FluentLanguageLoader = fluent_language_loader!();

loader
.load_fallback_language(&Localizations)
.expect("Error while loading fallback language");
// loader
// .load_fallback_language(&Localizations)
// .expect("Error while loading fallback language");

loader
});
// loader
// });

#[macro_export]
macro_rules! fl {
Expand Down
49 changes: 49 additions & 0 deletions src/app/settings.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// use crate::app::icon_cache::{IconCache, ICON_CACHE};
use crate::app::Flags;
use cosmic::app::Settings;
use cosmic::iced::{Limits, Size};
use std::sync::Mutex;

use super::config::CosmicBackupsConfig;
// use super::localize::set_localization;

pub fn init() -> (Settings, Flags) {
// set_localization();
// set_icon_cache();
set_logger();
let settings = get_app_settings();
let flags = get_flags();
(settings, flags)
}

pub fn get_app_settings() -> Settings {
let config = CosmicBackupsConfig::config();

let mut settings = Settings::default();
settings = settings.theme(config.app_theme.theme());
settings = settings.size_limits(Limits::NONE.min_width(400.0).min_height(180.0));
settings = settings.size(Size::new(800.0, 800.0));
settings = settings.debug(false);
settings
}

pub fn set_logger() {
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("warn")).init();
}

// pub fn set_icon_cache() {
// ICON_CACHE.get_or_init(|| Mutex::new(IconCache::new()));
// }

pub fn get_flags() -> Flags {
let (config_handler, config) = (
CosmicBackupsConfig::config_handler(),
CosmicBackupsConfig::config(),
);

let flags = Flags {
config_handler,
config,
};
flags
}
2 changes: 1 addition & 1 deletion src/core/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// SPDX-License-Identifier: GPL-3.0-only

pub mod localization;
// pub mod localization;

0 comments on commit 0ed0f1f

Please sign in to comment.