From 7179715ec1f27a784db69f2df41fc1e692ffc52e Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Thu, 27 Aug 2026 20:00:08 +0200 Subject: [PATCH] fix crash + correctly load attachments when creating the note view model --- application/note/src/note.rs | 11 ++++++++--- ui-rs/src/ui/button.rs | 1 - ui/common/args.c | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/application/note/src/note.rs b/application/note/src/note.rs index 978ab28..900cc17 100644 --- a/application/note/src/note.rs +++ b/application/note/src/note.rs @@ -134,6 +134,7 @@ impl Note { } else { n.init_from_model(model); n.load_content(); + n.load_attachments(); } // make sure we receive an event, when this note is attached or detached d.ctx.on_attachment_status_change_action("attachment_status_changed"); @@ -278,11 +279,16 @@ impl Note { let proxy = doc.doc_proxy(); self.backend.get_note_attachments(note_id, move|result|{ - proxy.call_mainthread(move |_doc, note|{ + proxy.call_mainthread(move |doc, note|{ match result { Ok(attachments) => { note.attachments.data_mut().clear(); - note.attachments.data_mut().extend(attachments); + if attachments.len() > 0 { + note.attachments.data_mut().extend(attachments); + doc.ctx.set_state(AppStates::NoteHasAttachments); + } else { + doc.ctx.unset_state(AppStates::NoteHasAttachments); + } note.attachments.update(); }, Err(e) => { @@ -367,7 +373,6 @@ impl Note { println!("note changed by {}", _from); self.load_content(); - self.load_attachments(); } /// Event before the text is changed: detect if the change affects the title diff --git a/ui-rs/src/ui/button.rs b/ui-rs/src/ui/button.rs index 5338f3f..5373595 100644 --- a/ui-rs/src/ui/button.rs +++ b/ui-rs/src/ui/button.rs @@ -36,7 +36,6 @@ use crate::ui::{event, toolkit, EventWrapper}; use crate::ui::ffi::*; use crate::ui::widget::*; - #[macro_export] macro_rules! button { ($parent:expr, $($tt:tt)*) => { diff --git a/ui/common/args.c b/ui/common/args.c index 822a7c9..8053d82 100644 --- a/ui/common/args.c +++ b/ui/common/args.c @@ -641,7 +641,7 @@ void ui_container_args_free(UiContainerArgs *args) { UiFrameArgs* ui_frame_args_new(void) { UiFrameArgs *args = malloc(sizeof(UiFrameArgs)); - memset(args, 0, sizeof(UiContainerArgs)); + memset(args, 0, sizeof(UiFrameArgs)); return args; } -- 2.52.0