mirror of
https://github.com/zadam/trilium.git
synced 2026-01-04 05:34:30 +01:00
feat(window): record openNoteContents of recently closed windows
This commit is contained in:
parent
7740154bdc
commit
3353d4f436
@ -41,9 +41,6 @@ export default class TabManager extends Component {
|
||||
this.recentlyClosedTabs = [];
|
||||
|
||||
this.tabsUpdate = new SpacedUpdate(async () => {
|
||||
if (!appContext.isMainWindow) {
|
||||
return;
|
||||
}
|
||||
if (options.is("databaseReadonly")) {
|
||||
return;
|
||||
}
|
||||
@ -52,9 +49,21 @@ export default class TabManager extends Component {
|
||||
.map((nc) => nc.getPojoState())
|
||||
.filter((t) => !!t);
|
||||
|
||||
await server.put("options", {
|
||||
openNoteContexts: JSON.stringify(openNoteContexts)
|
||||
});
|
||||
// Update the current window’s openNoteContexts in options
|
||||
const savedWindows = options.getJson("openNoteContexts");
|
||||
const win = savedWindows.find(w => w.windowId === appContext.windowId);
|
||||
if (win) {
|
||||
win.contexts = openNoteContexts;
|
||||
} else {
|
||||
savedWindows.push({
|
||||
windowId: appContext.windowId,
|
||||
createdAt: Date.now(),
|
||||
closedAt: null,
|
||||
contexts: savedWindows
|
||||
});
|
||||
}
|
||||
|
||||
await options.save("openNoteContexts", JSON.stringify(savedWindows));
|
||||
});
|
||||
|
||||
appContext.addBeforeUnloadListener(this);
|
||||
@ -69,8 +78,13 @@ export default class TabManager extends Component {
|
||||
}
|
||||
|
||||
async loadTabs() {
|
||||
// Get the current window’s openNoteContexts
|
||||
const savedWindows = options.getJson("openNoteContexts");
|
||||
const currentWin = savedWindows.find(w => w.windowId === appContext.windowId);
|
||||
const openNoteContexts = currentWin ? currentWin.contexts : undefined;
|
||||
|
||||
try {
|
||||
const noteContextsToOpen = (appContext.isMainWindow && options.getJson("openNoteContexts")) || [];
|
||||
const noteContextsToOpen = openNoteContexts || [];
|
||||
|
||||
// preload all notes at once
|
||||
await froca.getNotes([...noteContextsToOpen.flatMap((tab: NoteContextState) =>
|
||||
@ -119,6 +133,30 @@ export default class TabManager extends Component {
|
||||
}
|
||||
});
|
||||
|
||||
// Save window contents
|
||||
if (currentWin) {
|
||||
currentWin.createdAt = Date.now(),
|
||||
currentWin.closedAt = null;
|
||||
currentWin.contexts = filteredNoteContexts;
|
||||
} else {
|
||||
// Filter out the oldest entry (excluding the main window)
|
||||
if (savedWindows.length >= 10) {
|
||||
const candidates = savedWindows.filter(w => w.windowId !== "main");
|
||||
const oldestIndex = candidates.reduce((a, b) =>
|
||||
a.createdAt < b.createdAt ? a : b
|
||||
);
|
||||
savedWindows.splice(savedWindows.indexOf(oldestIndex), 1);
|
||||
}
|
||||
savedWindows.push({
|
||||
windowId: appContext.windowId,
|
||||
createdAt: Date.now(),
|
||||
closedAt: null,
|
||||
contexts: filteredNoteContexts
|
||||
});
|
||||
}
|
||||
|
||||
await options.save("openNoteContexts", JSON.stringify(savedWindows));
|
||||
|
||||
// if there's a notePath in the URL, make sure it's open and active
|
||||
// (useful, for e.g., opening clipped notes from clipper or opening link in an extra window)
|
||||
if (parsedFromUrl.notePath) {
|
||||
|
||||
@ -45,8 +45,15 @@ async function initNotSyncedOptions(initialized: boolean, opts: NotSyncedOpts =
|
||||
"openNoteContexts",
|
||||
JSON.stringify([
|
||||
{
|
||||
notePath: "root",
|
||||
active: true
|
||||
windowId: "main",
|
||||
createdAt: 0,
|
||||
closedAt: null,
|
||||
contexts: [
|
||||
{
|
||||
notePath: "root",
|
||||
active: true
|
||||
}
|
||||
]
|
||||
}
|
||||
]),
|
||||
false
|
||||
@ -251,8 +258,15 @@ function initStartupOptions() {
|
||||
"openNoteContexts",
|
||||
JSON.stringify([
|
||||
{
|
||||
notePath: process.env.TRILIUM_START_NOTE_ID || "root",
|
||||
active: true
|
||||
windowId: "main",
|
||||
createdAt: 0,
|
||||
closedAt: null,
|
||||
contexts: [
|
||||
{
|
||||
notePath: process.env.TRILIUM_START_NOTE_ID || "root",
|
||||
active: true
|
||||
}
|
||||
]
|
||||
}
|
||||
])
|
||||
);
|
||||
|
||||
@ -147,8 +147,15 @@ async function createInitialDatabase(skipDemoDb?: boolean) {
|
||||
"openNoteContexts",
|
||||
JSON.stringify([
|
||||
{
|
||||
notePath: startNoteId,
|
||||
active: true
|
||||
windowId: "main",
|
||||
createdAt: 0,
|
||||
closedAt: null,
|
||||
contexts: [
|
||||
{
|
||||
notePath: startNoteId,
|
||||
active: true
|
||||
}
|
||||
]
|
||||
}
|
||||
])
|
||||
);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user