Migrate to parking_lot

This commit is contained in:
micialware committed 2026-08-20 00:07:09 +03:00
1 parent bf805b79e5
commit 66f8a83dec
13 files changed
+85 -73

No files matched your search

+24 -23
View File
@@ -22,7 +22,8 @@ use rand::random_range;
use std::fs;
use std::ops::Add;
use std::path::PathBuf;
use std::sync::{Arc, Mutex};
use std::sync::Arc;
use parking_lot::Mutex;
use std::time::{Duration, Instant};
#[derive(Clone)]
@@ -73,7 +74,7 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
&& self.include_map.iter().any(|x| *x)
{
let mut words = vec![];
let dict = &self.state.lock().unwrap().dictionary;
let dict = &self.state.lock().dictionary;
words = self
.include_map
@@ -92,7 +93,7 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
if let WordAction(index) = message {
let word: WordData;
{
let state = self.state.lock().unwrap();
let state = self.state.lock();
let dict = &state.dictionary;
word = dict[*index].clone();
}
@@ -107,7 +108,7 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
}
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.tag_map = Default::default();
@@ -117,7 +118,7 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
fn update(&mut self, message: DictionaryMessage) -> Task<RootMessage> {
match message {
NewWord => {
let mut state = self.state.lock().unwrap();
let mut state = self.state.lock();
let mut word = WordData::new();
word.group_id = state.word_groups[self.selected_group_index].id;
@@ -128,21 +129,21 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
SetKey(i, v) => {
{
let dict = &mut self.state.lock().unwrap().dictionary;
let dict = &mut self.state.lock().dictionary;
dict[i].key = v;
}
return self.launch_auto_save_offset(i);
}
SetValue(i, v) => {
{
let dict = &mut self.state.lock().unwrap().dictionary;
let dict = &mut self.state.lock().dictionary;
dict[i].value = v
}
return self.launch_auto_save_offset(i);
}
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();
@@ -162,7 +163,7 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
}
WordAction(i) => {
let state = &mut self.state.lock().unwrap();
let state = &mut self.state.lock();
let dict = &mut state.dictionary;
let word = dict.remove(i);
self.include_map.remove(i);
@@ -173,7 +174,7 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
IncludeTag(t, v) => {
let index;
{
let state = self.state.lock().unwrap();
let state = self.state.lock();
index = state.word_groups[self.selected_group_index].id;
}
self.tag_map.insert(t, v);
@@ -193,7 +194,7 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
Back => {}
Test => {}
CreateGroup => {
let state = &mut self.state.lock().unwrap();
let state = &mut self.state.lock();
state.word_groups.push(WordGroup {
id: 0.into(),
@@ -201,14 +202,14 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
});
}
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);
if let Some(group) = group {
group.name = new.clone();
}
}
SaveGroup => {
let state = &mut self.state.lock().unwrap();
let state = &mut self.state.lock();
let connection = &state.connection;
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;
let index;
{
let state = self.state.lock().unwrap();
let state = self.state.lock();
index = state.word_groups[i].id;
}
self.update_words_include(index)
@@ -229,7 +230,7 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
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) {
let remove_group_id = group.id;
@@ -289,7 +290,7 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
impl DictionaryState {
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 {
include_map: vec![false; len],
@@ -309,7 +310,7 @@ impl DictionaryState {
}
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 word = &mut state.dictionary[i].clone();
@@ -331,7 +332,7 @@ impl DictionaryState {
let time = Instant::now();
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 dict = &state.dictionary;
@@ -443,7 +444,7 @@ impl DictionaryState {
}
fn filters(&self) -> iced::Element<'_, DictionaryMessage> {
let dict = &self.state.lock().unwrap().dictionary;
let dict = &self.state.lock().dictionary;
iced::widget::column![
text_input("Поиск", &self.search)
@@ -499,7 +500,7 @@ impl DictionaryState {
fn update_tags(&mut self) {
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| {
split_with_coma(element.tags.as_str())
@@ -540,7 +541,7 @@ impl DictionaryState {
return;
}
let dict = &self.state.lock().unwrap().dictionary;
let dict = &self.state.lock().dictionary;
let time = Instant::now();
self.include_map = dict
@@ -560,7 +561,7 @@ impl DictionaryState {
let mut row = Row::new();
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;
for (index, group) in groups.iter().enumerate() {
@@ -598,7 +599,7 @@ impl DictionaryState {
}
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 button = button("Добавить слово").style(jl_button);