2026-08-25 12:04:07 +03:00
|
|
|
use crate::data::Id;
|
|
|
|
|
use crate::data::entities::DeckSettings;
|
|
|
|
|
use crate::data::entities::{WordData, WordGroup};
|
|
|
|
|
use crate::data_provider::card_sets::load_sets;
|
|
|
|
|
use crate::data_provider::settings::get_setting;
|
|
|
|
|
use crate::data_provider::sqlite::default_connection;
|
|
|
|
|
use crate::data_provider::words::{load_word_groups, load_words};
|
|
|
|
|
use crate::navigation::RootMessage::Keyboard;
|
|
|
|
|
use crate::navigation::{AppSettings, RootMessage, ScreenState};
|
2026-08-23 21:49:01 +03:00
|
|
|
use chrono::NaiveDate;
|
|
|
|
|
use hashbrown::HashMap;
|
2026-08-25 12:04:07 +03:00
|
|
|
use iced::{Subscription, keyboard, window};
|
2026-08-23 21:49:01 +03:00
|
|
|
use iced_core::window::Position;
|
2026-08-24 01:37:00 +03:00
|
|
|
#[cfg(target_os = "linux")]
|
2026-08-23 21:49:01 +03:00
|
|
|
use iced_core::window::settings::PlatformSpecific;
|
2026-08-25 12:04:07 +03:00
|
|
|
use iced_core::{Font, Size, Theme};
|
2026-08-23 22:48:00 +03:00
|
|
|
use log::info;
|
2026-08-23 21:49:01 +03:00
|
|
|
use rusqlite::Connection;
|
|
|
|
|
pub const USER_FONT: Font = Font::with_name("Noto Sans JP");
|
|
|
|
|
|
|
|
|
|
pub fn start() -> iced::Result {
|
2026-08-23 22:48:00 +03:00
|
|
|
info!("Welcome to JapLearn");
|
2026-08-23 21:49:01 +03:00
|
|
|
iced::application(ScreenState::boot, ScreenState::update, ScreenState::view)
|
|
|
|
|
.window(window_settings())
|
|
|
|
|
.subscription(subscription)
|
|
|
|
|
.title("JapLearn")
|
|
|
|
|
.settings(iced::Settings {
|
|
|
|
|
default_text_size: iced::Pixels(18.0),
|
|
|
|
|
..iced::Settings::default()
|
|
|
|
|
})
|
|
|
|
|
.font(include_bytes!("../noto.ttf"))
|
|
|
|
|
.default_font(USER_FONT)
|
|
|
|
|
.theme(Theme::GruvboxDark)
|
|
|
|
|
.run()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[allow(unused_mut)]
|
|
|
|
|
fn window_settings() -> window::Settings {
|
|
|
|
|
let mut settings = window::Settings {
|
|
|
|
|
position: Position::Centered,
|
|
|
|
|
min_size: Some(Size::new(700.0_f32, 700.0_f32)),
|
|
|
|
|
..Default::default()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
|
{
|
|
|
|
|
settings.platform_specific = PlatformSpecific {
|
|
|
|
|
application_id: "JapLearn".to_string(),
|
|
|
|
|
override_redirect: false,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
settings
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn subscription(_state: &ScreenState) -> Subscription<RootMessage> {
|
|
|
|
|
keyboard::listen().map(Keyboard)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct AppState {
|
|
|
|
|
pub dictionary: Vec<WordData>,
|
|
|
|
|
pub decks: Vec<DeckSettings>,
|
|
|
|
|
pub word_groups: Vec<WordGroup>,
|
|
|
|
|
pub connection: Connection,
|
|
|
|
|
pub sync_data: AppSettings,
|
|
|
|
|
pub activity: HashMap<Id, Vec<(NaiveDate, u32)>>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Default for AppState {
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
Self::new()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl AppState {
|
|
|
|
|
pub fn new() -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
dictionary: vec![],
|
|
|
|
|
decks: vec![],
|
|
|
|
|
word_groups: vec![],
|
|
|
|
|
connection: default_connection(),
|
|
|
|
|
sync_data: 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);
|
|
|
|
|
|
2026-08-24 18:46:54 +03:00
|
|
|
state.dictionary = list.unwrap_or_default();
|
2026-08-24 17:33:21 +03:00
|
|
|
state.decks = sets.unwrap_or_default();
|
2026-08-24 18:46:54 +03:00
|
|
|
state.word_groups = groups.unwrap_or_default();
|
2026-08-23 21:49:01 +03:00
|
|
|
state.sync_data = setting
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn load_settings(connection: &Connection) -> AppSettings {
|
|
|
|
|
let key = get_setting("SYNC_KEY".to_string(), connection);
|
|
|
|
|
let fetch = get_setting("AUTO_WEB_FETCH".to_string(), connection)
|
|
|
|
|
.unwrap_or("false".to_string())
|
|
|
|
|
.parse::<bool>()
|
|
|
|
|
.unwrap();
|
|
|
|
|
AppSettings {
|
|
|
|
|
key,
|
|
|
|
|
auto_web_fetch: fetch,
|
|
|
|
|
}
|
|
|
|
|
}
|