2026-08-13 09:06:22 +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-08-04 16:53:09 +03:00
|
|
|
mod repetition_settings;
|
2026-08-13 22:03:47 +03:00
|
|
|
pub mod import;
|
2026-08-15 20:16:48 +03:00
|
|
|
pub mod helpers;
|
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-13 11:56:25 +03:00
|
|
|
use crate::data_provider::sqlite::default_connection;
|
2026-08-01 13:04:18 +03:00
|
|
|
use crate::data_provider::words::{load_word_groups, load_words};
|
2026-08-15 20:16:48 +03:00
|
|
|
use crate::lang::{CardSetSettings, 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-04-17 12:38:05 +03:00
|
|
|
use crate::RootMessage::Keyboard;
|
2026-08-13 11:56:25 +03:00
|
|
|
use chrono::NaiveDate;
|
2026-08-14 23:52:48 +03:00
|
|
|
use iced::{keyboard, Subscription, Theme};
|
2026-08-13 11:56:25 +03:00
|
|
|
use iced::{window, Font};
|
2026-08-04 14:09:40 +03:00
|
|
|
use iced_core::window::Position;
|
2026-08-13 11:56:25 +03:00
|
|
|
use iced_core::Size;
|
2026-04-13 22:25:58 +03:00
|
|
|
use rusqlite::Connection;
|
2026-08-13 11:56:25 +03:00
|
|
|
use std::collections::HashMap;
|
2026-08-13 17:39:00 +03:00
|
|
|
use iced_core::window::settings::PlatformSpecific;
|
2026-08-14 23:03:15 +03:00
|
|
|
use mimalloc::MiMalloc;
|
|
|
|
|
|
|
|
|
|
#[global_allocator]
|
|
|
|
|
static GLOBAL: MiMalloc = MiMalloc;
|
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-08-13 12:18:03 +03:00
|
|
|
println!("Welcome to JapLearn");
|
2026-08-13 22:38:48 +03:00
|
|
|
iced::application(ScreenState::boot, ScreenState::update, ScreenState::view).window(window_settings())
|
2026-05-05 12:02:59 +03:00
|
|
|
.subscription(subscription)
|
2026-08-13 17:39:00 +03:00
|
|
|
.title("JapLearn")
|
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-08-13 22:38:48 +03:00
|
|
|
.theme(Theme::GruvboxDark).run()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn window_settings() -> window::Settings {
|
|
|
|
|
let mut settings = window::Settings{
|
|
|
|
|
position: Position::Centered,
|
2026-08-15 13:22:59 +03:00
|
|
|
min_size: Some(Size::new(700.0_f32, 700.0_f32)),
|
2026-08-13 22:38:48 +03:00
|
|
|
.. Default::default()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
|
{
|
|
|
|
|
settings.platform_specific =
|
|
|
|
|
PlatformSpecific {
|
|
|
|
|
application_id: "JapLearn".to_string(),
|
|
|
|
|
override_redirect: false
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
settings
|
2026-02-10 11:28:12 +03:00
|
|
|
}
|
|
|
|
|
|
2026-04-14 15:19:46 +03:00
|
|
|
fn subscription(_state: &ScreenState) -> Subscription<RootMessage> {
|
2026-08-15 13:22:59 +03:00
|
|
|
keyboard::listen().map(Keyboard)
|
2026-04-14 15:19:46 +03:00
|
|
|
}
|
|
|
|
|
|
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,
|
2026-08-04 16:53:09 +03:00
|
|
|
pub activity: HashMap<u32, Vec<(NaiveDate, u32)>>
|
2026-08-01 01:22:26 +03:00
|
|
|
}
|
|
|
|
|
|
2026-08-15 13:22:59 +03:00
|
|
|
impl Default for AppState {
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
Self::new()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-01 01:22:26 +03:00
|
|
|
impl AppState {
|
|
|
|
|
pub fn new() -> Self {
|
2026-08-13 09:06:22 +03:00
|
|
|
|
2026-08-01 01:22:26 +03:00
|
|
|
|
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![],
|
2026-08-13 09:06:22 +03:00
|
|
|
connection: default_connection(),
|
|
|
|
|
sync_data: AppSettings { key: None, auto_web_fetch: false },
|
2026-08-04 16:53:09 +03:00
|
|
|
activity: Default::default(),
|
2026-08-01 01:22:26 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
2026-08-13 09:06:22 +03:00
|
|
|
let fetch = get_setting("AUTO_WEB_FETCH".to_string(), connection).unwrap_or("false".to_string()).parse::<bool>().unwrap();
|
|
|
|
|
AppSettings { key, auto_web_fetch: fetch }
|
2026-06-01 15:36:53 +03:00
|
|
|
}
|