Introduce MaybeError type

This commit is contained in:
micialware committed 2026-08-24 23:42:58 +03:00
1 parent d836b57d2a
commit a60ed37cd4
16 files changed
+127 -93

No files matched your search

+2 -2
View File
@@ -4,7 +4,7 @@ use crate::pages::import::ImportMessage::*;
use crate::data::entities::{WordData, WordGroup};
use crate::navigation::{NavigatedPage, Page, RootMessage};
use crate::notification::NotificationData::OpenFileError;
use crate::notification::NotificationData;
use crate::notification::{MaybeError, NotificationData};
use crate::styling::*;
use iced::widget::button::danger;
use iced::widget::container::success;
@@ -373,7 +373,7 @@ impl ImportState {
)
}
fn extract_import_file(path: PathBuf) -> Result<(), NotificationData> {
fn extract_import_file(path: PathBuf) -> MaybeError {
let file = File::open(path).map_err(|_| OpenFileError)?;
let reader = BufReader::new(file);
let mut archive = ZipArchive::new(reader).map_err(|_| OpenFileError)?;
+3 -3
View File
@@ -6,7 +6,7 @@ use crate::data::entities::{CardStatistics, DeckSettings, WordData};
use crate::data_provider::voice::get_voice;
use crate::navigation::Page::PreviousPage;
use crate::navigation::{KeyPressedPage, NavigatedPage, Page, RootMessage};
use crate::notification::NotificationData;
use crate::notification::{MaybeError, NotificationData};
use crate::styling::*;
use crate::{push_error, push_error_task};
use chrono::Local;
@@ -337,7 +337,7 @@ pub enum RepetitionMessage {
async fn play_sound(
sink: Arc<Option<MixerDeviceSink>>,
text: String,
) -> Result<(), NotificationData> {
) -> MaybeError {
let data = get_voice(text.as_str()).await?;
spawn_blocking(move || {
if let Some(sink) = sink.as_ref()
@@ -347,6 +347,6 @@ async fn play_sound(
}
})
.await
.unwrap();
.expect("Playing sound failed");
Ok(())
}
+3 -3
View File
@@ -4,7 +4,7 @@ use crate::data_provider::card_sets::{delete_set, update_deck};
use crate::data_provider::card_stats::{delete_stats, load_stats_of_deck};
use crate::navigation::Page::PreviousPage;
use crate::navigation::{NavigatedPage, Page, RootMessage};
use crate::notification::NotificationData;
use crate::notification::MaybeError;
use crate::pages::repetition_settings::RepetitionSettingsMessage::*;
use crate::styling::*;
use crate::{push_error, push_error_task};
@@ -13,7 +13,7 @@ use iced::widget::text_input::Catalog;
use iced::widget::{button, column, row, scrollable, space, text, text_input};
use iced::{Element, Task};
use iced_core::Length::Fill;
use iced_core::{Padding, Theme, color};
use iced_core::{color, Padding, Theme};
use parking_lot::Mutex;
use std::sync::Arc;
use std::time::Duration;
@@ -179,7 +179,7 @@ impl NavigatedPage<RepetitionSettingsMessage> for RepetitionSettingsState {
}
}
fn update_deck_stats(deck: &DeckSettings, state: &AppState) -> Result<(), NotificationData> {
fn update_deck_stats(deck: &DeckSettings, state: &AppState) -> MaybeError {
let mut db_stats = load_stats_of_deck(deck, &state.connection).expect("Wrong db operation");
let filtered_words = deck.get_word_list(state);
filtered_words.iter().for_each(|word| {
+9 -9
View File
@@ -1,12 +1,12 @@
use crate::app::AppState;
use crate::core::srs::{AppendMode, OrderMode};
use crate::data::Id;
use crate::data::entities::{CardStatistics, DeckSettings};
use crate::data::Id;
use crate::data_provider::card_sets::update_deck;
use crate::data_provider::card_stats::{add_stat_list, load_stats_of_deck};
use crate::navigation::Page::{History, PreviousPage, Repetition, RepetitionSettings};
use crate::navigation::{NavigatedPage, Page, RootMessage};
use crate::notification::{NotificationData, NotificationRequest};
use crate::notification::{MaybeError, NotificationRequest};
use crate::pages::history::HistoryState;
use crate::pages::repetition::RepetitionState;
use crate::pages::repetition_settings::RepetitionSettingsState;
@@ -16,17 +16,17 @@ use crate::push_error_task;
use crate::styling::*;
use chrono::{Days, Local, Utc};
use hashbrown::{HashMap, HashSet};
use iced::widget::button::{danger, Status};
pub use iced::widget::button::{Catalog, Style};
use iced::widget::button::{Status, danger};
use iced::widget::tooltip::Position::Top;
use iced::widget::{
Column, Row, button, column, container, lazy, radio, row, scrollable, space, svg, text,
text_input, tooltip,
button, column, container, lazy, radio, row, scrollable, space, svg, text, text_input, tooltip,
Column, Row,
};
use iced::{Background, Border, Center, Color, Element, Fill, Length, Shadow, Task, Theme};
use iced_core::Padding;
use iced_core::border::Radius;
use iced_core::svg::Handle;
use iced_core::Padding;
use parking_lot::Mutex;
use std::ops::Deref;
use std::sync::Arc;
@@ -562,7 +562,7 @@ impl RepetitionsState {
}
impl RepetitionsState {
fn append_all_words(state: &mut AppState, deck: &DeckViewData) -> Result<(), NotificationData> {
fn append_all_words(state: &mut AppState, deck: &DeckViewData) -> MaybeError {
let existing = &deck.existing_words_indices;
let mut created_set = HashSet::with_capacity(existing.len());
existing.iter().for_each(|c| {
@@ -580,7 +580,7 @@ impl RepetitionsState {
state: &mut AppState,
deck: &DeckSettings,
indices: impl Iterator<Item = usize>,
) -> Result<(), NotificationData> {
) -> MaybeError {
let words = &state.dictionary;
let stats = &mut indices
.map(|i| {
@@ -618,7 +618,7 @@ impl RepetitionsState {
self.selected_deck_index = None;
}
fn fill_deck_word_indices(&mut self) -> Result<(), NotificationData> {
fn fill_deck_word_indices(&mut self) -> MaybeError {
let state = &self.state.lock();
let mut deck = self.selected_deck().unwrap().clone();
let added: Vec<_> = load_stats_of_deck(&deck, &state.connection)?