From 32d1d03d11b380249e1f01b4cbbcb2f22591c403 Mon Sep 17 00:00:00 2001 From: ThaUnknown <6506529+ThaUnknown@users.noreply.github.com> Date: Tue, 20 Aug 2024 17:10:59 +0200 Subject: [PATCH] feat: #470 use a router for navigation, support backwards/forwards navigation --- README.md | 2 +- common/App.svelte | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b1196abf..37cb7db0 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,7 @@ apt install linux-Miru-*.deb ## **Building and Development** -*dont* +*good luck* Dependencies: - Node 16 or above diff --git a/common/App.svelte b/common/App.svelte index c165b999..8c44adcc 100644 --- a/common/App.svelte +++ b/common/App.svelte @@ -14,6 +14,35 @@ IPC.on('schedule', () => { page.set('schedule') }) + + let ignoreNext = false + function addPage (value, type) { + if (ignoreNext) { + ignoreNext = false + return + } + history.pushState({ type, value }, '', './?id=' + Math.trunc(Math.random() * Number.MAX_SAFE_INTEGER).toString()) + } + page.subscribe((value) => { + addPage(value, 'page') + }) + view.subscribe((value) => { + addPage(value, 'view') + }) + + addPage('home', 'page') + + window.addEventListener('popstate', e => { + const { state } = e + if (!state) return + ignoreNext = true + view.set(null) + if (state.type === 'page') { + page.set(state.value) + } else { + view.set(state.value) + } + })