mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
improved error handling in case of errors during initial tabs loading
This commit is contained in:
parent
173b28062e
commit
587387dd46
@ -48,60 +48,68 @@ export default class TabManager extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async loadTabs() {
|
async loadTabs() {
|
||||||
const tabsToOpen = appContext.isMainWindow
|
try {
|
||||||
? (options.getJson('openTabs') || [])
|
const tabsToOpen = appContext.isMainWindow
|
||||||
: [];
|
? (options.getJson('openTabs') || [])
|
||||||
|
: [];
|
||||||
|
|
||||||
let filteredTabs = [];
|
let filteredTabs = [];
|
||||||
|
|
||||||
// preload all notes at once
|
// preload all notes at once
|
||||||
await froca.getNotes([
|
await froca.getNotes([
|
||||||
tabsToOpen.map(tab => treeService.getNoteIdFromNotePath(tab.notePath)),
|
tabsToOpen.map(tab => treeService.getNoteIdFromNotePath(tab.notePath)),
|
||||||
tabsToOpen.map(tab => tab.hoistedNoteId),
|
tabsToOpen.map(tab => tab.hoistedNoteId),
|
||||||
], true);
|
], true);
|
||||||
|
|
||||||
for (const openTab of tabsToOpen) {
|
for (const openTab of tabsToOpen) {
|
||||||
if (openTab.notePath && !(treeService.getNoteIdFromNotePath(openTab.notePath) in froca.notes)) {
|
if (openTab.notePath && !(treeService.getNoteIdFromNotePath(openTab.notePath) in froca.notes)) {
|
||||||
// note doesn't exist so don't try to open tab for it
|
// note doesn't exist so don't try to open tab for it
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(openTab.hoistedNoteId in froca.notes)) {
|
||||||
|
openTab.hoistedNoteId = 'root';
|
||||||
|
}
|
||||||
|
|
||||||
|
filteredTabs.push(openTab);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!froca.getNoteFromCache(openTab.hoistedNoteId)) {
|
if (utils.isMobile()) {
|
||||||
continue;
|
// mobile frontend doesn't have tabs so show only the active tab
|
||||||
|
filteredTabs = filteredTabs.filter(tab => tab.active);
|
||||||
}
|
}
|
||||||
|
|
||||||
filteredTabs.push(openTab);
|
if (filteredTabs.length === 0) {
|
||||||
}
|
filteredTabs.push({
|
||||||
|
notePath: glob.extraHoistedNoteId || 'root',
|
||||||
|
active: true,
|
||||||
|
hoistedNoteId: glob.extraHoistedNoteId || 'root'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (utils.isMobile()) {
|
if (!filteredTabs.find(tab => tab.active)) {
|
||||||
// mobile frontend doesn't have tabs so show only the active tab
|
filteredTabs[0].active = true;
|
||||||
filteredTabs = filteredTabs.filter(tab => tab.active);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (filteredTabs.length === 0) {
|
await this.tabsUpdate.allowUpdateWithoutChange(async () => {
|
||||||
filteredTabs.push({
|
for (const tab of filteredTabs) {
|
||||||
notePath: glob.extraHoistedNoteId || 'root',
|
await this.openContextWithNote(tab.notePath, tab.active, tab.ntxId, tab.hoistedNoteId, tab.mainNtxId);
|
||||||
active: true,
|
}
|
||||||
hoistedNoteId: glob.extraHoistedNoteId || 'root'
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
if (!filteredTabs.find(tab => tab.active)) {
|
// if there's notePath in the URL, make sure it's open and active
|
||||||
filteredTabs[0].active = true;
|
// (useful, among others, for opening clipped notes from clipper)
|
||||||
}
|
if (treeService.isNotePathInAddress()) {
|
||||||
|
const [notePath, ntxId] = treeService.getHashValueFromAddress();
|
||||||
|
|
||||||
await this.tabsUpdate.allowUpdateWithoutChange(async () => {
|
await appContext.tabManager.switchToNoteContext(ntxId, notePath);
|
||||||
for (const tab of filteredTabs) {
|
|
||||||
await this.openContextWithNote(tab.notePath, tab.active, tab.ntxId, tab.hoistedNoteId, tab.mainNtxId);
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
catch (e) {
|
||||||
|
logError(`Loading tabs '${options.get('openTabs')}' failed: ${e.message}`);
|
||||||
|
|
||||||
// if there's notePath in the URL, make sure it's open and active
|
// try to recover
|
||||||
// (useful, among others, for opening clipped notes from clipper)
|
await this.openEmptyTab();
|
||||||
if (treeService.isNotePathInAddress()) {
|
|
||||||
const [notePath, ntxId] = treeService.getHashValueFromAddress();
|
|
||||||
|
|
||||||
await appContext.tabManager.switchToNoteContext(ntxId, notePath);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user