aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/modules/notes/NotesModule.qml
diff options
context:
space:
mode:
Diffstat (limited to 'desktop/modules/notes/NotesModule.qml')
-rw-r--r--desktop/modules/notes/NotesModule.qml45
1 files changed, 28 insertions, 17 deletions
diff --git a/desktop/modules/notes/NotesModule.qml b/desktop/modules/notes/NotesModule.qml
index 082f02c..992cbfa 100644
--- a/desktop/modules/notes/NotesModule.qml
+++ b/desktop/modules/notes/NotesModule.qml
@@ -150,27 +150,38 @@ Module {
if (done) done(ok, ok ? "" : mod.dbView.saveError);
}
- // A note body. notes.sh keeps the title out of the file, so this is the
- // body and nothing else. setText writes the path directly and needs no
- // prior load; reading the file back is what would need one, and nothing
- // here reads it back.
- property FileView bodyView: FileView {
- blockWrites: true
- printErrors: false
- property string saveError: ""
- onSaved: saveError = ""
- onSaveFailed: error => {
- console.warn("notes: note body write failed:", error);
- saveError = "the note's file could not be written";
+ // A note body, written through a Process rather than a FileView.
+ // FileView.setText() with EMPTY text on a path that view has not loaded
+ // writes no file at all and reports no error, which is how a note created
+ // with an empty body ended up in db.json with no file beside it. cat reads
+ // stdin, so any content and any length works, including none, and the exit
+ // code is the real outcome. Clearing stdinEnabled after the write is what
+ // gives cat its EOF.
+ property Process bodyWriter: Process {
+ stdinEnabled: true
+ property string data: ""
+ property var done: null
+ property string err: ""
+ onStarted: {
+ mod.bodyWriter.write(mod.bodyWriter.data);
+ mod.bodyWriter.stdinEnabled = false;
+ }
+ onExited: code => {
+ const d = mod.bodyWriter.done;
+ mod.bodyWriter.done = null;
+ if (d) d(code === 0, code === 0 ? "" : (mod.bodyWriter.err || "the note's file could not be written"));
}
+ stderr: StdioCollector { onStreamFinished: mod.bodyWriter.err = this.text }
}
function writeBody(path, text, done) {
- mod.bodyView.path = path;
- mod.bodyView.saveError = "";
- mod.bodyView.setText(text);
- const ok = mod.bodyView.saveError === "";
- if (done) done(ok, ok ? "" : mod.bodyView.saveError);
+ mod.bodyWriter.done = done;
+ mod.bodyWriter.data = text;
+ mod.bodyWriter.err = "";
+ mod.bodyWriter.command = ["sh", "-c", 'cat > "$1"', "sh", path];
+ mod.bodyWriter.stdinEnabled = true;
+ mod.bodyWriter.running = false;
+ mod.bodyWriter.running = true;
}
// The path of a note's body, "" when the entry's file is not a plain