Skip to content

Commit

Permalink
feat: #470 use a router for navigation, support backwards/forwards na…
Browse files Browse the repository at this point in the history
…vigation
  • Loading branch information
ThaUnknown committed Aug 20, 2024
1 parent 1923be4 commit 32d1d03
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ apt install linux-Miru-*.deb

## **Building and Development**

*dont*
*good luck*

Dependencies:
- Node 16 or above
Expand Down
29 changes: 29 additions & 0 deletions common/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
</script>

<script>
Expand Down

0 comments on commit 32d1d03

Please sign in to comment.