99 lines
2.5 KiB
Rust
99 lines
2.5 KiB
Rust
// #![windows_subsystem = "windows"]
|
|
mod data_provider;
|
|
mod dictionary;
|
|
mod dictionary_test;
|
|
mod lang;
|
|
mod quiz;
|
|
mod randomizer;
|
|
mod repetition;
|
|
mod repetitions;
|
|
mod selector;
|
|
mod sync;
|
|
mod word;
|
|
mod writing;
|
|
mod history;
|
|
pub mod navigation;
|
|
pub mod styling;
|
|
|
|
use crate::data_provider::card_sets::load_sets;
|
|
use crate::data_provider::settings::get_setting;
|
|
use crate::data_provider::words::{load_word_groups, load_words};
|
|
use crate::dictionary::app_data_dir;
|
|
use crate::lang::{WordData, WordGroup};
|
|
use crate::navigation::{AppSettings, RootMessage, ScreenState};
|
|
use crate::quiz::*;
|
|
use crate::repetitions::CardSetSettings;
|
|
use crate::RootMessage::Keyboard;
|
|
use iced::Font;
|
|
use iced::{keyboard, Program, Subscription, Theme};
|
|
use rusqlite::Connection;
|
|
|
|
|
|
const USER_FONT: Font = Font::with_name("Noto Sans JP");
|
|
|
|
fn main() -> iced::Result {
|
|
|
|
iced::application(ScreenState::boot, ScreenState::update, ScreenState::view)
|
|
.subscription(subscription)
|
|
.title("Kana learn app")
|
|
.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()
|
|
}
|
|
|
|
fn subscription(_state: &ScreenState) -> Subscription<RootMessage> {
|
|
keyboard::listen().map(|e| Keyboard(e))
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
Self{
|
|
dictionary: vec![],
|
|
card_sets: vec![],
|
|
word_groups: vec![],
|
|
connection,
|
|
sync_data: AppSettings { key: None },
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
state.dictionary = list;
|
|
state.card_sets = sets;
|
|
state.word_groups = groups;
|
|
state.sync_data = setting
|
|
}
|
|
|
|
fn load_settings(connection: &Connection) -> AppSettings {
|
|
let key = get_setting("SYNC_KEY".to_string(), connection);
|
|
AppSettings { key }
|
|
}
|
|
|