Skip to content

Commit

Permalink
fix: config issue
Browse files Browse the repository at this point in the history
  • Loading branch information
edfloreshz committed May 27, 2024
1 parent 46e2ef8 commit 4d94c45
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 40 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ tracing-subscriber = { version = "0.3.18", features = ["json"] }
[dependencies.libcosmic]
git = "https://github.com/pop-os/libcosmic.git"
default-features = false
features = ["dbus-config", "tokio", "winit", "wgpu"]
features = ["multi-window", "tokio", "winit", "wgpu"]

[dependencies.i18n-embed]
version = "0.14"
Expand Down
15 changes: 8 additions & 7 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{env, process};

use cosmic::app::{Command, Core};
use cosmic::iced::alignment::{Horizontal, Vertical};
use cosmic::iced::{window, event, Event, keyboard::Event as KeyEvent, Subscription};
use cosmic::iced::{event, keyboard::Event as KeyEvent, window, Event, Subscription};
use cosmic::iced_core::keyboard::{Key, Modifiers};
use cosmic::widget::menu::{
action::MenuAction,
Expand All @@ -21,7 +21,7 @@ use cosmic::{
};
use cosmic::{widget, Application, Apply, Element};

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

pub mod config;
Expand Down Expand Up @@ -302,7 +302,7 @@ impl Application for App {
if let Some(repository) = self.nav_model.data::<Repository>(entity) {
self.selected_repository = Some(repository.clone());
let window_title = format!("{} - {}", repository.name, fl!("cosmic-backups"));
commands.push(self.set_window_title(window_title));
commands.push(self.set_window_title(window_title, self.main_window_id()));
}

Command::batch(commands)
Expand All @@ -325,11 +325,11 @@ impl Application for App {
.into()
}

fn subscription(&self) -> Subscription<Self::Message> {
fn subscription(&self) -> Subscription<Self::Message> {
struct ConfigSubscription;
struct ThemeSubscription;

let mut subscriptions = vec![
let subscriptions = vec![
event::listen_with(|event, status| match event {
Event::Keyboard(KeyEvent::KeyPressed { key, modifiers, .. }) => match status {
event::Status::Ignored => Some(Message::Key(modifiers, key)),
Expand Down Expand Up @@ -433,10 +433,11 @@ impl Application for App {
.unwrap_or_default()
.to_string_lossy()
.to_string();
let mut repositories = self.config.repositories.clone();
let repository = Repository { name, path };
self.config.repositories.push(repository.clone());
repositories.push(repository.clone());
self.create_nav_item(repository);
config_set!(repositories, self.config.repositories.clone());
config_set!(repositories, repositories);
}
Err(e) => {
// TODO: Show error to user.
Expand Down
15 changes: 2 additions & 13 deletions src/app/settings.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
// use crate::app::icon_cache::{IconCache, ICON_CACHE};
use super::config::CosmicBackupsConfig;
use crate::app::Flags;
use log::info;
use cosmic::app::Settings;
use cosmic::iced::{Limits, Size};

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();
Expand All @@ -28,14 +22,9 @@ pub fn get_app_settings() -> Settings {
}

pub fn set_logger() {
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("warn")).init();
info!("Did not load repository information");
tracing_subscriber::fmt().json().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(),
Expand Down
21 changes: 2 additions & 19 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-only

use crate::app::App;
use app::{config::CosmicBackupsConfig, Flags};
use cosmic::app::Settings;

use tracing::info;
use tracing_subscriber;
use app::settings;

/// The `app` module is used by convention to indicate the main component of our application.
mod app;
Expand All @@ -18,19 +14,6 @@ mod core;
/// - `()` is the flags that your app needs to use before it starts.
/// If your app does not need any flags, you can pass in `()`.
fn main() -> cosmic::iced::Result {
tracing_subscriber::fmt()
.json()
.init();

let (settings, flags) = settings();
let (settings, flags) = settings::init();
cosmic::app::run::<App>(settings, flags)
}

fn settings() -> (Settings, Flags) {
let settings = Settings::default();
let flags = Flags {
config_handler: CosmicBackupsConfig::config_handler(),
config: CosmicBackupsConfig::config(),
};
(settings, flags)
}

0 comments on commit 4d94c45

Please sign in to comment.