diff --git a/web/js/app.js b/web/js/app.js index cb9ecd9..795b953 100644 --- a/web/js/app.js +++ b/web/js/app.js @@ -385,7 +385,7 @@ const content = t.content.length > DRAFT_MAX ? t.content.slice(0, DRAFT_MAX) : t.content; return { draft: { title: t.title, format: t.format, categories: t.categories, content } }; }); - const active = state.tabs.findIndex((t) => t.key === state.activeKey); + const active = Math.max(0, state.tabs.findIndex((t) => t.key === state.activeKey)); localStorage.setItem(TABS_KEY, JSON.stringify({ open, active })); } catch { /* quota cheia: ignora */ } }, 400); @@ -415,8 +415,10 @@ } if (!opened.length) opened.push(newTab()); } + // índice salvo pode ser inválido (-1 de sessão encerrada sem aba ativa, etc.) state.tabs = opened; - const want = saved && Number.isInteger(saved.active) ? Math.min(saved.active, opened.length - 1) : 0; + const raw = saved && Number.isInteger(saved.active) ? saved.active : 0; + const want = Math.min(Math.max(0, raw), opened.length - 1); activateTab(opened[want].key); } @@ -2026,7 +2028,13 @@ async function boot() { applyPrefs(); await Promise.all([loadNotes(), loadAggregates()]); - await restoreTabs(); + try { + await restoreTabs(); + } catch (err) { + console.error('restoreTabs falhou', err); + state.tabs = [newTab()]; + activateTab(state.tabs[0].key); + } updateStatus(); state.booted = true; refreshInstallUI(); diff --git a/web/sw.js b/web/sw.js index 71a56c4..e71beec 100644 --- a/web/sw.js +++ b/web/sw.js @@ -1,7 +1,7 @@ /* Service Worker do Notas — caches versionados. * BUMP de CACHE em todo deploy que mude shell/assets (o activate limpa os antigos). */ -const CACHE = 'notas-shell-v2'; +const CACHE = 'notas-shell-v3'; const SHELL = [ '/', '/css/app.css',