diff --git a/Cargo.lock b/Cargo.lock index 4bd99e4..82ef046 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2203,7 +2203,7 @@ checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" [[package]] name = "jap_learn" -version = "0.1.3" +version = "0.2.0" dependencies = [ "chrono", "criterion", @@ -2501,9 +2501,6 @@ name = "litemap" version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "47d9d19d1d6efa0109d2f65ff4c85cddd50bd572e5a00127ab10987290bcefae" -dependencies = [ - "serde_core", -] [[package]] name = "litrs" @@ -3596,9 +3593,9 @@ checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" [[package]] name = "rand" -version = "0.10.2" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7f5fa3a058cd35567ef9bfa5e75732bee0f9e4c55fa90477bef2dfcdbc4be80" +checksum = "65c9fb96cbc91e3478eaae79a69fcd3f1ae4ad052e471fe6732fff548984b4af" dependencies = [ "chacha20", "getrandom 0.4.1", @@ -3857,9 +3854,9 @@ dependencies = [ [[package]] name = "rhai" -version = "1.26.0" +version = "1.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e6e1be9d697d537ce450766df42ad6adf1a93f25f21d73217354ad7e3d3dae1" +checksum = "0334639972c0ea5a3fd366aa36116754a11431b619fec3ed559b3f73bcbcebf5" dependencies = [ "ahash", "bitflags 2.10.0", diff --git a/Cargo.toml b/Cargo.toml index 9bb6112..3760d40 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,15 +1,15 @@ [package] name = "jap_learn" -version = "0.1.3" +version = "0.2.0" edition = "2024" [dependencies] iced = { version = "0.14.0", features = ["tokio", "svg", "lazy", "crisp", "tiny-skia", "wayland", "wgpu"], default-features = false} iced_core = "0.14.0" -rand = "0.10.2" +rand = "0.10.3" dirs = "7.0.0" serde_json = "1.0.151" -rhai = { version = "1.26.0", features = ["sync"] } +rhai = { version = "1.26.1", features = ["sync"] } chrono = "0.4.45" rusqlite = { version = "0.40.2", features = ["chrono", "bundled"] } reqwest = { version = "0.13.5", features = ["json", "stream", "multipart"] } @@ -27,7 +27,7 @@ parking_lot = "0.12.5" env_logger = "0.11.11" log = "0.4.34" fsrs = "6.6.2" -litemap = { version = "0.8.3", features = ["serde"] } +litemap = { version = "0.8.3" } [profile.super-release] inherits = "release" diff --git a/src/data_provider/words.rs b/src/data_provider/words.rs index bbfedc3..6a842c8 100644 --- a/src/data_provider/words.rs +++ b/src/data_provider/words.rs @@ -69,26 +69,6 @@ fn additional_to_string(map: &LiteMap) -> String { parts.join("") } -fn additional_from_string_temp(data: String) -> LiteMap { - let pre_map: LiteMap = serde_json::from_str(data.as_str()).unwrap(); - LiteMap::from( - pre_map - .iter() - .map(|(k, v)| { - ( - match k.as_str() { - "reading" => Id(1), - "description" => Id(2), - "context" => Id(3), - &_ => Id(0), - }, - v.to_string(), - ) - }) - .collect(), - ) -} - fn additional_from_string(data: String) -> LiteMap { if data.is_empty() { return LiteMap::new(); diff --git a/src/notification.rs b/src/notification.rs index bc6c025..ccbaa0d 100644 --- a/src/notification.rs +++ b/src/notification.rs @@ -138,8 +138,8 @@ impl NotificationManager { fn draw_data<'a>(data: &NotificationData) -> Element<'a, NotificationMessage> { match data { - NotificationData::DataLoaded => { - text!("Данные успешно загружены на сервер") + NotificationData::DataSynced => { + text!("Данные успешно синхронизированы") } NotificationData::ImportError => { text!("Ошибка при импорте данных из Anki") @@ -168,6 +168,9 @@ impl NotificationManager { NotificationData::CompressError => { text!("Ошибка сжатия или распаковки данных") } + NotificationData::LocalVersionChanged => { + text!("Локальная версия будет заменена") + } } .width(Fill) .into() @@ -184,7 +187,7 @@ pub enum NotificationRequest { #[derive(Clone, Debug)] pub enum NotificationData { PermissionDenied, - DataLoaded, + DataSynced, ImportError, IncorrectAnkiFile, OpenFileError, @@ -193,6 +196,7 @@ pub enum NotificationData { DbSaveError, DbLoadError, CompressError, + LocalVersionChanged, } pub type MaybeError = Result<(), NotificationData>; diff --git a/src/pages/sync.rs b/src/pages/sync.rs index cead796..27cfa5d 100644 --- a/src/pages/sync.rs +++ b/src/pages/sync.rs @@ -15,6 +15,7 @@ use iced::widget::{button, column, container, progress_bar, row, space, text, to use iced::{Center, Element, Fill, Font, Length, Task}; use log::error; use std::time::Duration; +use crate::notification::NotificationData::LocalVersionChanged; #[derive(Clone)] pub enum SyncMessage { @@ -31,11 +32,13 @@ pub enum SyncMessage { Disable, DisableSync, SwitchAutoSync, + ResetRealLoad, } pub struct SyncState { state: AppState, auto_fetch: bool, frozen: bool, + real_load: bool, progress: f32, } @@ -99,6 +102,18 @@ impl NavigatedPage for SyncState { return tasks; } GetLast => { + if self.real_load == false { + self.real_load = true; + return Task::batch([ + Task::future(async { + tokio::time::sleep(Duration::from_millis(3000)).await; + return RootMessage::Sync(ResetRealLoad); + }), + Task::done(RootMessage::PushNotification(NotificationRequest::Warning(LocalVersionChanged))) + ]); + } + + self.real_load = false; let id = self.state.sync_data.read().key.clone().unwrap(); let tasks = Task::batch([ Task::perform( @@ -134,7 +149,7 @@ impl NavigatedPage for SyncState { } return Task::done(RootMessage::PushNotification(NotificationRequest::Info( - NotificationData::DataLoaded, + NotificationData::DataSynced, ))); } Disable => {} @@ -166,6 +181,9 @@ impl NavigatedPage for SyncState { return push_error_task!(err); } } + ResetRealLoad => { + self.real_load = false; + } } Task::none() } @@ -189,6 +207,7 @@ impl SyncState { auto_fetch, state, frozen: false, + real_load: false, progress: 0.0, } }