Files
jap_learn/src/main.rs
T

91 lines
2.5 KiB
Rust
Raw Normal View History

2026-08-01 13:04:18 +03:00
// #![windows_subsystem = "windows"]
2026-05-05 12:02:59 +03:00
mod data_provider;
2026-04-09 22:45:31 +03:00
mod dictionary;
mod dictionary_test;
2026-08-01 19:43:07 +03:00
mod history;
2026-02-10 11:28:12 +03:00
mod lang;
2026-08-01 19:43:07 +03:00
pub mod navigation;
2026-02-10 12:12:16 +03:00
mod quiz;
2026-04-09 22:45:31 +03:00
mod randomizer;
mod repetition;
mod repetitions;
2026-02-10 12:12:16 +03:00
mod selector;
2026-08-01 19:43:07 +03:00
pub mod styling;
2026-06-01 15:36:53 +03:00
mod sync;
2026-04-17 12:38:05 +03:00
mod word;
2026-05-05 12:02:59 +03:00
mod writing;
2026-04-17 12:38:05 +03:00
2026-04-13 22:25:58 +03:00
use crate::data_provider::card_sets::load_sets;
2026-06-01 15:36:53 +03:00
use crate::data_provider::settings::get_setting;
2026-08-01 13:04:18 +03:00
use crate::data_provider::words::{load_word_groups, load_words};
use crate::dictionary::app_data_dir;
2026-05-05 12:02:59 +03:00
use crate::lang::{WordData, WordGroup};
2026-08-01 13:04:18 +03:00
use crate::navigation::{AppSettings, RootMessage, ScreenState};
2026-02-10 12:12:16 +03:00
use crate::quiz::*;
2026-08-01 13:04:18 +03:00
use crate::repetitions::CardSetSettings;
2026-04-17 12:38:05 +03:00
use crate::RootMessage::Keyboard;
2026-08-01 13:04:18 +03:00
use iced::Font;
2026-08-01 19:36:43 +03:00
use iced::{keyboard, Program, Subscription, Theme};
2026-04-13 22:25:58 +03:00
use rusqlite::Connection;
2026-02-10 11:28:12 +03:00
2026-07-31 23:03:40 +03:00
const USER_FONT: Font = Font::with_name("Noto Sans JP");
2026-02-10 11:28:12 +03:00
fn main() -> iced::Result {
2026-05-05 12:02:59 +03:00
iced::application(ScreenState::boot, ScreenState::update, ScreenState::view)
.subscription(subscription)
2026-04-09 22:45:31 +03:00
.title("Kana learn app")
2026-08-01 19:43:07 +03:00
.settings(iced::Settings {
2026-08-01 13:04:18 +03:00
default_text_size: iced::Pixels(18.0),
..iced::Settings::default()
})
2026-04-09 22:45:31 +03:00
.font(include_bytes!("../noto.ttf"))
2026-08-01 01:22:26 +03:00
.default_font(USER_FONT)
2026-07-31 23:03:40 +03:00
.theme(Theme::GruvboxDark)
2026-05-05 12:02:59 +03:00
.run()
2026-02-10 11:28:12 +03:00
}
2026-04-14 15:19:46 +03:00
fn subscription(_state: &ScreenState) -> Subscription<RootMessage> {
keyboard::listen().map(|e| Keyboard(e))
}
2026-08-01 01:22:26 +03:00
pub struct AppState {
pub dictionary: Vec<WordData>,
pub card_sets: Vec<CardSetSettings>,
pub word_groups: Vec<WordGroup>,
pub connection: Connection,
pub sync_data: AppSettings,
}
impl AppState {
pub fn new() -> Self {
let path = app_data_dir();
let db_file = path.join("data.db");
let connection = Connection::open(db_file).unwrap();
connection.execute("PRAGMA foreign_keys = ON;", []).unwrap();
2026-08-01 19:43:07 +03:00
Self {
2026-08-01 01:22:26 +03:00
dictionary: vec![],
card_sets: vec![],
word_groups: vec![],
connection,
sync_data: AppSettings { key: None },
}
}
}
2026-07-31 23:03:40 +03:00
fn fill_state(state: &mut AppState) {
2026-07-29 13:52:47 +03:00
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);
state.dictionary = list;
state.card_sets = sets;
state.word_groups = groups;
state.sync_data = setting
}
2026-06-01 15:36:53 +03:00
fn load_settings(connection: &Connection) -> AppSettings {
let key = get_setting("SYNC_KEY".to_string(), connection);
AppSettings { key }
}