Skip to content

Commit

Permalink
restore saved notes exactly as they were
Browse files Browse the repository at this point in the history
if there were no open notes when you closed the app, the most recently
edited note will be opened when you open the app again
  • Loading branch information
vixalien committed Mar 23, 2023
1 parent 48142ad commit f62dd31
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,26 @@ export class Application extends Adw.Application {

this.init_actions();

load_notes()
.then((notes) => {
notes.forEach((note) => {
note.connect("notify::modified", (_, x) => {
save_note(note);
});

// changing open doesn't change modified
note.connect("notify::open", () => {
save_note(note);
});

this.notes_list.append(note);

if (note.open) {
this.show_note(note.uuid);
}
try {
const notes = load_notes();

notes.forEach((note) => {
note.connect("notify::modified", (_, x) => {
save_note(note);
});

// changing open doesn't change modified
note.connect("notify::open", () => {
save_note(note);
});

this.sort_notes();
}).catch(console.log);
this.notes_list.append(note);
});

this.sort_notes();
} catch (error) {
console.error(error as any);
}
}

save() {
Expand Down Expand Up @@ -108,14 +107,21 @@ export class Application extends Adw.Application {

this.foreach_note((note) => {
if (note.open) {
has_one_open = true;
if (has_one_open == false) has_one_open = true;
this.show_note(note.uuid);
}
});

if (!has_one_open) {
settings.set_boolean("show-all-notes", true);
this.all_notes();
const last_open_note = this.notes_array()
.sort((a, b) => b.modified.compare(a.modified))[0];

if (has_one_open) {
this.show_note(last_open_note.uuid);
} else {
settings.set_boolean("show-all-notes", true);
this.all_notes();
}
}
}

Expand Down

0 comments on commit f62dd31

Please sign in to comment.