Migrate to parking_lot

This commit is contained in:
2026-08-20 00:07:09 +03:00
parent bf805b79e5
commit 66f8a83dec
13 changed files with 85 additions and 73 deletions
Generated
+1 -1
View File
@@ -2319,6 +2319,7 @@ dependencies = [
"iced", "iced",
"iced_core", "iced_core",
"mimalloc", "mimalloc",
"parking_lot",
"rand", "rand",
"rayon", "rayon",
"reqwest", "reqwest",
@@ -2326,7 +2327,6 @@ dependencies = [
"rhai", "rhai",
"rodio", "rodio",
"rusqlite", "rusqlite",
"serde",
"serde_json", "serde_json",
"sha2", "sha2",
"tokio", "tokio",
+1 -1
View File
@@ -8,7 +8,6 @@ iced = { version = "0.14.0", features = ["tokio", "svg", "lazy"]}
iced_core = "0.14.0" iced_core = "0.14.0"
rand = "0.10.2" rand = "0.10.2"
dirs = "6.0.0" dirs = "6.0.0"
serde = { version = "1.0.229", features = ["derive"] }
serde_json = "1.0.151" serde_json = "1.0.151"
rhai = { version = "1.25.1", features = ["sync"] } rhai = { version = "1.25.1", features = ["sync"] }
chrono = "0.4.45" chrono = "0.4.45"
@@ -24,6 +23,7 @@ rfd = "0.17.2"
mimalloc = "0.1.52" mimalloc = "0.1.52"
hashbrown = "0.17.1" hashbrown = "0.17.1"
rayon = "1.12.0" rayon = "1.12.0"
parking_lot = "0.12.5"
[profile.super-release] [profile.super-release]
inherits = "release" inherits = "release"
+24 -23
View File
@@ -22,7 +22,8 @@ use rand::random_range;
use std::fs; use std::fs;
use std::ops::Add; use std::ops::Add;
use std::path::PathBuf; use std::path::PathBuf;
use std::sync::{Arc, Mutex}; use std::sync::Arc;
use parking_lot::Mutex;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
#[derive(Clone)] #[derive(Clone)]
@@ -73,7 +74,7 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
&& self.include_map.iter().any(|x| *x) && self.include_map.iter().any(|x| *x)
{ {
let mut words = vec![]; let mut words = vec![];
let dict = &self.state.lock().unwrap().dictionary; let dict = &self.state.lock().dictionary;
words = self words = self
.include_map .include_map
@@ -92,7 +93,7 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
if let WordAction(index) = message { if let WordAction(index) = message {
let word: WordData; let word: WordData;
{ {
let state = self.state.lock().unwrap(); let state = self.state.lock();
let dict = &state.dictionary; let dict = &state.dictionary;
word = dict[*index].clone(); word = dict[*index].clone();
} }
@@ -107,7 +108,7 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
} }
fn navigated(&mut self) { fn navigated(&mut self) {
let len = self.state.lock().unwrap().dictionary.len(); let len = self.state.lock().dictionary.len();
self.include_map = vec![false; len]; self.include_map = vec![false; len];
self.tag_map = Default::default(); self.tag_map = Default::default();
@@ -117,7 +118,7 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
fn update(&mut self, message: DictionaryMessage) -> Task<RootMessage> { fn update(&mut self, message: DictionaryMessage) -> Task<RootMessage> {
match message { match message {
NewWord => { NewWord => {
let mut state = self.state.lock().unwrap(); let mut state = self.state.lock();
let mut word = WordData::new(); let mut word = WordData::new();
word.group_id = state.word_groups[self.selected_group_index].id; word.group_id = state.word_groups[self.selected_group_index].id;
@@ -128,21 +129,21 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
SetKey(i, v) => { SetKey(i, v) => {
{ {
let dict = &mut self.state.lock().unwrap().dictionary; let dict = &mut self.state.lock().dictionary;
dict[i].key = v; dict[i].key = v;
} }
return self.launch_auto_save_offset(i); return self.launch_auto_save_offset(i);
} }
SetValue(i, v) => { SetValue(i, v) => {
{ {
let dict = &mut self.state.lock().unwrap().dictionary; let dict = &mut self.state.lock().dictionary;
dict[i].value = v dict[i].value = v
} }
return self.launch_auto_save_offset(i); return self.launch_auto_save_offset(i);
} }
SetTags(i, mut v) => { SetTags(i, mut v) => {
{ {
let dict = &mut self.state.lock().unwrap().dictionary; let dict = &mut self.state.lock().dictionary;
let current_tags_value = dict[i].tags.clone(); let current_tags_value = dict[i].tags.clone();
@@ -162,7 +163,7 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
} }
WordAction(i) => { WordAction(i) => {
let state = &mut self.state.lock().unwrap(); let state = &mut self.state.lock();
let dict = &mut state.dictionary; let dict = &mut state.dictionary;
let word = dict.remove(i); let word = dict.remove(i);
self.include_map.remove(i); self.include_map.remove(i);
@@ -173,7 +174,7 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
IncludeTag(t, v) => { IncludeTag(t, v) => {
let index; let index;
{ {
let state = self.state.lock().unwrap(); let state = self.state.lock();
index = state.word_groups[self.selected_group_index].id; index = state.word_groups[self.selected_group_index].id;
} }
self.tag_map.insert(t, v); self.tag_map.insert(t, v);
@@ -193,7 +194,7 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
Back => {} Back => {}
Test => {} Test => {}
CreateGroup => { CreateGroup => {
let state = &mut self.state.lock().unwrap(); let state = &mut self.state.lock();
state.word_groups.push(WordGroup { state.word_groups.push(WordGroup {
id: 0.into(), id: 0.into(),
@@ -201,14 +202,14 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
}); });
} }
EditGroup(new) => { EditGroup(new) => {
let state = &mut self.state.lock().unwrap(); let state = &mut self.state.lock();
let group = state.word_groups.get_mut(self.selected_group_index); let group = state.word_groups.get_mut(self.selected_group_index);
if let Some(group) = group { if let Some(group) = group {
group.name = new.clone(); group.name = new.clone();
} }
} }
SaveGroup => { SaveGroup => {
let state = &mut self.state.lock().unwrap(); let state = &mut self.state.lock();
let connection = &state.connection; let connection = &state.connection;
let mut group = state.word_groups[self.selected_group_index].clone(); let mut group = state.word_groups[self.selected_group_index].clone();
@@ -219,7 +220,7 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
self.selected_group_index = i; self.selected_group_index = i;
let index; let index;
{ {
let state = self.state.lock().unwrap(); let state = self.state.lock();
index = state.word_groups[i].id; index = state.word_groups[i].id;
} }
self.update_words_include(index) self.update_words_include(index)
@@ -229,7 +230,7 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
return Task::none(); return Task::none();
} }
{ {
let state = &mut self.state.lock().unwrap(); let state = &mut self.state.lock();
if let Some(group) = state.word_groups.get(self.selected_group_index) { if let Some(group) = state.word_groups.get(self.selected_group_index) {
let remove_group_id = group.id; let remove_group_id = group.id;
@@ -289,7 +290,7 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
impl DictionaryState { impl DictionaryState {
pub fn new(state: Arc<Mutex<AppState>>) -> Self { pub fn new(state: Arc<Mutex<AppState>>) -> Self {
let len = state.lock().unwrap().dictionary.len(); let len = state.lock().dictionary.len();
let mut result = DictionaryState { let mut result = DictionaryState {
include_map: vec![false; len], include_map: vec![false; len],
@@ -309,7 +310,7 @@ impl DictionaryState {
} }
fn save_word(&mut self, i: usize) { fn save_word(&mut self, i: usize) {
let state = &mut self.state.lock().unwrap(); let state = &mut self.state.lock();
let connection = &state.connection; let connection = &state.connection;
let word = &mut state.dictionary[i].clone(); let word = &mut state.dictionary[i].clone();
@@ -331,7 +332,7 @@ impl DictionaryState {
let time = Instant::now(); let time = Instant::now();
let mut col = Column::new().width(Fill); let mut col = Column::new().width(Fill);
let state = self.state.lock().unwrap(); let state = self.state.lock();
let group_id = state.word_groups[self.selected_group_index].id; let group_id = state.word_groups[self.selected_group_index].id;
let dict = &state.dictionary; let dict = &state.dictionary;
@@ -443,7 +444,7 @@ impl DictionaryState {
} }
fn filters(&self) -> iced::Element<'_, DictionaryMessage> { fn filters(&self) -> iced::Element<'_, DictionaryMessage> {
let dict = &self.state.lock().unwrap().dictionary; let dict = &self.state.lock().dictionary;
iced::widget::column![ iced::widget::column![
text_input("Поиск", &self.search) text_input("Поиск", &self.search)
@@ -499,7 +500,7 @@ impl DictionaryState {
fn update_tags(&mut self) { fn update_tags(&mut self) {
let mut tags_list: HashSet<String> = HashSet::new(); let mut tags_list: HashSet<String> = HashSet::new();
let dict = &self.state.lock().unwrap().dictionary; let dict = &self.state.lock().dictionary;
dict.iter().for_each(|element| { dict.iter().for_each(|element| {
split_with_coma(element.tags.as_str()) split_with_coma(element.tags.as_str())
@@ -540,7 +541,7 @@ impl DictionaryState {
return; return;
} }
let dict = &self.state.lock().unwrap().dictionary; let dict = &self.state.lock().dictionary;
let time = Instant::now(); let time = Instant::now();
self.include_map = dict self.include_map = dict
@@ -560,7 +561,7 @@ impl DictionaryState {
let mut row = Row::new(); let mut row = Row::new();
row = row.push(button("+").style(text).on_press(CreateGroup)); row = row.push(button("+").style(text).on_press(CreateGroup));
let state = &self.state.lock().unwrap(); let state = &self.state.lock();
let groups = &state.word_groups; let groups = &state.word_groups;
for (index, group) in groups.iter().enumerate() { for (index, group) in groups.iter().enumerate() {
@@ -598,7 +599,7 @@ impl DictionaryState {
} }
fn add_word_button(&self) -> iced::Element<'_, DictionaryMessage> { fn add_word_button(&self) -> iced::Element<'_, DictionaryMessage> {
let state = self.state.lock().unwrap(); let state = self.state.lock();
let group_id = state.word_groups[self.selected_group_index].id; let group_id = state.word_groups[self.selected_group_index].id;
let button = button("Добавить слово").style(jl_button); let button = button("Добавить слово").style(jl_button);
+3 -2
View File
@@ -9,7 +9,8 @@ use iced::alignment::Horizontal::Center;
use iced::widget::space::horizontal; use iced::widget::space::horizontal;
use iced::widget::*; use iced::widget::*;
use iced::{Element, Fill, FillPortion, Task}; use iced::{Element, Fill, FillPortion, Task};
use std::sync::{Arc, Mutex}; use std::sync::Arc;
use parking_lot::Mutex;
#[derive(Clone)] #[derive(Clone)]
pub struct HistoryState { pub struct HistoryState {
@@ -47,7 +48,7 @@ impl NavigatedPage<HistoryMessage> for HistoryState {
impl HistoryState { impl HistoryState {
pub fn new(id: crate::lang::Id, state: Arc<Mutex<AppState>>) -> Self { pub fn new(id: crate::lang::Id, state: Arc<Mutex<AppState>>) -> Self {
let state = state.lock().unwrap(); let state = state.lock();
let history = get_history_of_set(id); let history = get_history_of_set(id);
let words = history let words = history
.iter() .iter()
+6 -5
View File
@@ -21,7 +21,8 @@ use rusqlite::Connection;
use std::fs::{File, OpenOptions}; use std::fs::{File, OpenOptions};
use std::io::BufReader; use std::io::BufReader;
use std::path::PathBuf; use std::path::PathBuf;
use std::sync::{Arc, Mutex}; use std::sync::Arc;
use parking_lot::Mutex;
use tokio::task::spawn_blocking; use tokio::task::spawn_blocking;
use zip::ZipArchive; use zip::ZipArchive;
@@ -141,7 +142,7 @@ impl NavigatedPage<ImportMessage> for ImportState {
back_overlay( back_overlay(
{ {
if let Some(value) = &self.progress { if let Some(value) = &self.progress {
column![progress_bar(0f32..=1f32, *value.lock().unwrap()),] column![progress_bar(0f32..=1f32, *value.lock()),]
.spacing(QUARTER_SPACING) .spacing(QUARTER_SPACING)
.into() .into()
} else { } else {
@@ -444,7 +445,7 @@ impl ImportState {
name: group.name.clone(), name: group.name.clone(),
}; };
{ {
let state = state.lock().unwrap(); let state = state.lock();
add_group(&mut group_entity, &state.connection); add_group(&mut group_entity, &state.connection);
} }
@@ -480,14 +481,14 @@ impl ImportState {
words_list.push(word); words_list.push(word);
} }
let mut state = state.lock().unwrap(); let mut state = state.lock();
let connection = &mut state.connection; let connection = &mut state.connection;
let mut index = 0; let mut index = 0;
let total_len = words_list.len() as f32 / 1024.0; let total_len = words_list.len() as f32 / 1024.0;
for word in &mut words_list.chunks_mut(1024) { for word in &mut words_list.chunks_mut(1024) {
add_words(word, connection); add_words(word, connection);
index += 1; index += 1;
let mut progress = progress.lock().unwrap(); let mut progress = progress.lock();
*progress = index as f32 / total_len; *progress = index as f32 / total_len;
} }
+4 -3
View File
@@ -18,7 +18,8 @@ use std::collections::HashMap;
use std::fmt::{Display, Formatter}; use std::fmt::{Display, Formatter};
use std::num::ParseIntError; use std::num::ParseIntError;
use std::str::FromStr; use std::str::FromStr;
use std::sync::{Arc, Mutex}; use std::sync::Arc;
use parking_lot::Mutex;
use std::time::Instant; use std::time::Instant;
const MAX_HISTORY_LEN: usize = 20; const MAX_HISTORY_LEN: usize = 20;
@@ -354,7 +355,7 @@ pub struct DeckData {
impl DeckData { impl DeckData {
pub fn new(settings: &DeckSettings, state: Arc<Mutex<AppState>>) -> Self { pub fn new(settings: &DeckSettings, state: Arc<Mutex<AppState>>) -> Self {
let state_for = state.clone(); let state_for = state.clone();
let state_locked = state.lock().unwrap(); let state_locked = state.lock();
let mut current_set = load_stats_of_deck(settings, &state_locked.connection); let mut current_set = load_stats_of_deck(settings, &state_locked.connection);
let last_list: Vec<_> = settings let last_list: Vec<_> = settings
@@ -446,7 +447,7 @@ impl DeckData {
self.order_module = OrderModule::WorstWordsSRS(module); self.order_module = OrderModule::WorstWordsSRS(module);
} }
} }
update_stat_score(word, &self.state.lock().unwrap().connection); update_stat_score(word, &self.state.lock().connection);
push_note( push_note(
self.settings.id, self.settings.id,
HistoryItem { HistoryItem {
+5 -4
View File
@@ -30,7 +30,8 @@ use iced::keyboard::Event;
use iced::{Element, Task}; use iced::{Element, Task};
use reqwest::Error; use reqwest::Error;
use rusqlite::Connection; use rusqlite::Connection;
use std::sync::{Arc, Mutex}; use std::sync::Arc;
use parking_lot::Mutex;
use std::time::Instant; use std::time::Instant;
impl Default for ScreenState { impl Default for ScreenState {
@@ -97,7 +98,7 @@ impl ScreenState {
let reading_additional_task = Task::perform(Self::load_additional_data(), |data| data); let reading_additional_task = Task::perform(Self::load_additional_data(), |data| data);
let final_task; let final_task;
let state_guard = state.app_state.lock().unwrap(); let state_guard = state.app_state.lock();
if state_guard.sync_data.auto_web_fetch { if state_guard.sync_data.auto_web_fetch {
let key = state_guard.sync_data.key.clone().unwrap(); let key = state_guard.sync_data.key.clone().unwrap();
final_task = Task::batch([ final_task = Task::batch([
@@ -169,13 +170,13 @@ impl ScreenState {
} }
if let DataLoaded(data) = message { if let DataLoaded(data) = message {
self.app_state.lock().unwrap().activity = data; self.app_state.lock().activity = data;
return Task::none(); return Task::none();
} }
if let UpdateData = message { if let UpdateData = message {
println!("Loading data"); println!("Loading data");
let mut state = self.app_state.lock().unwrap(); let mut state = self.app_state.lock();
if cfg!(windows) { if cfg!(windows) {
state.connection = Connection::open_in_memory().unwrap(); state.connection = Connection::open_in_memory().unwrap();
} }
+3 -2
View File
@@ -13,7 +13,8 @@ use iced::widget::{Column, button, column, container, row, rule, space, text, to
use iced::{Element, Fill, Task, Theme, alignment, keyboard}; use iced::{Element, Fill, Task, Theme, alignment, keyboard};
use rodio::MixerDeviceSink; use rodio::MixerDeviceSink;
use std::collections::HashSet; use std::collections::HashSet;
use std::sync::{Arc, Mutex}; use std::sync::Arc;
use parking_lot::Mutex;
use tokio::task::spawn_blocking; use tokio::task::spawn_blocking;
pub struct RepetitionState { pub struct RepetitionState {
@@ -148,7 +149,7 @@ impl RepetitionState {
} }
fn increment_counter(&mut self) { fn increment_counter(&mut self) {
let mut state = self.state.lock().unwrap(); let mut state = self.state.lock();
let id = self.settings.id; let id = self.settings.id;
let activity = state.activity.get_mut(&id); let activity = state.activity.get_mut(&id);
+9 -7
View File
@@ -11,9 +11,11 @@ use iced::widget::{button, column, row, scrollable, space, text, text_input};
use iced::{Element, Task}; use iced::{Element, Task};
use iced_core::Length::Fill; use iced_core::Length::Fill;
use iced_core::{Padding, Theme, color}; use iced_core::{Padding, Theme, color};
use std::sync::{Arc, Mutex}; use std::sync::Arc;
use parking_lot::Mutex;
use std::time::Duration; use std::time::Duration;
pub struct RepetitionSettingsState { pub struct RepetitionSettingsState {
set: DeckSettings, set: DeckSettings,
index: usize, index: usize,
@@ -23,10 +25,10 @@ pub struct RepetitionSettingsState {
} }
impl RepetitionSettingsState { impl RepetitionSettingsState {
pub(crate) fn new(index: usize, p1: Arc<Mutex<AppState>>) -> RepetitionSettingsState { pub(crate) fn new(index: usize, state: Arc<Mutex<AppState>>) -> RepetitionSettingsState {
let set; let set;
{ {
let local_state = p1.lock().unwrap(); let local_state = state.lock();
set = local_state.decks[index].clone(); set = local_state.decks[index].clone();
} }
let filter_state = set.check_filter(); let filter_state = set.check_filter();
@@ -34,7 +36,7 @@ impl RepetitionSettingsState {
RepetitionSettingsState { RepetitionSettingsState {
index, index,
set, set,
state: p1, state,
real_delete: false, real_delete: false,
correct_filter: filter_state, correct_filter: filter_state,
} }
@@ -55,7 +57,7 @@ impl NavigatedPage<RepetitionSettingsMessage> for RepetitionSettingsState {
match message { match message {
Back => {} Back => {}
Save => { Save => {
let mut state = self.state.lock().unwrap(); let mut state = self.state.lock();
update_deck(&mut self.set, &state.connection); update_deck(&mut self.set, &state.connection);
state.decks[self.index] = self.set.clone(); state.decks[self.index] = self.set.clone();
} }
@@ -73,7 +75,7 @@ impl NavigatedPage<RepetitionSettingsMessage> for RepetitionSettingsState {
self.correct_filter = self.set.check_filter(); self.correct_filter = self.set.check_filter();
} }
TryFilter => { TryFilter => {
let state = self.state.lock().unwrap(); let state = self.state.lock();
let count = self.set.get_word_list(&state).len(); let count = self.set.get_word_list(&state).len();
self.set.count = Some(count); self.set.count = Some(count);
} }
@@ -85,7 +87,7 @@ impl NavigatedPage<RepetitionSettingsMessage> for RepetitionSettingsState {
RootMessage::RepetitionSettings(RevertDeleteSet) RootMessage::RepetitionSettings(RevertDeleteSet)
}); });
} }
let mut state = self.state.lock().unwrap(); let mut state = self.state.lock();
delete_set(&self.set, &state.connection); delete_set(&self.set, &state.connection);
state.decks.remove(self.index); state.decks.remove(self.index);
return Task::done(RootMessage::RepetitionSettings(Back)); return Task::done(RootMessage::RepetitionSettings(Back));
+11 -10
View File
@@ -23,7 +23,8 @@ use iced_core::Padding;
use iced_core::border::Radius; use iced_core::border::Radius;
use iced_core::svg::Handle; use iced_core::svg::Handle;
use std::ops::Deref; use std::ops::Deref;
use std::sync::{Arc, Mutex}; use std::sync::Arc;
use parking_lot::Mutex;
#[derive(Clone)] #[derive(Clone)]
pub struct RepetitionsState { pub struct RepetitionsState {
@@ -47,7 +48,7 @@ impl NavigatedPage<RepetitionsMessage> for RepetitionsState {
let selected_set = self.selected_deck_mut().unwrap(); let selected_set = self.selected_deck_mut().unwrap();
if selected_set.append_mode == AppendMode::Full { if selected_set.append_mode == AppendMode::Full {
Self::append_all_words(&mut clone.lock().unwrap(), selected_set); Self::append_all_words(&mut clone.lock(), selected_set);
selected_set.existing_words_indices = selected_set.available_words_indices.clone(); selected_set.existing_words_indices = selected_set.available_words_indices.clone();
} else { } else {
if selected_set if selected_set
@@ -80,7 +81,7 @@ impl NavigatedPage<RepetitionsMessage> for RepetitionsState {
} }
fn navigated(&mut self) { fn navigated(&mut self) {
let index = self.selected_deck_index.unwrap(); let index = self.selected_deck_index.unwrap();
let state = self.state.lock().unwrap(); let state = self.state.lock();
if let Some(global_deck) = state.decks.get(index) { if let Some(global_deck) = state.decks.get(index) {
if global_deck.id != self.selected_deck().unwrap().id { if global_deck.id != self.selected_deck().unwrap().id {
drop(state); drop(state);
@@ -116,7 +117,7 @@ impl NavigatedPage<RepetitionsMessage> for RepetitionsState {
self.clear_selection(); self.clear_selection();
let deck = self.decks.remove(index); let deck = self.decks.remove(index);
if deck.id.is_valid() { if deck.id.is_valid() {
let mut state = self.state.lock().unwrap(); let mut state = self.state.lock();
state.decks.remove(index); state.decks.remove(index);
self.decks = self self.decks = self
.decks .decks
@@ -137,7 +138,7 @@ impl NavigatedPage<RepetitionsMessage> for RepetitionsState {
self.select_deck(index); self.select_deck(index);
let deck = self.selected_deck().unwrap(); let deck = self.selected_deck().unwrap();
if deck.existing_words_indices.is_none() { if deck.existing_words_indices.is_none() {
let state = self.state.lock().unwrap(); let state = self.state.lock();
let added: Vec<_> = load_stats_of_deck(deck, &state.connection) let added: Vec<_> = load_stats_of_deck(deck, &state.connection)
.iter() .iter()
.map(|c| self.word_id_index_map[&c.word_id]) .map(|c| self.word_id_index_map[&c.word_id])
@@ -151,7 +152,7 @@ impl NavigatedPage<RepetitionsMessage> for RepetitionsState {
} }
Save => { Save => {
let mut deck = self.selected_deck().unwrap().clone(); let mut deck = self.selected_deck().unwrap().clone();
let mut state = self.state.lock().unwrap(); let mut state = self.state.lock();
{ {
update_deck(&mut deck.general_settings, &state.connection); update_deck(&mut deck.general_settings, &state.connection);
if let Some(index) = deck.index { if let Some(index) = deck.index {
@@ -176,7 +177,7 @@ impl NavigatedPage<RepetitionsMessage> for RepetitionsState {
deck.general_settings.filter = value; deck.general_settings.filter = value;
} }
TryFilter => { TryFilter => {
let state = self.state.lock().unwrap(); let state = self.state.lock();
let deck = self.selected_deck().unwrap(); let deck = self.selected_deck().unwrap();
let count = deck.get_word_list(&state).len(); let count = deck.get_word_list(&state).len();
drop(state); drop(state);
@@ -220,7 +221,7 @@ impl NavigatedPage<RepetitionsMessage> for RepetitionsState {
} }
let deck = self.selected_deck().unwrap(); let deck = self.selected_deck().unwrap();
let mut state = self.state.lock().unwrap(); let mut state = self.state.lock();
Self::append_words(&mut state, &deck.general_settings, adding.into_iter()); Self::append_words(&mut state, &deck.general_settings, adding.into_iter());
} }
} }
@@ -253,7 +254,7 @@ impl NavigatedPage<RepetitionsMessage> for RepetitionsState {
impl RepetitionsState { impl RepetitionsState {
pub(crate) fn new(state: Arc<Mutex<AppState>>) -> RepetitionsState { pub(crate) fn new(state: Arc<Mutex<AppState>>) -> RepetitionsState {
let state_ = state.lock().unwrap(); let state_ = state.lock();
let mut map = HashMap::with_capacity(state_.dictionary.len()); let mut map = HashMap::with_capacity(state_.dictionary.len());
state_ state_
@@ -408,7 +409,7 @@ impl RepetitionsState {
fn activity_bar(&self, deck: &DeckSettings) -> Element<'_, RepetitionsMessage> { fn activity_bar(&self, deck: &DeckSettings) -> Element<'_, RepetitionsMessage> {
const MAX_DAY_COUNT: f32 = 128.0; const MAX_DAY_COUNT: f32 = 128.0;
let state = self.state.lock().unwrap(); let state = self.state.lock();
let history = state.activity.get(&deck.id); let history = state.activity.get(&deck.id);
let mut counts: Vec<u32> = vec![0; 30 * 7]; let mut counts: Vec<u32> = vec![0; 30 * 7];
let now = Local::now().date_naive(); let now = Local::now().date_naive();
+2 -1
View File
@@ -15,7 +15,8 @@ use iced::{Element, Task, alignment};
use iced_core::Alignment::Center; use iced_core::Alignment::Center;
use iced_core::Background; use iced_core::Background;
use iced_core::Color; use iced_core::Color;
use std::sync::{Arc, Mutex}; use std::sync::Arc;
use parking_lot::Mutex;
pub struct SelectorState { pub struct SelectorState {
pub set: KanaSet, pub set: KanaSet,
+12 -11
View File
@@ -9,7 +9,8 @@ use iced::widget::button::danger;
use iced::widget::container::rounded_box; use iced::widget::container::rounded_box;
use iced::widget::{button, column, container, progress_bar, row, space, text, toggler}; use iced::widget::{button, column, container, progress_bar, row, space, text, toggler};
use iced::{Center, Element, Fill, Font, Length, Task}; use iced::{Center, Element, Fill, Font, Length, Task};
use std::sync::{Arc, Mutex}; use std::sync::Arc;
use parking_lot::Mutex;
use std::time::Duration; use std::time::Duration;
#[derive(Clone)] #[derive(Clone)]
@@ -52,7 +53,7 @@ impl NavigatedPage<SyncMessage> for SyncState {
match message { match message {
Back => {} Back => {}
CopyKey => { CopyKey => {
let state = self.state.lock().unwrap(); let state = self.state.lock();
let key = state.sync_data.key.clone().unwrap(); let key = state.sync_data.key.clone().unwrap();
return iced::clipboard::write(key) return iced::clipboard::write(key)
.map(|_val: String| RootMessage::Sync(KeyCopied)); .map(|_val: String| RootMessage::Sync(KeyCopied));
@@ -69,14 +70,14 @@ impl NavigatedPage<SyncMessage> for SyncState {
if !validate_id(&new_id) { if !validate_id(&new_id) {
return Task::none(); return Task::none();
} }
let mut state = self.state.lock().unwrap(); let mut state = self.state.lock();
state.sync_data.key = Some(new_id.clone()); state.sync_data.key = Some(new_id.clone());
set_setting("SYNC_KEY".to_string(), new_id, &state.connection); set_setting("SYNC_KEY".to_string(), new_id, &state.connection);
} }
Send => { Send => {
self.prepare_to_db_interaction(); self.prepare_to_db_interaction();
let id = self.state.lock().unwrap().sync_data.key.clone().unwrap(); let id = self.state.lock().sync_data.key.clone().unwrap();
let tasks = Task::batch([ let tasks = Task::batch([
Task::perform( Task::perform(
async { tokio::time::sleep(Duration::from_millis(200)).await }, async { tokio::time::sleep(Duration::from_millis(200)).await },
@@ -88,7 +89,7 @@ impl NavigatedPage<SyncMessage> for SyncState {
return tasks; return tasks;
} }
GetLast => { GetLast => {
let id = self.state.lock().unwrap().sync_data.key.clone().unwrap(); let id = self.state.lock().sync_data.key.clone().unwrap();
let tasks = Task::batch([ let tasks = Task::batch([
Task::perform( Task::perform(
async { tokio::time::sleep(Duration::from_millis(200)).await }, async { tokio::time::sleep(Duration::from_millis(200)).await },
@@ -116,7 +117,7 @@ impl NavigatedPage<SyncMessage> for SyncState {
let mut updated_state = AppState::new(); let mut updated_state = AppState::new();
fill_state(&mut updated_state); fill_state(&mut updated_state);
let mut state = self.state.lock().unwrap(); let mut state = self.state.lock();
state.sync_data = updated_state.sync_data; state.sync_data = updated_state.sync_data;
state.connection = updated_state.connection; state.connection = updated_state.connection;
state.decks = updated_state.decks; state.decks = updated_state.decks;
@@ -125,14 +126,14 @@ impl NavigatedPage<SyncMessage> for SyncState {
} }
Disable => {} Disable => {}
DisableSync => { DisableSync => {
let mut state = self.state.lock().unwrap(); let mut state = self.state.lock();
state.sync_data.key = None; state.sync_data.key = None;
delete_settings("SYNC_KEY".to_string(), &state.connection); delete_settings("SYNC_KEY".to_string(), &state.connection);
delete_settings("AUTO_WEB_FETCH".to_string(), &state.connection); delete_settings("AUTO_WEB_FETCH".to_string(), &state.connection);
} }
SwitchAutoSync => { SwitchAutoSync => {
self.auto_fetch = !self.auto_fetch; self.auto_fetch = !self.auto_fetch;
let mut state = self.state.lock().unwrap(); let mut state = self.state.lock();
state.sync_data.auto_web_fetch = self.auto_fetch; state.sync_data.auto_web_fetch = self.auto_fetch;
set_setting( set_setting(
"AUTO_WEB_FETCH".to_string(), "AUTO_WEB_FETCH".to_string(),
@@ -159,7 +160,7 @@ impl SyncState {
pub fn new(state: Arc<Mutex<AppState>>) -> SyncState { pub fn new(state: Arc<Mutex<AppState>>) -> SyncState {
let auto_fetch; let auto_fetch;
{ {
auto_fetch = state.lock().unwrap().sync_data.auto_web_fetch; auto_fetch = state.lock().sync_data.auto_web_fetch;
} }
Self { Self {
auto_fetch, auto_fetch,
@@ -176,7 +177,7 @@ impl SyncState {
space().into() space().into()
}; };
{ {
if let Some(key) = self.state.lock().unwrap().sync_data.key.clone() { if let Some(key) = self.state.lock().sync_data.key.clone() {
column![ column![
text!("Ваш ключ синхронизации"), text!("Ваш ключ синхронизации"),
container( container(
@@ -233,7 +234,7 @@ impl SyncState {
} }
self.frozen = true; self.frozen = true;
self.progress = 0.0; self.progress = 0.0;
let state = self.state.lock().unwrap(); let state = self.state.lock();
state state
.connection .connection
.query_row("PRAGMA wal_checkpoint(TRUNCATE)", [], |_| Ok(())) .query_row("PRAGMA wal_checkpoint(TRUNCATE)", [], |_| Ok(()))
+4 -3
View File
@@ -8,7 +8,8 @@ use crate::{AppState, RootMessage};
use iced::widget::button::danger; use iced::widget::button::danger;
use iced::widget::{button, column, row, rule, scrollable, text, text_input}; use iced::widget::{button, column, row, rule, scrollable, text, text_input};
use iced::{Element, Fill, Task}; use iced::{Element, Fill, Task};
use std::sync::{Arc, Mutex}; use std::sync::Arc;
use parking_lot::Mutex;
#[derive(Clone)] #[derive(Clone)]
pub struct WordState { pub struct WordState {
@@ -31,13 +32,13 @@ impl NavigatedPage<WordMessage> for WordState {
match message { match message {
Back => {} Back => {}
Save => { Save => {
let mut state = self.state.lock().unwrap(); let mut state = self.state.lock();
state.dictionary[self.index] = self.word.clone(); state.dictionary[self.index] = self.word.clone();
update_word(&mut self.word, &state.connection); update_word(&mut self.word, &state.connection);
return Task::done(RootMessage::Word(Back)); return Task::done(RootMessage::Word(Back));
} }
Delete => { Delete => {
let mut state = self.state.lock().unwrap(); let mut state = self.state.lock();
state.dictionary.remove(self.index); state.dictionary.remove(self.index);
delete_word(&self.word, &state.connection); delete_word(&self.word, &state.connection);
return Task::done(RootMessage::Word(Back)); return Task::done(RootMessage::Word(Back));