mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-21 01:18:43 +00:00
Attribute browser Actions save warnings to Actions
This commit is contained in:
1 parent
5079bfcceb
commit
7faa701073
2 files changed
+36
-17
No files matched your search
@@ -95,6 +95,11 @@ impl From<String> for WriteError {
|
||||
}
|
||||
}
|
||||
|
||||
pub enum SaveWarning {
|
||||
Actions(String),
|
||||
Presets(String),
|
||||
}
|
||||
|
||||
/// Three sampled images per preset (tip, dual tip, texture), plus group/index/action/pattern records.
|
||||
pub const MAX_RECORDS: usize = MAX_GROUPS + MAX_PRESETS_PER_GROUP * 3 + 3;
|
||||
|
||||
@@ -271,16 +276,16 @@ impl Bridge {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn error(&self) -> Option<String> {
|
||||
pub fn error(&self) -> Option<SaveWarning> {
|
||||
let s = self.state();
|
||||
s.rejected
|
||||
.values()
|
||||
.iter()
|
||||
.next()
|
||||
.cloned()
|
||||
.or_else(|| s.error.clone())
|
||||
.or_else(|| s.action_error.as_ref().map(|e| e.message().to_owned()))
|
||||
.or_else(|| s.action_quarantine.clone())
|
||||
.or_else(|| s.actions_unsynced.then(|| "Browser Actions definitions could not be staged".into()))
|
||||
.map(|(name, error)| if name == ACTIONS_FILE { SaveWarning::Actions(error.clone()) } else { SaveWarning::Presets(error.clone()) })
|
||||
.or_else(|| s.error.clone().map(SaveWarning::Presets))
|
||||
.or_else(|| s.action_error.as_ref().map(|e| SaveWarning::Actions(e.message().to_owned())))
|
||||
.or_else(|| s.action_quarantine.clone().map(SaveWarning::Actions))
|
||||
.or_else(|| s.actions_unsynced.then(|| SaveWarning::Actions("Browser Actions definitions could not be staged".into())))
|
||||
}
|
||||
|
||||
pub fn unsaved(&self) -> bool {
|
||||
@@ -457,6 +462,7 @@ mod tests {
|
||||
#[test]
|
||||
fn stale_or_uncertain_actions_do_not_block_ordinary_presets() {
|
||||
for error in [WriteError::Stale("stale".into()), WriteError::Uncertain("unknown commit".into())] {
|
||||
let reason = error.message().to_owned();
|
||||
let bridge = Bridge::default();
|
||||
bridge.load_action_keys(5, ActionKeys::default());
|
||||
bridge.write(ACTIONS_FILE, b"local actions").unwrap();
|
||||
@@ -476,6 +482,7 @@ mod tests {
|
||||
bridge.finish(batch, Ok(()));
|
||||
assert!(bridge.unsaved(), "the Action intent is still pending");
|
||||
assert!(bridge.begin().is_none(), "retry must wait for a fresh Action generation");
|
||||
assert!(matches!(bridge.error(), Some(SaveWarning::Actions(message)) if message == reason));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -554,7 +561,7 @@ mod tests {
|
||||
b.write("index.json", b"new").unwrap();
|
||||
b.finish(batch, Err(WriteError::Aborted("QuotaExceededError".into())));
|
||||
assert!(b.unsaved());
|
||||
assert!(b.error().unwrap().contains("QuotaExceeded"));
|
||||
assert!(matches!(b.error(), Some(SaveWarning::Presets(message)) if message == "QuotaExceededError"));
|
||||
assert!(b.begin().is_none());
|
||||
b.retry();
|
||||
let batch = b.begin().unwrap();
|
||||
@@ -663,7 +670,7 @@ mod tests {
|
||||
import(&mut s);
|
||||
assert!(s.tools.presets.iter().any(|p| p.name == "Browser seam brush"));
|
||||
assert!(b.unsaved());
|
||||
assert!(b.error().unwrap().contains("SecurityError"));
|
||||
assert!(matches!(b.error(), Some(SaveWarning::Presets(message)) if message == "SecurityError"));
|
||||
assert!(b.begin().is_none());
|
||||
}
|
||||
#[test]
|
||||
|
||||
@@ -14,6 +14,8 @@ use photocraft_ui_egui::theme::ThemeKind;
|
||||
use photocraft_ui_egui::{FileDialogAnswer, FileDialogRequest, PhotocraftApp, Services};
|
||||
use wasm_bindgen::JsCast as _;
|
||||
|
||||
use crate::preset_bridge::SaveWarning;
|
||||
|
||||
type Inbox = Arc<Mutex<Vec<(String, Vec<u8>)>>>;
|
||||
type PlaceInbox = photocraft_ui_egui::PlaceInbox;
|
||||
|
||||
@@ -499,11 +501,11 @@ impl eframe::App for WebShell {
|
||||
}
|
||||
|
||||
fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) {
|
||||
// Only while a preset change is unsaved. Storage the browser denies from the start (a
|
||||
// Only while a change is unsaved. Storage the browser denies from the start (a
|
||||
// sandboxed iframe, blocked site data) loses nothing until the first change, and that
|
||||
// change brings the banner with the reason.
|
||||
if self.presets.unsaved()
|
||||
&& let Some(error) = self.presets.error()
|
||||
&& let Some(warning) = self.presets.error()
|
||||
{
|
||||
egui::Panel::top("browser_preset_storage").show(ui, |ui| {
|
||||
let tokens = photocraft_ui_egui::theme::Tokens::for_kind(self.app.ui.theme);
|
||||
@@ -513,13 +515,23 @@ impl eframe::App for WebShell {
|
||||
self.presets.retry();
|
||||
ui.ctx().request_repaint();
|
||||
}
|
||||
ui.colored_label(tokens.warning, i18n::fmt(i18n::t("Brush preset changes are not saved: {error}"), &[("error", &error)]));
|
||||
});
|
||||
ui.label(if self.database.is_some() {
|
||||
i18n::t("Keep this tab open to retain your brushes.")
|
||||
} else {
|
||||
i18n::t("Browser storage is unavailable; brushes are session-only. Keep this tab open to retain them.")
|
||||
match &warning {
|
||||
SaveWarning::Actions(error) => {
|
||||
ui.colored_label(tokens.warning, i18n::t("Actions"));
|
||||
ui.colored_label(tokens.warning, error.as_str());
|
||||
}
|
||||
SaveWarning::Presets(error) => {
|
||||
ui.colored_label(tokens.warning, i18n::fmt(i18n::t("Brush preset changes are not saved: {error}"), &[("error", error)]));
|
||||
}
|
||||
}
|
||||
});
|
||||
if matches!(warning, SaveWarning::Presets(_)) {
|
||||
ui.label(if self.database.is_some() {
|
||||
i18n::t("Keep this tab open to retain your brushes.")
|
||||
} else {
|
||||
i18n::t("Browser storage is unavailable; brushes are session-only. Keep this tab open to retain them.")
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
self.app.ui_frame(ui, frame);
|
||||
|
||||
Reference in new issue
Block a user