Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ The map behind the dashboard, the layout editor, the offline view, the HV batter
- **Read-only API tokens** -- Make a token under Settings > Data & API > API tokens and let a script, a dashboard or a watch read what the app shows, without signing in. A token can only read: it cannot send commands or change anything, and the full data export, the logs and the diagnostics stay with a signed-in session.
- **Home Assistant** -- Your car appears in Home Assistant automatically through MQTT discovery, sharing GarageStack's broker and MG session instead of needing a second integration. GarageStack adds sensors of its own to the car: the APK and its days left, open recalls, the maintenance due next and the last trip. See [`HOME_ASSISTANT.md`](documentation/HOME_ASSISTANT.md).
- **Progressive Web App (PWA)** -- Installable on mobile or desktop for a native app-like experience, complete with a home screen icon and push notification support. Where the browser allows it, GarageStack offers to install itself, and the offer can be turned down for good. It also opens without a connection, in an underground car park or away from home without your VPN: every page then shows what that device last loaded (the dashboard, statistics, the map with its routes, the trip log, charge history, maintenance and climate schedules) and says so and from when, the buttons that need the server (commands, editing, the log viewer) are hidden until it can be reached again, and the directions dialog still offers the coordinates and a `geo:` link for a map app with offline maps. The maps keep their streets too: the app keeps the map tiles it has shown (up to about 150 raster tiles and 400 basemap files, for a month), so the areas you looked at with a signal are there offline. It never downloads areas you have not looked at, which OpenStreetMap's tile policy forbids. The saved pages and the kept tiles are forgotten on signing out. Installing and push need HTTPS, see [HTTPS](#https).
- **Swipe for the menu** -- On a phone, **Settings > General > This device** can switch on swiping the menu: a swipe to the right that starts a little in from the left edge of the screen opens it, and a swipe to the left closes it. It starts clear of the very edge, which a phone's own back gesture takes, so the two are never mixed up. It is off until a device switches it on, stays with that device, and is left out of the map pages and of anything that pans or scrolls sideways under the finger, such as a map, a chart or a row of chips.
- **Charging stations** -- Overlay nearby EV charging stations on the map, sourced from the [Open Charge Map](https://openchargemap.org) database. Station data is cached in the database for 7 days; on page load the map immediately shows all stations within 100 km of your car that are already cached. Markers show operational status; clicking a marker displays the station name, operator, address, and available connector types with power ratings. Requires a free OCM API key (`OPENCHARGEMAP_API_KEY`). Unlike fuel stations and service areas, charging station tiles are loaded on demand as you browse the map and are not pre-populated by the background Worker.
- **Fuel stations** -- Overlay nearby petrol and diesel stations on the map (HEV and PHEV only; not shown for BEV). Sourced from OpenStreetMap via the Overpass API -- no API key required. POI data is cached in the database for 7 days and pre-populated by the Worker for a 100 km radius around the car's last known position so the overlay is instant on first view.
- **Motorway service areas** -- Overlay motorway service areas and rest stops on the map (all vehicle types). Same DB-backed cache and Worker pre-cache as fuel stations; useful for BEV drivers who often find fast chargers at service areas.
Expand Down
17 changes: 17 additions & 0 deletions frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import { useScreenWakeLock } from '@/composables/useScreenWakeLock'
import { usePhoneGpsRecorder } from '@/composables/usePhoneGpsRecorder'
import { useRelativeTime } from '@/composables/useRelativeTime'
import { useEscapeKey } from '@/composables/useEscapeKey'
import { useDrawerSwipe, useEdgeSwipeOffered } from '@/composables/useDrawerSwipe'
import { useUiSettingsStore } from '@/stores/settingsUi'
import { formatDateTime, formatTime } from '@/utils/format'
import { mayPlugIn } from '@/utils/vehicleType'

Expand Down Expand Up @@ -227,6 +229,21 @@ function closeMenuOnLink(event: MouseEvent) {
if (event.target instanceof Element && event.target.closest('a')) closeMenu()
}

// A swipe from the left edge opens the mobile menu and a swipe to the left closes it, where this
// device has asked for that (Settings > General > This device). The two pages that are a map from
// edge to edge pan it on any touch, so there the swipe does not open the menu; an open menu
// still closes by swipe wherever it is.
const uiSettings = useUiSettingsStore()
const edgeSwipeOffered = useEdgeSwipeOffered()
useDrawerSwipe({
enabled: () => uiSettings.edgeSwipeMenu && edgeSwipeOffered.value && !isLoginRoute.value,
blocksOpening: () => route.name === 'map' || route.name === 'tripEdit',
isOpen: () => menuOpen.value,
open: () => (menuOpen.value = true),
close: closeMenu,
closeFrom: '.sidebar, .sidebar-backdrop',
})

// Escape closes the mobile menu and puts focus back on the button that opened it.
const hamburger = ref<HTMLButtonElement | null>(null)
useEscapeKey(
Expand Down
117 changes: 117 additions & 0 deletions frontend/src/__tests__/App.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import { setBrowserOnline } from '@/composables/__tests__/connectionStub'

const session = vi.hoisted(() => ({ authenticated: false }))

// Only what the app reads of this device's settings: whether swiping the menu is switched on.
const ui = vi.hoisted(() => ({ edgeSwipeMenu: false }))

vi.mock('@/stores/settingsUi', () => ({ useUiSettingsStore: () => ui }))

vi.mock('@/stores/auth', () => ({
useAuthStore: () => ({
isAuthenticated: session.authenticated,
Expand Down Expand Up @@ -174,6 +179,118 @@ describe('App mobile menu', () => {
})
})

describe('App menu swipe', () => {
// Phone-sized, with a touchscreen: what the swipe is offered on.
function onATouchPhone() {
vi.stubGlobal('matchMedia', (query: string) => ({
matches: query === '(width <= 767px)' || query === '(any-pointer: coarse)',
media: query,
addEventListener: () => {},
removeEventListener: () => {},
}))
}

async function mountClosed(path = '/') {
const router = createRouter({
history: createMemoryHistory(),
routes: [
{ path: '/', component: Page },
{ path: '/map', name: 'map', component: Page },
{ path: '/login', name: 'login', component: Page },
],
})
await router.push(path)
return mount(App, {
attachTo: document.body,
global: {
plugins: [i18n, router],
stubs: {
FontAwesomeIcon: true,
AppFooter: true,
NotificationPanel: true,
DemoBanner: true,
PwaInstallModal: true,
},
},
})
}

function swipe(target: Element, x: number, dx: number) {
const init = { bubbles: true, isPrimary: true, pointerType: 'touch', pointerId: 1 }
target.dispatchEvent(new PointerEvent('pointerdown', { ...init, clientX: x, clientY: 300 }))
target.dispatchEvent(
new PointerEvent('pointermove', { ...init, clientX: x + dx, clientY: 300 }),
)
}

afterEach(() => {
vi.unstubAllGlobals()
ui.edgeSwipeMenu = false
document.body.innerHTML = ''
})

it('opens the menu for a swipe from the left edge, and closes it for one back', async () => {
onATouchPhone()
ui.edgeSwipeMenu = true
const wrapper = await mountClosed()
expect(wrapper.find('.sidebar--open').exists()).toBe(false)

swipe(wrapper.get('.app-body').element, 40, 100)
await flushPromises()
expect(wrapper.find('.sidebar--open').exists()).toBe(true)
expect(wrapper.get('.hamburger').attributes('aria-expanded')).toBe('true')

swipe(wrapper.get('.sidebar').element, 200, -100)
await flushPromises()
expect(wrapper.find('.sidebar--open').exists()).toBe(false)
})

it('leaves the menu shut while this device has not asked for the swipe', async () => {
onATouchPhone()
const wrapper = await mountClosed()

swipe(wrapper.get('.app-body').element, 40, 100)
await flushPromises()

expect(wrapper.find('.sidebar--open').exists()).toBe(false)
})

it('leaves the menu shut on a screen without a touchscreen, whatever the setting says', async () => {
ui.edgeSwipeMenu = true
const wrapper = await mountClosed()

swipe(wrapper.get('.app-body').element, 40, 100)
await flushPromises()

expect(wrapper.find('.sidebar--open').exists()).toBe(false)
})

// The map pans on any touch, so on its page the swipe does not open the menu.
it('does not open the menu on the map page', async () => {
onATouchPhone()
ui.edgeSwipeMenu = true
const wrapper = await mountClosed('/map')

swipe(wrapper.get('.app-body').element, 40, 100)
await flushPromises()

expect(wrapper.find('.sidebar--open').exists()).toBe(false)
})

it('still closes a menu opened by its button on the map page', async () => {
onATouchPhone()
ui.edgeSwipeMenu = true
const wrapper = await mountClosed('/map')
await wrapper.get('.hamburger').trigger('click')
expect(wrapper.find('.sidebar--open').exists()).toBe(true)

swipe(wrapper.get('.sidebar').element, 200, -100)
await flushPromises()

expect(wrapper.find('.sidebar--open').exists()).toBe(false)
})
})

describe('App top bar', () => {
// On a phone the page's own buttons and then Settings land in the slots; with the bell they form
// one evenly spaced group, the slots coming first so the bell stays at the far end.
Expand Down
19 changes: 15 additions & 4 deletions frontend/src/components/settings/DeviceSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,33 @@ import { useI18n } from 'vue-i18n'
import { useUiSettingsStore } from '@/stores/settingsUi'
import { useKeepScreenOnOffered } from '@/composables/useScreenWakeLock'
import { usePhoneGpsOffered, usePhoneGpsStatus } from '@/composables/usePhoneGpsRecorder'
import { useEdgeSwipeOffered } from '@/composables/useDrawerSwipe'
import SettingsToggle from '../SettingsToggle.vue'
import SettingsSection from './SettingsSection.vue'

const { t } = useI18n()
const settings = useUiSettingsStore()
const screenOffered = useKeepScreenOnOffered()
const gpsOffered = usePhoneGpsOffered()
const edgeSwipeOffered = useEdgeSwipeOffered()
const { denied, recording } = usePhoneGpsStatus()
</script>

<template>
<!-- Only in the installed app: a browser tab dims like any other page, and only an app kept
on screen can follow the phone's GPS. Both stay with this device. -->
<SettingsSection v-if="screenOffered" :title="t('settings.device.title')">
<!-- What suits one device. Keeping the screen on and the phone's GPS are for the installed app: a
browser tab dims like any other page, and only an app kept on screen can follow the phone's
GPS. Swiping the menu open is for any phone with a touchscreen. All stay with this device. -->
<SettingsSection v-if="screenOffered || edgeSwipeOffered" :title="t('settings.device.title')">
<div class="settings-toggles">
<SettingsToggle
v-if="screenOffered"
v-model="settings.keepScreenOn"
:label="t('settings.keepScreenOn.label')"
:desc="t('settings.keepScreenOn.desc')"
input-id="footer-toggle-keep-screen-on"
/>
<SettingsToggle
v-if="gpsOffered"
v-if="screenOffered && gpsOffered"
v-model="settings.recordPhoneGps"
:label="t('settings.phoneGps.label')"
:desc="t('settings.phoneGps.desc')"
Expand All @@ -44,6 +48,13 @@ const { denied, recording } = usePhoneGpsStatus()
</p>
</template>
</SettingsToggle>
<SettingsToggle
v-if="edgeSwipeOffered"
v-model="settings.edgeSwipeMenu"
:label="t('settings.edgeSwipeMenu.label')"
:desc="t('settings.edgeSwipeMenu.desc')"
input-id="footer-toggle-edge-swipe-menu"
/>
</div>
</SettingsSection>
</template>
49 changes: 49 additions & 0 deletions frontend/src/components/settings/__tests__/SettingsModal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,55 @@ describe('SettingsModal appearance', () => {
expect(panel(wrapper, 'general').find('#footer-toggle-record-phone-gps').exists()).toBe(false)
})

// A phone-sized screen with a touchscreen, in the browser or in the installed app.
function runOnPhone(installed: boolean, touch = true) {
vi.stubGlobal('matchMedia', (query: string) => ({
matches:
query === '(width <= 767px)' ||
(touch && query === '(any-pointer: coarse)') ||
(installed && query === '(display-mode: standalone)'),
addEventListener: () => {},
removeEventListener: () => {},
}))
}

it('offers swiping the menu on a phone in a browser tab, where the installed-app settings are not', async () => {
runOnPhone(false)
const { wrapper } = await render()
const general = panel(wrapper, 'general')
const toggle = general.get('#footer-toggle-edge-swipe-menu')
expect(general.text()).toContain(en.settings.edgeSwipeMenu.label)
expect(general.text()).toContain(en.settings.device.title)
expect(general.find('#footer-toggle-keep-screen-on').exists()).toBe(false)

expect((toggle.element as HTMLInputElement).checked).toBe(false)
await toggle.setValue(true)
expect(useUiSettingsStore(pinia).edgeSwipeMenu).toBe(true)
})

it('offers it next to the installed app settings on a phone', async () => {
runOnPhone(true)
Object.defineProperty(navigator, 'wakeLock', {
configurable: true,
value: { request: vi.fn<() => Promise<never>>() },
})
const { wrapper } = await render()
const general = panel(wrapper, 'general')

expect(general.find('#footer-toggle-edge-swipe-menu').exists()).toBe(true)
expect(general.find('#footer-toggle-keep-screen-on').exists()).toBe(true)
})

// A narrow desktop window has no finger to swipe with, and nothing else for this device either.
it('is not offered without a touchscreen', async () => {
runOnPhone(false, false)
const { wrapper } = await render()
const general = panel(wrapper, 'general')

expect(general.find('#footer-toggle-edge-swipe-menu').exists()).toBe(false)
expect(general.text()).not.toContain(en.settings.device.title)
})

it('offers recording GPS only once the screen is kept on', async () => {
runAs(true)
const { wrapper } = await render()
Expand Down
Loading
Loading