Formatting
This commit is contained in:
1 parent
dddac01bdf
commit
10cf7f0d2e
28 files changed
+130
-130
No files matched your search
+12
-12
@@ -1,21 +1,21 @@
|
||||
use chrono::NaiveDate;
|
||||
use hashbrown::HashMap;
|
||||
use iced::{keyboard, window, Subscription};
|
||||
use iced_core::{Font, Size, Theme};
|
||||
use iced_core::window::Position;
|
||||
#[cfg(target_os = "linux")]
|
||||
use iced_core::window::settings::PlatformSpecific;
|
||||
use log::info;
|
||||
use rusqlite::Connection;
|
||||
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::data::entities::{ WordData, WordGroup};
|
||||
use crate::data::Id;
|
||||
use crate::navigation::{AppSettings, RootMessage, ScreenState};
|
||||
use crate::navigation::RootMessage::Keyboard;
|
||||
use crate::navigation::{AppSettings, RootMessage, ScreenState};
|
||||
use chrono::NaiveDate;
|
||||
use hashbrown::HashMap;
|
||||
use iced::{Subscription, keyboard, window};
|
||||
use iced_core::window::Position;
|
||||
#[cfg(target_os = "linux")]
|
||||
use iced_core::window::settings::PlatformSpecific;
|
||||
use iced_core::{Font, Size, Theme};
|
||||
use log::info;
|
||||
use rusqlite::Connection;
|
||||
pub const USER_FONT: Font = Font::with_name("Noto Sans JP");
|
||||
|
||||
pub fn start() -> iced::Result {
|
||||
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
pub mod deck;
|
||||
pub mod kana_set;
|
||||
pub mod srs;
|
||||
pub mod deck;
|
||||
+1
-2
@@ -161,8 +161,7 @@ impl WorstWordsSRSModule {
|
||||
}
|
||||
}
|
||||
fn fill_pool(&mut self, set: &[CardStatistics]) {
|
||||
let mut sorted = set.iter().enumerate()
|
||||
.collect::<Vec<_>>();
|
||||
let mut sorted = set.iter().enumerate().collect::<Vec<_>>();
|
||||
sorted.sort_by_key(|c| c.1.score);
|
||||
let mut worst = sorted[0..self.pool_size]
|
||||
.iter()
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
pub mod entities;
|
||||
|
||||
use rusqlite::ToSql;
|
||||
use rusqlite::types::{FromSql, FromSqlError, FromSqlResult, ToSqlOutput, ValueRef};
|
||||
use std::fmt::{Display, Formatter};
|
||||
use std::num::ParseIntError;
|
||||
use std::str::FromStr;
|
||||
use rusqlite::ToSql;
|
||||
use rusqlite::types::{FromSql, FromSqlError, FromSqlResult, ToSqlOutput, ValueRef};
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, Hash, Copy, Ord, PartialOrd, Default)]
|
||||
pub struct Id(pub(crate) u32);
|
||||
|
||||
@@ -111,7 +111,7 @@ impl DeckSettings {
|
||||
|
||||
let result = engine.eval_ast_with_scope::<bool>(&mut scope, &ast);
|
||||
if let Ok(result) = result {
|
||||
return result
|
||||
return result;
|
||||
}
|
||||
false
|
||||
})
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use crate::core::srs::OrderMode;
|
||||
|
||||
use crate::data::entities::DeckSettings;
|
||||
use rusqlite::Connection;
|
||||
use crate::notification::{MaybeError, NotificationData};
|
||||
use crate::notification::NotificationData::{DbLoadError, DbSaveError};
|
||||
use crate::notification::{MaybeError, NotificationData};
|
||||
use rusqlite::Connection;
|
||||
|
||||
pub fn load_sets(connection: &Connection) -> Result<Vec<DeckSettings>, NotificationData> {
|
||||
let mut stmt = connection
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::data::entities::{CardStatistics, DeckSettings};
|
||||
use crate::notification::{MaybeError, NotificationData};
|
||||
use crate::notification::NotificationData::{DbLoadError, DbSaveError};
|
||||
use crate::notification::{MaybeError, NotificationData};
|
||||
use log::info;
|
||||
use rusqlite::{Connection, params};
|
||||
use std::time::Instant;
|
||||
@@ -32,7 +32,9 @@ pub fn load_stats_of_deck(
|
||||
|
||||
pub fn add_stat_list(stats: &mut [CardStatistics], connection: &mut Connection) -> MaybeError {
|
||||
let time = Instant::now();
|
||||
let tx = connection.transaction().expect("Failed to create transaction");
|
||||
let tx = connection
|
||||
.transaction()
|
||||
.expect("Failed to create transaction");
|
||||
let count = stats.len();
|
||||
|
||||
{
|
||||
|
||||
@@ -2,8 +2,8 @@ use crate::core::srs::WordOpenMode;
|
||||
use crate::data::Id;
|
||||
use crate::data::entities::HistoryItem;
|
||||
use crate::fs::*;
|
||||
use crate::notification::{MaybeError, NotificationData};
|
||||
use crate::notification::NotificationData::PermissionDenied;
|
||||
use crate::notification::{MaybeError, NotificationData};
|
||||
use chrono::DateTime;
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::io::Write;
|
||||
@@ -29,7 +29,6 @@ fn append_lines_if_exists(path: PathBuf, lines: &mut Vec<String>) -> MaybeError
|
||||
.for_each(|i| lines.push(i));
|
||||
}
|
||||
Ok(())
|
||||
|
||||
}
|
||||
|
||||
fn parse_history_items(strings: Vec<String>) -> Vec<HistoryItem> {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use crate::helpers::into_result;
|
||||
use crate::notification::NotificationData;
|
||||
use crate::notification::NotificationData::IncorrectAnkiFile;
|
||||
use hashbrown::HashMap;
|
||||
use log::info;
|
||||
use rusqlite::Connection;
|
||||
use serde_json::Value;
|
||||
use crate::helpers::into_result;
|
||||
use crate::notification::NotificationData::IncorrectAnkiFile;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ImportData(pub(crate) Vec<ImportGroup>);
|
||||
@@ -29,8 +29,7 @@ pub fn load_groups(connection: &Connection) -> Result<ImportData, NotificationDa
|
||||
let json_models: String = connection
|
||||
.query_one("select models from col", (), |row| row.get(0))
|
||||
.map_err(|_| IncorrectAnkiFile)?;
|
||||
let raw: Value = serde_json::from_str(json_models.as_str())
|
||||
.map_err(|_| IncorrectAnkiFile)?;
|
||||
let raw: Value = serde_json::from_str(json_models.as_str()).map_err(|_| IncorrectAnkiFile)?;
|
||||
let sets = raw.as_object();
|
||||
if let Some(sets) = sets {
|
||||
let mut total_data = ImportData(vec![]);
|
||||
@@ -48,14 +47,13 @@ pub fn load_groups(connection: &Connection) -> Result<ImportData, NotificationDa
|
||||
for (_, collection) in sets {
|
||||
let fields_property = collection.get("fields");
|
||||
if let Some(fields_property) = fields_property {
|
||||
let fields = into_result(fields_property
|
||||
.as_array(), IncorrectAnkiFile)?
|
||||
let fields = into_result(fields_property.as_array(), IncorrectAnkiFile)?
|
||||
.iter()
|
||||
.filter_map(|x| x.get("name"))
|
||||
.map(|x| x.as_str().unwrap().to_string())
|
||||
.collect();
|
||||
let id = collection.get("id");
|
||||
if id.is_none() || id.unwrap().as_u64().is_none(){
|
||||
if id.is_none() || id.unwrap().as_u64().is_none() {
|
||||
return Err(IncorrectAnkiFile);
|
||||
}
|
||||
let id = id.unwrap().as_u64().unwrap();
|
||||
@@ -80,12 +78,15 @@ pub fn load_groups(connection: &Connection) -> Result<ImportData, NotificationDa
|
||||
total_data.0.push(group);
|
||||
}
|
||||
}
|
||||
return Ok(total_data)
|
||||
return Ok(total_data);
|
||||
}
|
||||
Err(IncorrectAnkiFile)
|
||||
}
|
||||
|
||||
pub fn get_words_of_group(connection: &Connection, group_id: u64) -> Result<Vec<ImportNote>, NotificationData> {
|
||||
pub fn get_words_of_group(
|
||||
connection: &Connection,
|
||||
group_id: u64,
|
||||
) -> Result<Vec<ImportNote>, NotificationData> {
|
||||
let mut count_stmt = connection
|
||||
.prepare("select tags, flds from notes where mid == ?1;")
|
||||
.map_err(|_| IncorrectAnkiFile)?;
|
||||
|
||||
@@ -17,11 +17,7 @@ pub fn get_setting(key: String, connection: &Connection) -> Option<String> {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn set_setting(
|
||||
key: String,
|
||||
value: String,
|
||||
connection: &Connection,
|
||||
) -> MaybeError {
|
||||
pub fn set_setting(key: String, value: String, connection: &Connection) -> MaybeError {
|
||||
let current = get_settings_list(connection)?;
|
||||
if current.contains(&key) {
|
||||
update_settings(key, value, connection)?;
|
||||
@@ -39,11 +35,7 @@ pub fn delete_settings(key: String, connection: &Connection) -> MaybeError {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn create_settings(
|
||||
key: String,
|
||||
value: String,
|
||||
connection: &Connection,
|
||||
) -> MaybeError {
|
||||
fn create_settings(key: String, value: String, connection: &Connection) -> MaybeError {
|
||||
connection
|
||||
.execute(
|
||||
"INSERT into settings (id, value) VALUES (?1, ?2)",
|
||||
@@ -53,11 +45,7 @@ fn create_settings(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update_settings(
|
||||
key: String,
|
||||
value: String,
|
||||
connection: &Connection,
|
||||
) -> MaybeError {
|
||||
fn update_settings(key: String, value: String, connection: &Connection) -> MaybeError {
|
||||
connection
|
||||
.execute(
|
||||
"update settings
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
use rusqlite::Connection;
|
||||
use crate::fs::*;
|
||||
use rusqlite::Connection;
|
||||
|
||||
pub fn create_db() {
|
||||
let db_file = db_path();
|
||||
if !db_file.exists() {
|
||||
std::fs::File::create(&db_file).expect("Database file creation failed");
|
||||
let connection = Connection::open(&db_file).expect("Connection open failed");
|
||||
connection.execute("PRAGMA foreign_keys = ON;", []).expect("Failed to set PRAGMA");
|
||||
connection
|
||||
.execute("PRAGMA foreign_keys = ON;", [])
|
||||
.expect("Failed to set PRAGMA");
|
||||
|
||||
create_tables(&connection);
|
||||
}
|
||||
@@ -52,6 +54,8 @@ fn make_card_stats(conn: &Connection) -> Result<(), rusqlite::Error> {
|
||||
pub fn default_connection() -> Connection {
|
||||
let db_file = db_path();
|
||||
let connection = Connection::open(db_file).expect("Failed to open database");
|
||||
connection.execute("PRAGMA foreign_keys = ON;", []).expect("Failed to set PRAGMA");
|
||||
connection
|
||||
.execute("PRAGMA foreign_keys = ON;", [])
|
||||
.expect("Failed to set PRAGMA");
|
||||
connection
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
use crate::fs::*;
|
||||
use crate::notification::NotificationData;
|
||||
use crate::notification::NotificationData::*;
|
||||
use reqwest::Client;
|
||||
use sha2::{Digest, Sha256};
|
||||
use std::fs::File;
|
||||
use std::io::BufReader;
|
||||
use crate::fs::*;
|
||||
use crate::notification::NotificationData;
|
||||
use crate::notification::NotificationData::*;
|
||||
|
||||
pub async fn get_voice(text: &str) -> Result<BufReader<File>, NotificationData> {
|
||||
let mut path = voice_dir()?;
|
||||
@@ -19,7 +19,11 @@ pub async fn get_voice(text: &str) -> Result<BufReader<File>, NotificationData>
|
||||
.send()
|
||||
.await;
|
||||
|
||||
let query = query.map_err(|_| VoiceVoxUnavailable)?.text().await.map_err(|_| VoiceVoxUnavailable)?;
|
||||
let query = query
|
||||
.map_err(|_| VoiceVoxUnavailable)?
|
||||
.text()
|
||||
.await
|
||||
.map_err(|_| VoiceVoxUnavailable)?;
|
||||
// Synthesis
|
||||
let audio = client
|
||||
.post(format!("{engine_url}/synthesis?speaker=11"))
|
||||
@@ -32,8 +36,12 @@ pub async fn get_voice(text: &str) -> Result<BufReader<File>, NotificationData>
|
||||
.await
|
||||
.map_err(|_| VoiceVoxUnavailable)?;
|
||||
|
||||
tokio::fs::write(&path, &audio).await.map_err(|_| PermissionDenied)?;
|
||||
tokio::fs::write(&path, &audio)
|
||||
.await
|
||||
.map_err(|_| PermissionDenied)?;
|
||||
}
|
||||
|
||||
Ok(BufReader::new(File::open(path).map_err(|_| PermissionDenied)?))
|
||||
Ok(BufReader::new(
|
||||
File::open(path).map_err(|_| PermissionDenied)?,
|
||||
))
|
||||
}
|
||||
@@ -5,7 +5,7 @@ use log::info;
|
||||
use std::io;
|
||||
use tokio::fs::{File, OpenOptions};
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
use zstd::{Decoder, Encoder, DEFAULT_COMPRESSION_LEVEL};
|
||||
use zstd::{DEFAULT_COMPRESSION_LEVEL, Decoder, Encoder};
|
||||
|
||||
// const API_URL: &str = "http://127.0.0.1:8089/";
|
||||
const API_URL: &str = "https://learning.micialware.ru/";
|
||||
|
||||
+11
-12
@@ -1,6 +1,6 @@
|
||||
use crate::data::entities::{WordData, WordGroup};
|
||||
use crate::notification::{MaybeError, NotificationData};
|
||||
use crate::notification::NotificationData::{DbLoadError, DbSaveError};
|
||||
use crate::notification::{MaybeError, NotificationData};
|
||||
use rusqlite::{Connection, params};
|
||||
use std::collections::HashMap;
|
||||
|
||||
@@ -22,10 +22,7 @@ pub fn add_word(word: &mut WordData, connection: &Connection) -> MaybeError {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn add_words(
|
||||
words: &mut [WordData],
|
||||
connection: &mut Connection,
|
||||
) -> MaybeError {
|
||||
pub fn add_words(words: &mut [WordData], connection: &mut Connection) -> MaybeError {
|
||||
let tx = connection.transaction().map_err(|_| DbLoadError)?;
|
||||
let count = words.len();
|
||||
|
||||
@@ -102,14 +99,17 @@ pub fn load_words(connection: &Connection) -> Result<Vec<WordData>, Notification
|
||||
key: row.get(1)?,
|
||||
value: row.get(2)?,
|
||||
tags: row.get(3)?,
|
||||
additional: serde_json::from_str::<HashMap<String, String>>(&additional).unwrap_or_default(),
|
||||
additional: serde_json::from_str::<HashMap<String, String>>(&additional)
|
||||
.unwrap_or_default(),
|
||||
group_id: row.get(5)?,
|
||||
})
|
||||
})
|
||||
.map_err(|_| DbLoadError)?;
|
||||
|
||||
let mut buffer = Vec::with_capacity(1024);
|
||||
word_iter.filter_map(|res| res.ok()).for_each(|i| buffer.push(i));
|
||||
word_iter
|
||||
.filter_map(|res| res.ok())
|
||||
.for_each(|i| buffer.push(i));
|
||||
|
||||
Ok(buffer)
|
||||
}
|
||||
@@ -128,7 +128,9 @@ pub fn load_word_groups(connection: &Connection) -> Result<Vec<WordGroup>, Notif
|
||||
.map_err(|_| DbLoadError)?;
|
||||
|
||||
let mut buffer = Vec::with_capacity(8);
|
||||
group_iter.filter_map(|res| res.ok()).for_each(|i| buffer.push(i));
|
||||
group_iter
|
||||
.filter_map(|res| res.ok())
|
||||
.for_each(|i| buffer.push(i));
|
||||
|
||||
Ok(buffer)
|
||||
}
|
||||
@@ -146,10 +148,7 @@ pub fn add_group(group: &mut WordGroup, connection: &Connection) -> MaybeError {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn update_group(
|
||||
group: &mut WordGroup,
|
||||
connection: &Connection,
|
||||
) -> MaybeError {
|
||||
pub fn update_group(group: &mut WordGroup, connection: &Connection) -> MaybeError {
|
||||
if !group.id.is_valid() {
|
||||
Ok(add_group(group, connection)?)
|
||||
} else {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
use crate::notification::NotificationData;
|
||||
use crate::notification::NotificationData::PermissionDenied;
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub fn app_data_dir() -> PathBuf {
|
||||
let mut dir = dirs::data_dir().expect("Unsupported OS");
|
||||
|
||||
+7
-6
@@ -2,22 +2,23 @@
|
||||
macro_rules! push_error_task {
|
||||
($e:expr) => {
|
||||
iced::Task::done(push_error!($e))
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! push_error {
|
||||
($e:expr) => {
|
||||
$crate::navigation::RootMessage::PushNotification($crate::notification::NotificationRequest::Error($e))
|
||||
}
|
||||
$crate::navigation::RootMessage::PushNotification(
|
||||
$crate::notification::NotificationRequest::Error($e),
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn into_result<R, E>(option: Option<R>, error: E) -> Result<R, E>{
|
||||
pub fn into_result<R, E>(option: Option<R>, error: E) -> Result<R, E> {
|
||||
if let Some(r) = option {
|
||||
Ok(r)
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Err(error)
|
||||
}
|
||||
}
|
||||
+6
-7
@@ -1,14 +1,14 @@
|
||||
#![windows_subsystem = "windows"]
|
||||
mod data_provider;
|
||||
pub mod notification;
|
||||
pub mod app;
|
||||
mod styling;
|
||||
mod pages;
|
||||
mod navigation;
|
||||
mod fs;
|
||||
mod core;
|
||||
mod data;
|
||||
mod data_provider;
|
||||
mod fs;
|
||||
pub mod helpers;
|
||||
mod navigation;
|
||||
pub mod notification;
|
||||
mod pages;
|
||||
mod styling;
|
||||
|
||||
use crate::app::start;
|
||||
use mimalloc::MiMalloc;
|
||||
@@ -16,7 +16,6 @@ use mimalloc::MiMalloc;
|
||||
#[global_allocator]
|
||||
static GLOBAL: MiMalloc = MiMalloc;
|
||||
|
||||
|
||||
fn main() -> iced::Result {
|
||||
env_logger::init();
|
||||
start()
|
||||
|
||||
+4
-3
@@ -1,4 +1,4 @@
|
||||
use crate::app::{fill_state, AppState};
|
||||
use crate::app::{AppState, fill_state};
|
||||
use crate::data::Id;
|
||||
use crate::data_provider::history::get_history_of_set;
|
||||
use crate::data_provider::sqlite::{create_db, default_connection};
|
||||
@@ -109,8 +109,9 @@ impl ScreenState {
|
||||
create_db();
|
||||
info!("Db created");
|
||||
let state = ScreenState::default();
|
||||
let reading_additional_task =
|
||||
Task::perform(Self::load_additional_data(), |data| data.unwrap_or_else(|err| push_error!(err)));
|
||||
let reading_additional_task = Task::perform(Self::load_additional_data(), |data| {
|
||||
data.unwrap_or_else(|err| push_error!(err))
|
||||
});
|
||||
|
||||
let mut final_task = reading_additional_task;
|
||||
let state_guard = state.app_state.lock();
|
||||
|
||||
+3
-1
@@ -109,7 +109,9 @@ impl NotificationManager {
|
||||
iced::widget::button("✕")
|
||||
.on_press(NotificationMessage::Remove(*id))
|
||||
.style(iced::widget::button::text)
|
||||
].align_y(Center).width(300)
|
||||
]
|
||||
.align_y(Center)
|
||||
.width(300)
|
||||
.padding(HALF_SPACING),
|
||||
);
|
||||
container
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
use crate::data::entities::WordData;
|
||||
use crate::navigation::Page::PreviousPage;
|
||||
use crate::navigation::RootMessage;
|
||||
use crate::navigation::*;
|
||||
use crate::pages::dictionary::split_with_coma;
|
||||
use crate::pages::dictionary_quiz::DictionaryQuizMessage::*;
|
||||
use crate::navigation::Page::PreviousPage;
|
||||
use crate::navigation::*;
|
||||
use crate::pages::quiz::Score;
|
||||
use crate::styling::*;
|
||||
use iced::Background::Color;
|
||||
@@ -11,7 +12,6 @@ use iced::widget::container::Style;
|
||||
use iced::widget::{Row, button, container, row, space, text, text_input};
|
||||
use iced::{Border, Element, Fill, Task, Theme, alignment};
|
||||
use rand::prelude::SliceRandom;
|
||||
use crate::data::entities::WordData;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DictionaryQuizState {
|
||||
@@ -147,7 +147,8 @@ impl DictionaryQuizState {
|
||||
self.score.total += 1;
|
||||
}
|
||||
if self.answer.to_lowercase() == self.correct.to_lowercase()
|
||||
|| split_with_coma(self.correct.to_lowercase().as_str()).contains(&self.answer.to_lowercase())
|
||||
|| split_with_coma(self.correct.to_lowercase().as_str())
|
||||
.contains(&self.answer.to_lowercase())
|
||||
{
|
||||
if !self.is_help {
|
||||
self.score.correct += 1;
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
use crate::data_provider::history::{get_history_of_set};
|
||||
use crate::app::AppState;
|
||||
use crate::data::INVALID_ID;
|
||||
use crate::data::entities::{HistoryItem, WordData};
|
||||
use crate::data_provider::history::get_history_of_set;
|
||||
use crate::navigation::*;
|
||||
use crate::styling::*;
|
||||
use HistoryMessage::Back;
|
||||
use chrono::Local;
|
||||
use iced::alignment::Horizontal::Center;
|
||||
use iced::widget::space::horizontal;
|
||||
@@ -8,10 +12,6 @@ use iced::widget::*;
|
||||
use iced::{Element, Fill, FillPortion, Task};
|
||||
use parking_lot::Mutex;
|
||||
use std::sync::Arc;
|
||||
use HistoryMessage::Back;
|
||||
use crate::app::AppState;
|
||||
use crate::data::entities::{HistoryItem, WordData};
|
||||
use crate::data::INVALID_ID;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct HistoryState {
|
||||
|
||||
+10
-9
@@ -1,10 +1,13 @@
|
||||
use crate::app::AppState;
|
||||
use crate::data::entities::{WordData, WordGroup};
|
||||
use crate::data_provider::import::{ImportData, ImportGroup, get_words_of_group, load_groups};
|
||||
use crate::data_provider::words::{add_group, add_words};
|
||||
use crate::pages::import::ImportMessage::*;
|
||||
use crate::data::entities::{WordData, WordGroup};
|
||||
use crate::fs::*;
|
||||
use crate::navigation::{NavigatedPage, Page, RootMessage};
|
||||
use crate::notification::NotificationData::OpenFileError;
|
||||
use crate::notification::{MaybeError, NotificationData};
|
||||
use crate::pages::import::ImportMessage::*;
|
||||
use crate::push_error;
|
||||
use crate::styling::*;
|
||||
use iced::widget::button::danger;
|
||||
use iced::widget::container::success;
|
||||
@@ -16,6 +19,7 @@ use iced::{Element, Task};
|
||||
use iced_core::Alignment::Center;
|
||||
use iced_core::Length::Fill;
|
||||
use iced_core::Padding;
|
||||
use log::info;
|
||||
use parking_lot::Mutex;
|
||||
use rfd::AsyncFileDialog;
|
||||
use rusqlite::Connection;
|
||||
@@ -23,12 +27,8 @@ use std::fs::{File, OpenOptions};
|
||||
use std::io::BufReader;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use log::info;
|
||||
use tokio::task::spawn_blocking;
|
||||
use zip::ZipArchive;
|
||||
use crate::app::AppState;
|
||||
use crate::fs::*;
|
||||
use crate::push_error;
|
||||
|
||||
const DEFAULT_FIELDS: [&str; 6] = ["key", "value", "tags", "reading", "context", "description"];
|
||||
|
||||
@@ -433,7 +433,8 @@ impl ImportState {
|
||||
async move {
|
||||
spawn_blocking(move || {
|
||||
let temp_file_path = temp_import_path();
|
||||
let connection = Connection::open(&temp_file_path).map_err(|_| OpenFileError)?;
|
||||
let connection =
|
||||
Connection::open(&temp_file_path).map_err(|_| OpenFileError)?;
|
||||
let import_list = get_words_of_group(&connection, group.id)?;
|
||||
let mut words_list = Vec::with_capacity(import_list.len());
|
||||
|
||||
@@ -500,8 +501,8 @@ impl ImportState {
|
||||
},
|
||||
|r: Result<(), NotificationData>| match r {
|
||||
Ok(_) => RootMessage::Import(ImportFinished),
|
||||
Err(err) => push_error!(err)
|
||||
}
|
||||
Err(err) => push_error!(err),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+2
-3
@@ -1,4 +1,5 @@
|
||||
|
||||
use crate::app::USER_FONT;
|
||||
use crate::core::kana_set::KanaSet;
|
||||
use crate::navigation::Page::PreviousPage;
|
||||
use crate::navigation::{NavigatedPage, Page, RootMessage};
|
||||
use crate::pages::quiz::QuizMessage::*;
|
||||
@@ -6,8 +7,6 @@ use crate::styling::*;
|
||||
use iced::widget::*;
|
||||
use iced::{Element, Fill, Task, alignment};
|
||||
use rand::seq::SliceRandom;
|
||||
use crate::app::USER_FONT;
|
||||
use crate::core::kana_set::KanaSet;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct QuizState {
|
||||
|
||||
@@ -334,10 +334,7 @@ pub enum RepetitionMessage {
|
||||
PlayFinished,
|
||||
}
|
||||
|
||||
async fn play_sound(
|
||||
sink: Arc<Option<MixerDeviceSink>>,
|
||||
text: String,
|
||||
) -> MaybeError {
|
||||
async fn play_sound(sink: Arc<Option<MixerDeviceSink>>, text: String) -> MaybeError {
|
||||
let data = get_voice(text.as_str()).await?;
|
||||
spawn_blocking(move || {
|
||||
if let Some(sink) = sink.as_ref()
|
||||
|
||||
@@ -13,7 +13,7 @@ use iced::widget::text_input::Catalog;
|
||||
use iced::widget::{button, column, row, scrollable, space, text, text_input};
|
||||
use iced::{Element, Task};
|
||||
use iced_core::Length::Fill;
|
||||
use iced_core::{color, Padding, Theme};
|
||||
use iced_core::{Padding, Theme, color};
|
||||
use parking_lot::Mutex;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
@@ -63,12 +63,12 @@ impl NavigatedPage<RepetitionSettingsMessage> for RepetitionSettingsState {
|
||||
Save => {
|
||||
let mut state = self.state.lock();
|
||||
if let Err(e) = update_deck(&mut self.set, &state.connection) {
|
||||
return push_error_task!(e)
|
||||
return push_error_task!(e);
|
||||
}
|
||||
if self.filter_changed
|
||||
&& let Err(e) = update_deck_stats(&self.set, &state)
|
||||
{
|
||||
return push_error_task!(e)
|
||||
return push_error_task!(e);
|
||||
}
|
||||
state.decks[self.index] = self.set.clone();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::app::AppState;
|
||||
use crate::core::srs::{AppendMode, OrderMode};
|
||||
use crate::data::entities::{CardStatistics, DeckSettings};
|
||||
use crate::data::Id;
|
||||
use crate::data::entities::{CardStatistics, DeckSettings};
|
||||
use crate::data_provider::card_sets::update_deck;
|
||||
use crate::data_provider::card_stats::{add_stat_list, load_stats_of_deck};
|
||||
use crate::navigation::Page::{History, PreviousPage, Repetition, RepetitionSettings};
|
||||
@@ -16,17 +16,17 @@ use crate::push_error_task;
|
||||
use crate::styling::*;
|
||||
use chrono::{Days, Local, Utc};
|
||||
use hashbrown::{HashMap, HashSet};
|
||||
use iced::widget::button::{danger, Status};
|
||||
pub use iced::widget::button::{Catalog, Style};
|
||||
use iced::widget::button::{Status, danger};
|
||||
use iced::widget::tooltip::Position::Top;
|
||||
use iced::widget::{
|
||||
button, column, container, lazy, radio, row, scrollable, space, svg, text, text_input, tooltip,
|
||||
Column, Row,
|
||||
Column, Row, button, column, container, lazy, radio, row, scrollable, space, svg, text,
|
||||
text_input, tooltip,
|
||||
};
|
||||
use iced::{Background, Border, Center, Color, Element, Fill, Length, Shadow, Task, Theme};
|
||||
use iced_core::Padding;
|
||||
use iced_core::border::Radius;
|
||||
use iced_core::svg::Handle;
|
||||
use iced_core::Padding;
|
||||
use parking_lot::Mutex;
|
||||
use std::ops::Deref;
|
||||
use std::sync::Arc;
|
||||
@@ -53,7 +53,7 @@ impl NavigatedPage<RepetitionsMessage> for RepetitionsState {
|
||||
|
||||
let selected_set = self.selected_deck_mut().unwrap();
|
||||
if selected_set.append_mode == AppendMode::Full {
|
||||
if let Err(_err) = Self::append_all_words(&mut clone.lock(), selected_set){
|
||||
if let Err(_err) = Self::append_all_words(&mut clone.lock(), selected_set) {
|
||||
return None;
|
||||
}
|
||||
selected_set.existing_words_indices = selected_set.available_words_indices.clone();
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
use crate::pages::dictionary::DictionaryState;
|
||||
use crate::app::AppState;
|
||||
use crate::core::kana_set::{KanaSet, KanaType};
|
||||
use crate::navigation::Page::*;
|
||||
use crate::navigation::{NavigatedPage, Page, RootMessage};
|
||||
use crate::pages::dictionary::DictionaryState;
|
||||
use crate::pages::quiz::QuizState;
|
||||
use crate::pages::randomizer::RandomizerState;
|
||||
use crate::pages::repetitions::RepetitionsState;
|
||||
use crate::pages::selector::SelectorMessage::ChangeMode;
|
||||
use crate::styling::*;
|
||||
use crate::pages::sync::SyncState;
|
||||
use crate::pages::writing::WritingState;
|
||||
use crate::styling::*;
|
||||
use iced::widget::button::{Status, Style};
|
||||
use iced::widget::*;
|
||||
use iced::{Element, Task, alignment};
|
||||
@@ -15,9 +18,6 @@ use iced_core::Background;
|
||||
use iced_core::Color;
|
||||
use parking_lot::Mutex;
|
||||
use std::sync::Arc;
|
||||
use crate::app::AppState;
|
||||
use crate::core::kana_set::{KanaSet, KanaType};
|
||||
use crate::pages::quiz::QuizState;
|
||||
|
||||
pub struct SelectorState {
|
||||
pub set: KanaSet,
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
|
||||
use crate::core::kana_set::KanaSet;
|
||||
use crate::navigation::Page::PreviousPage;
|
||||
use crate::navigation::{NavigatedPage, Page, RootMessage};
|
||||
use crate::styling::*;
|
||||
use iced::widget::*;
|
||||
use iced::{Element, Fill, Task, alignment};
|
||||
use rand::seq::SliceRandom;
|
||||
use crate::core::kana_set::KanaSet;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct WritingState {
|
||||
|
||||
Reference in new issue
Block a user