Partial AppState rewrite
This commit is contained in:
1 parent
29a90d48d9
commit
0c4aec3dc0
13 files changed
+75
-49
No files matched your search
+15
-11
@@ -1,9 +1,10 @@
|
||||
use std::sync::Arc;
|
||||
use crate::data::Id;
|
||||
use crate::data::entities::DeckSettings;
|
||||
use crate::data::entities::{WordData, WordGroup};
|
||||
use crate::data_provider::decks::load_sets;
|
||||
use crate::data_provider::settings::get_setting;
|
||||
use crate::data_provider::sqlite::default_connection;
|
||||
use crate::data_provider::sqlite::{SqliteConnection};
|
||||
use crate::data_provider::words::{load_word_groups, load_words};
|
||||
use crate::navigation::RootMessage::Keyboard;
|
||||
use crate::navigation::{AppSettings, RootMessage, ScreenState};
|
||||
@@ -15,6 +16,7 @@ use iced_core::window::Position;
|
||||
use iced_core::window::settings::PlatformSpecific;
|
||||
use iced_core::{Font, Size, Theme};
|
||||
use log::info;
|
||||
use parking_lot::RwLock;
|
||||
use rusqlite::Connection;
|
||||
pub const USER_FONT: Font = Font::with_name("Noto Sans JP");
|
||||
|
||||
@@ -57,12 +59,13 @@ fn subscription(_state: &ScreenState) -> Subscription<RootMessage> {
|
||||
keyboard::listen().map(Keyboard)
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct AppState {
|
||||
pub dictionary: Vec<WordData>,
|
||||
pub decks: Vec<DeckSettings>,
|
||||
pub word_groups: Vec<WordGroup>,
|
||||
pub connection: Connection,
|
||||
pub sync_data: AppSettings,
|
||||
pub connection: Arc<RwLock<SqliteConnection>>,
|
||||
pub sync_data: Arc<RwLock<AppSettings>>,
|
||||
pub activity: HashMap<Id, Vec<(NaiveDate, u32)>>,
|
||||
}
|
||||
|
||||
@@ -78,26 +81,27 @@ impl AppState {
|
||||
dictionary: vec![],
|
||||
decks: vec![],
|
||||
word_groups: vec![],
|
||||
connection: default_connection(),
|
||||
sync_data: AppSettings {
|
||||
connection: Arc::new(RwLock::new(Default::default())),
|
||||
sync_data: Arc::new(RwLock::new(AppSettings {
|
||||
key: None,
|
||||
auto_web_fetch: false,
|
||||
},
|
||||
})),
|
||||
activity: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fill_state(state: &mut AppState) {
|
||||
let list = load_words(&state.connection);
|
||||
let sets = load_sets(&state.connection);
|
||||
let groups = load_word_groups(&state.connection);
|
||||
let setting = load_settings(&state.connection);
|
||||
let connection = state.connection.read();
|
||||
let list = load_words(&connection);
|
||||
let sets = load_sets(&connection);
|
||||
let groups = load_word_groups(&connection);
|
||||
let setting = load_settings(&connection);
|
||||
|
||||
state.dictionary = list.unwrap_or_default();
|
||||
state.decks = sets.unwrap_or_default();
|
||||
state.word_groups = groups.unwrap_or_default();
|
||||
state.sync_data = setting
|
||||
state.sync_data = Arc::new(RwLock::new(setting))
|
||||
}
|
||||
|
||||
fn load_settings(connection: &Connection) -> AppSettings {
|
||||
|
||||
Reference in new issue
Block a user