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
+12 -11
View File
@@ -9,7 +9,8 @@ use iced::widget::button::danger;
use iced::widget::container::rounded_box;
use iced::widget::{button, column, container, progress_bar, row, space, text, toggler};
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;
#[derive(Clone)]
@@ -52,7 +53,7 @@ impl NavigatedPage<SyncMessage> for SyncState {
match message {
Back => {}
CopyKey => {
let state = self.state.lock().unwrap();
let state = self.state.lock();
let key = state.sync_data.key.clone().unwrap();
return iced::clipboard::write(key)
.map(|_val: String| RootMessage::Sync(KeyCopied));
@@ -69,14 +70,14 @@ impl NavigatedPage<SyncMessage> for SyncState {
if !validate_id(&new_id) {
return Task::none();
}
let mut state = self.state.lock().unwrap();
let mut state = self.state.lock();
state.sync_data.key = Some(new_id.clone());
set_setting("SYNC_KEY".to_string(), new_id, &state.connection);
}
Send => {
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([
Task::perform(
async { tokio::time::sleep(Duration::from_millis(200)).await },
@@ -88,7 +89,7 @@ impl NavigatedPage<SyncMessage> for SyncState {
return tasks;
}
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([
Task::perform(
async { tokio::time::sleep(Duration::from_millis(200)).await },
@@ -116,7 +117,7 @@ impl NavigatedPage<SyncMessage> for SyncState {
let mut updated_state = AppState::new();
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.connection = updated_state.connection;
state.decks = updated_state.decks;
@@ -125,14 +126,14 @@ impl NavigatedPage<SyncMessage> for SyncState {
}
Disable => {}
DisableSync => {
let mut state = self.state.lock().unwrap();
let mut state = self.state.lock();
state.sync_data.key = None;
delete_settings("SYNC_KEY".to_string(), &state.connection);
delete_settings("AUTO_WEB_FETCH".to_string(), &state.connection);
}
SwitchAutoSync => {
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;
set_setting(
"AUTO_WEB_FETCH".to_string(),
@@ -159,7 +160,7 @@ impl SyncState {
pub fn new(state: Arc<Mutex<AppState>>) -> SyncState {
let auto_fetch;
{
auto_fetch = state.lock().unwrap().sync_data.auto_web_fetch;
auto_fetch = state.lock().sync_data.auto_web_fetch;
}
Self {
auto_fetch,
@@ -176,7 +177,7 @@ impl SyncState {
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![
text!("Ваш ключ синхронизации"),
container(
@@ -233,7 +234,7 @@ impl SyncState {
}
self.frozen = true;
self.progress = 0.0;
let state = self.state.lock().unwrap();
let state = self.state.lock();
state
.connection
.query_row("PRAGMA wal_checkpoint(TRUNCATE)", [], |_| Ok(()))