feat: #470 use a router for navigation, support backwards/forwards navigation

removed fork's back button support
This commit is contained in:
ThaUnknown 2024-08-20 17:10:59 +02:00 committed by NoCrypt
parent 19be275482
commit d682d6d881
2 changed files with 28 additions and 27 deletions

View file

@ -14,7 +14,34 @@
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>

View file

@ -33,34 +33,8 @@
$: maxwidth = $isMobile ? '200px' : '60rem'
onMount(() => {
// Check update (ask if on Android, install if on PC)
// Check update
if($settings.enableAutoUpdate && SUPPORTS.update) IPC.emit('update')
if (SUPPORTS.isAndroid) {
// Back button support
let backButtonPressTimeout;
window.Capacitor.Plugins.App.addListener("backButton", () => {
if (page === "home" && $view === null && $rss === null) {
if (backButtonPressTimeout) {
clearTimeout(backButtonPressTimeout);
window.Capacitor.Plugins.App.exitApp();
} else {
toast.warning("Press again to exit", { duration: 1000 });
backButtonPressTimeout = setTimeout(() => {
backButtonPressTimeout = null;
}, 1000);
}
} else {
if (document.fullscreenElement) document.exitFullscreen();
page = "home";
$rss = null;
$view = null;
}
});
}
});
onDestroy(() => {
if (SUPPORTS.isAndroid) window.Capacitor.Plugins.App.removeAllListeners();
});
function closeMiniplayer() {