mirror of
https://github.com/zadam/trilium.git
synced 2025-11-13 00:35:50 +01:00
prompt user when there are unsaved changes, #1692
This commit is contained in:
@@ -54,8 +54,6 @@ export default class NoteDetailWidget extends TabAwareWidget {
|
||||
|
||||
this.typeWidgets = {};
|
||||
|
||||
const updateInterval = utils.isDesktop() ? 1000 : 5000;
|
||||
|
||||
this.spacedUpdate = new SpacedUpdate(async () => {
|
||||
const {note} = this.tabContext;
|
||||
const {noteId} = note;
|
||||
@@ -66,7 +64,9 @@ export default class NoteDetailWidget extends TabAwareWidget {
|
||||
protectedSessionHolder.touchProtectedSessionIfNecessary(note);
|
||||
|
||||
await server.put('notes/' + noteId, dto, this.componentId);
|
||||
}, updateInterval);
|
||||
});
|
||||
|
||||
appContext.addBeforeUnloadListener(this);
|
||||
}
|
||||
|
||||
isEnabled() {
|
||||
@@ -295,7 +295,7 @@ export default class NoteDetailWidget extends TabAwareWidget {
|
||||
}
|
||||
|
||||
beforeUnloadEvent() {
|
||||
this.spacedUpdate.updateNowIfNecessary();
|
||||
return this.spacedUpdate.isAllSavedAndTriggerUpdate();
|
||||
}
|
||||
|
||||
textPreviewDisabledEvent({tabContext}) {
|
||||
|
||||
@@ -3,6 +3,7 @@ import utils from "../services/utils.js";
|
||||
import protectedSessionHolder from "../services/protected_session_holder.js";
|
||||
import server from "../services/server.js";
|
||||
import SpacedUpdate from "../services/spaced_update.js";
|
||||
import appContext from "../services/app_context.js";
|
||||
|
||||
const TPL = `
|
||||
<div class="note-title-container">
|
||||
@@ -37,6 +38,8 @@ export default class NoteTitleWidget extends TabAwareWidget {
|
||||
|
||||
await server.put(`notes/${this.noteId}/change-title`, {title});
|
||||
});
|
||||
|
||||
appContext.addBeforeUnloadListener(this);
|
||||
}
|
||||
|
||||
doRender() {
|
||||
@@ -101,6 +104,6 @@ export default class NoteTitleWidget extends TabAwareWidget {
|
||||
}
|
||||
|
||||
beforeUnloadEvent() {
|
||||
this.spacedUpdate.updateNowIfNecessary();
|
||||
return this.spacedUpdate.isAllSavedAndTriggerUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user