Fix compression bug
This commit is contained in:
1 parent
1d24fe2631
commit
dddac01bdf
4 files changed
+61
-76
No files matched your search
+34
-36
@@ -6,11 +6,11 @@ use crate::data_provider::web_api::{
|
||||
get_local_version, get_web_version, load_data, set_local_version,
|
||||
};
|
||||
use crate::fs::*;
|
||||
use crate::{message_navigation, push_error, push_error_task};
|
||||
use crate::navigation::Page::*;
|
||||
use crate::navigation::RootMessage::{
|
||||
DataLoaded, Keyboard, Notification, PushNotification, UpdateData,
|
||||
};
|
||||
use crate::notification::NotificationData::PermissionDenied;
|
||||
use crate::notification::{
|
||||
NotificationData, NotificationManager, NotificationMessage, NotificationRequest,
|
||||
};
|
||||
@@ -30,6 +30,7 @@ use crate::pages::writing::{WritingMessage, WritingState};
|
||||
use crate::state_navigate_handle;
|
||||
use crate::state_update;
|
||||
use crate::view_navigation;
|
||||
use crate::{message_navigation, push_error, push_error_task};
|
||||
use chrono::NaiveDate;
|
||||
use hashbrown::HashMap;
|
||||
use iced::keyboard::Event;
|
||||
@@ -41,7 +42,6 @@ use parking_lot::Mutex;
|
||||
use rusqlite::Connection;
|
||||
use std::sync::Arc;
|
||||
use std::time::Instant;
|
||||
use crate::notification::NotificationData::PermissionDenied;
|
||||
|
||||
impl Default for ScreenState {
|
||||
fn default() -> Self {
|
||||
@@ -109,7 +109,8 @@ impl ScreenState {
|
||||
create_db();
|
||||
info!("Db created");
|
||||
let state = ScreenState::default();
|
||||
let reading_additional_task = Task::perform(Self::load_additional_data(), |data| data);
|
||||
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();
|
||||
@@ -126,7 +127,7 @@ impl ScreenState {
|
||||
RootMessage::None
|
||||
}
|
||||
}
|
||||
Err(err) => PushNotification(NotificationRequest::Warning(err)),
|
||||
Err(err) => push_error!(err),
|
||||
}),
|
||||
]);
|
||||
}
|
||||
@@ -136,39 +137,36 @@ impl ScreenState {
|
||||
(state, final_task)
|
||||
}
|
||||
|
||||
async fn load_additional_data() -> RootMessage {
|
||||
let directory = history_dir();
|
||||
async fn load_additional_data() -> Result<RootMessage, NotificationData> {
|
||||
let directory = history_dir()?;
|
||||
|
||||
if let Ok(directory) = directory {
|
||||
let mut map = HashMap::new();
|
||||
for file in directory
|
||||
.read_dir()
|
||||
.expect("Cant read history directory")
|
||||
.flatten()
|
||||
let mut map = HashMap::new();
|
||||
for file in directory
|
||||
.read_dir()
|
||||
.map_err(|_| PermissionDenied)?
|
||||
.filter_map(Result::ok)
|
||||
{
|
||||
let mut vec = vec![];
|
||||
let history_file_name = match file.file_name().into_string() {
|
||||
Err(_) => continue,
|
||||
Ok(v) => v,
|
||||
};
|
||||
|
||||
if let Ok(id) = history_file_name.split('_').collect::<Vec<_>>()[1].parse::<Id>()
|
||||
&& let Ok(history) = get_history_of_set(id)
|
||||
{
|
||||
let mut vec = vec![];
|
||||
let history_file_name = match file.file_name().into_string() {
|
||||
Err(_) => continue,
|
||||
Ok(v) => v,
|
||||
};
|
||||
|
||||
if let Ok(id) = history_file_name[4..history_file_name.len() - 12].parse::<Id>()
|
||||
&& let Ok(history) = get_history_of_set(id)
|
||||
{
|
||||
let by_date = history.chunk_by(|x, x1| {
|
||||
x.timestamp.naive_local().date() == x1.timestamp.naive_local().date()
|
||||
});
|
||||
for group in by_date {
|
||||
vec.push((group[0].timestamp.naive_local().date(), group.len() as u32));
|
||||
}
|
||||
map.insert(id, vec);
|
||||
} else {
|
||||
return PushNotification(NotificationRequest::Warning(PermissionDenied));
|
||||
let by_date = history.chunk_by(|x, x1| {
|
||||
x.timestamp.naive_local().date() == x1.timestamp.naive_local().date()
|
||||
});
|
||||
for group in by_date {
|
||||
vec.push((group[0].timestamp.naive_local().date(), group.len() as u32));
|
||||
}
|
||||
map.insert(id, vec);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
return DataLoaded(map);
|
||||
}
|
||||
PushNotification(NotificationRequest::Warning(directory.err().unwrap()))
|
||||
Ok(DataLoaded(map))
|
||||
}
|
||||
|
||||
async fn load_web_backup(string: String) -> Result<bool, NotificationData> {
|
||||
@@ -205,8 +203,8 @@ impl ScreenState {
|
||||
}
|
||||
let db_file = db_path();
|
||||
let temp_db_file = temp_db_path();
|
||||
if std::fs::rename(temp_db_file, &db_file).is_err(){
|
||||
return push_error_task!(PermissionDenied)
|
||||
if std::fs::rename(temp_db_file, &db_file).is_err() {
|
||||
return push_error_task!(PermissionDenied);
|
||||
}
|
||||
|
||||
state.connection = default_connection();
|
||||
@@ -294,11 +292,11 @@ impl ScreenState {
|
||||
}
|
||||
|
||||
fn handle_keyboard(&mut self, message: Event) -> Task<RootMessage> {
|
||||
if let Some(page) = self.stack.last_mut(){
|
||||
if let Some(page) = self.stack.last_mut() {
|
||||
return match page {
|
||||
Repetition(page) => page.press(&message),
|
||||
_ => Task::none(),
|
||||
}
|
||||
};
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user