Features:
- Add preferences for WakeLock and AutoRefresh - Add WakeLock and AutoRefresh to Board - Attempt adding transitions to Board elements UI: - Add '3D' styling to preference toggles
This commit is contained in:
@@ -15,7 +15,7 @@
|
|||||||
<BaseCard header={'Nearby Stations'}>
|
<BaseCard header={'Nearby Stations'}>
|
||||||
<div class="card-content">
|
<div class="card-content">
|
||||||
{#if !prefs.current.NearToMe}
|
{#if !prefs.current.NearToMe}
|
||||||
<Button onclick={() => prefs.toggleLocation(true)}>Enable Location</Button>
|
<Button onclick={() => prefs.toggleNearToMe(true)}>Enable Location</Button>
|
||||||
{:else if nearestStationsState.error && nearestStationsState.list.length === 0}
|
{:else if nearestStationsState.error && nearestStationsState.list.length === 0}
|
||||||
<p class="msg">{nearestStationsState.error}</p>
|
<p class="msg">{nearestStationsState.error}</p>
|
||||||
{:else if nearestStationsState.loading && nearestStationsState.list.length === 0}
|
{:else if nearestStationsState.loading && nearestStationsState.list.length === 0}
|
||||||
|
|||||||
@@ -66,6 +66,7 @@
|
|||||||
border-radius: 1rem;
|
border-radius: 1rem;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
transition: background-color 0.2s ease;
|
transition: background-color 0.2s ease;
|
||||||
|
box-shadow: inset 0 1px 3px rgba(0,0,0,0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
.toggle-thumb {
|
.toggle-thumb {
|
||||||
@@ -77,8 +78,8 @@
|
|||||||
background-color: var(--color-accent);
|
background-color: var(--color-accent);
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
transition: transform 0.2s ease;
|
transition: transform 0.2s ease;
|
||||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
|
||||||
filter: brightness(0.95);
|
filter: brightness(1.45);
|
||||||
}
|
}
|
||||||
|
|
||||||
.toggle-input:checked + .toggle-track {
|
.toggle-input:checked + .toggle-track {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { ApiStationsBoard } from '@owlboard/owlboard-ts';
|
import type { ApiStationsBoard } from '@owlboard/owlboard-ts';
|
||||||
import { formatUkTime, estClass, delayClassFromTimePair } from '$lib/utils/time';
|
import { formatUkTime, estClass, delayClassFromTimePair } from '$lib/utils/time';
|
||||||
|
import { fade } from 'svelte/transition';
|
||||||
|
|
||||||
let { services }: { services: ApiStationsBoard.BoardService[] } = $props();
|
let { services }: { services: ApiStationsBoard.BoardService[] } = $props();
|
||||||
|
|
||||||
@@ -48,6 +49,8 @@
|
|||||||
{#each services as service (getRowKey(service))}
|
{#each services as service (getRowKey(service))}
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr
|
<tr
|
||||||
|
in:fade={{duration: 150, delay:150}}
|
||||||
|
out:fade={{duration:150}}
|
||||||
class="service-row"
|
class="service-row"
|
||||||
class:serviceCancelled={service.c}
|
class:serviceCancelled={service.c}
|
||||||
class:servicePass={service.wtp}
|
class:servicePass={service.wtp}
|
||||||
@@ -123,14 +126,14 @@
|
|||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
{#if service.o}
|
{#if service.o}
|
||||||
<tr class="toc-coach-row">
|
<tr class="toc-coach-row" in:fade={{ duration: 150, delay: 150 }} out:fade={{ duration: 150 }}>
|
||||||
<td colspan="8">
|
<td colspan="8">
|
||||||
{service.o}
|
{service.o}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{/if}
|
{/if}
|
||||||
{#if service.c && service.cr?.r}
|
{#if service.c && service.cr?.r}
|
||||||
<tr class="cancel-row">
|
<tr class="cancel-row" in:fade={{ duration: 150, delay: 150 }} out:fade={{ duration: 150 }}>
|
||||||
<td colspan="8">
|
<td colspan="8">
|
||||||
{service.cr.r}
|
{service.cr.r}
|
||||||
{#if service.cr.l}
|
{#if service.cr.l}
|
||||||
@@ -141,7 +144,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
{/if}
|
{/if}
|
||||||
{#if service.dr?.r}
|
{#if service.dr?.r}
|
||||||
<tr class="delay-row">
|
<tr class="delay-row" in:fade={{ duration: 150, delay: 150 }} out:fade={{ duration: 150 }}>
|
||||||
<td colspan="9">
|
<td colspan="9">
|
||||||
{service.dr.r}
|
{service.dr.r}
|
||||||
{#if service.dr.l}
|
{#if service.dr.l}
|
||||||
|
|||||||
@@ -3,13 +3,17 @@ import { browser } from '$app/environment';
|
|||||||
export interface Preferences {
|
export interface Preferences {
|
||||||
NearToMe: boolean;
|
NearToMe: boolean;
|
||||||
ShowPassingTrains: boolean;
|
ShowPassingTrains: boolean;
|
||||||
|
BoardWakeLock: boolean;
|
||||||
|
AutoRefresh: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const STORAGE_KEY = 'ob_pref';
|
const STORAGE_KEY = 'ob_pref';
|
||||||
|
|
||||||
const DEFAULT_PREFS: Preferences = {
|
const DEFAULT_PREFS: Preferences = {
|
||||||
NearToMe: false,
|
NearToMe: false,
|
||||||
ShowPassingTrains: true
|
ShowPassingTrains: true,
|
||||||
|
BoardWakeLock: true,
|
||||||
|
AutoRefresh: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
function loadPrefs(): Preferences {
|
function loadPrefs(): Preferences {
|
||||||
@@ -50,6 +54,14 @@ class PreferencesStore {
|
|||||||
toggleShowPassingTrains(enabled: boolean) {
|
toggleShowPassingTrains(enabled: boolean) {
|
||||||
this.current.ShowPassingTrains = enabled;
|
this.current.ShowPassingTrains = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toggleBoardWakeLock(enabled: boolean) {
|
||||||
|
this.current.BoardWakeLock = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
toggleAutoRefresh(enabled: boolean) {
|
||||||
|
this.current.AutoRefresh = enabled;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const prefs = new PreferencesStore();
|
export const prefs = new PreferencesStore();
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount, untrack } from 'svelte';
|
import { onMount, untrack } from 'svelte';
|
||||||
import { quickLinks } from '$lib/quick-links.svelte';
|
import { quickLinks } from '$lib/quick-links.svelte';
|
||||||
|
import { invalidateAll } from '$app/navigation';
|
||||||
import StationAlertCard from '$lib/components/ui/station-board/StationAlertCard.svelte';
|
import StationAlertCard from '$lib/components/ui/station-board/StationAlertCard.svelte';
|
||||||
|
|
||||||
import { formatUkDateTime, formatUkTime } from '$lib/utils/time';
|
import { formatUkDateTime, formatUkTime } from '$lib/utils/time';
|
||||||
@@ -8,6 +9,77 @@
|
|||||||
let { data } = $props();
|
let { data } = $props();
|
||||||
let now = $state(new Date());
|
let now = $state(new Date());
|
||||||
|
|
||||||
|
// Handle auto-refreshing & Wake-lock
|
||||||
|
$effect(() => {
|
||||||
|
let intervalId: number | undefined;
|
||||||
|
let wakeLock: WakeLockSentinel | null = null;
|
||||||
|
|
||||||
|
const requestWakeLock = async () => {
|
||||||
|
if ('wakeLock' in navigator && !wakeLock) {
|
||||||
|
try {
|
||||||
|
wakeLock = await navigator.wakeLock.request('screen');
|
||||||
|
console.log("Wake lock obtained");
|
||||||
|
} catch (error) {
|
||||||
|
console.warn("Wake lock request rejected: ", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const releaseWakeLock = async () => {
|
||||||
|
if (wakeLock) {
|
||||||
|
try {
|
||||||
|
await wakeLock.release();
|
||||||
|
console.log("Wake lock released");
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Wake lock release failed: ", error);
|
||||||
|
}
|
||||||
|
wakeLock = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const startPolling = async () => {
|
||||||
|
await requestWakeLock();
|
||||||
|
if (intervalId) return;
|
||||||
|
intervalId = window.setInterval(async () => {
|
||||||
|
try {
|
||||||
|
console.log("Invalidating data")
|
||||||
|
await invalidateAll();
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Background data fetch failed: ", error)
|
||||||
|
}
|
||||||
|
}, 61000);
|
||||||
|
console.log("Polling started")
|
||||||
|
};
|
||||||
|
|
||||||
|
const stopPolling = async () => {
|
||||||
|
if (intervalId) {
|
||||||
|
window.clearInterval(intervalId);
|
||||||
|
intervalId = undefined;
|
||||||
|
console.log("Polling ended")
|
||||||
|
}
|
||||||
|
await releaseWakeLock();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleVisibilityChange = () => {
|
||||||
|
if (document.hidden) {
|
||||||
|
stopPolling();
|
||||||
|
} else {
|
||||||
|
startPolling();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!document.hidden) {
|
||||||
|
startPolling();
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener('visibilitychange', handleVisibilityChange);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
stopPolling();
|
||||||
|
document.removeEventListener('visibilitychange', handleVisibilityChange);
|
||||||
|
};
|
||||||
|
})
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
const interval = setInterval(() => {
|
const interval = setInterval(() => {
|
||||||
now = new Date();
|
now = new Date();
|
||||||
@@ -16,18 +88,19 @@
|
|||||||
return () => clearInterval(interval);
|
return () => clearInterval(interval);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Update 'QuickLinks'
|
const currentBoardId = $derived(
|
||||||
$effect(() => {
|
data.BoardLocation ? (data.BoardLocation.c ?? data.BoardLocation.t) : null
|
||||||
if (data.BoardLocation) {
|
);
|
||||||
const id = data.BoardLocation?.c ?? data.BoardLocation?.t;
|
|
||||||
if (id) {
|
// Update 'QuickLinks' when currentBoardId changes
|
||||||
// Untrack, as we do not need to handle changes to quickLinks - this is WRITE_ONLY
|
$effect(() => {
|
||||||
|
if (currentBoardId) {
|
||||||
|
// Keep the execution and logs inside untrack to isolate dependencies completely
|
||||||
untrack(() => {
|
untrack(() => {
|
||||||
quickLinks.recordVisit(id);
|
quickLinks.recordVisit(currentBoardId);
|
||||||
console.log(`QuickLink visit recorded: ${JSON.stringify(data.BoardLocation)}`);
|
console.log(`QuickLink visit recorded: ${JSON.stringify(data.BoardLocation)}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Wake Lock API Handling
|
// Wake Lock API Handling
|
||||||
|
|||||||
@@ -23,6 +23,18 @@
|
|||||||
checked={prefs.current.ShowPassingTrains}
|
checked={prefs.current.ShowPassingTrains}
|
||||||
onchange={(checked) => prefs.toggleShowPassingTrains(checked)}
|
onchange={(checked) => prefs.toggleShowPassingTrains(checked)}
|
||||||
/>
|
/>
|
||||||
|
<Toggle
|
||||||
|
label={'Keep screen awake on live pages'}
|
||||||
|
id={'toggle-board-wake-lock'}
|
||||||
|
checked={prefs.current.BoardWakeLock}
|
||||||
|
onchange={(checked) => prefs.toggleBoardWakeLock(checked)}
|
||||||
|
/>
|
||||||
|
<Toggle
|
||||||
|
label={'Auto-refresh data'}
|
||||||
|
id={'toggle-auto-refresh'}
|
||||||
|
checked={prefs.current.AutoRefresh}
|
||||||
|
onchange={(checked) => prefs.toggleAutoRefresh(checked)}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</BaseCard>
|
</BaseCard>
|
||||||
|
|||||||
Reference in New Issue
Block a user