Skip to content

Commit

Permalink
Main vehicle: Alert when Cockpit is minimized while vehicle is still …
Browse files Browse the repository at this point in the history
…armed

Signed-off-by: Arturo Manzoli <[email protected]>
  • Loading branch information
ArturoManzoli committed Oct 7, 2024
1 parent dfe3941 commit bc85ef8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/stores/alert.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { ipcRenderer } from 'electron'
import { defineStore } from 'pinia'
import { computed, reactive, watch } from 'vue'

import { useBlueOsStorage } from '@/composables/settingsSyncer'
import { isElectron } from '@/libs/utils'

import { Alert, AlertLevel } from '../types/alert'

Expand Down Expand Up @@ -138,6 +140,9 @@ export const useAlertStore = defineStore('alert', () => {
watch(alerts, () => {
const lastAlert = alerts.slice(-1)[0]
const alertLevelEnabled = enabledAlertLevels.value.find((enabledAlert) => enabledAlert.level === lastAlert.level)
if (lastAlert.level === AlertLevel.Critical && alertLevelEnabled !== undefined && alertLevelEnabled.enabled) {
speak(lastAlert.message)
}
if (
!enableVoiceAlerts.value ||
((alertLevelEnabled === undefined || !alertLevelEnabled.enabled) && !lastAlert.message.startsWith('#'))
Expand Down
8 changes: 8 additions & 0 deletions src/stores/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
} from '@/types/joystick'

import { useAlertStore } from './alert'
import { useMainVehicleStore } from './mainVehicle'

export type controllerUpdateCallback = (
state: JoystickState,
Expand All @@ -42,6 +43,8 @@ const cockpitStdMappingsKey = 'cockpit-standard-mappings-v2'

export const useControllerStore = defineStore('controller', () => {
const alertStore = useAlertStore()
const vehicleStore = useMainVehicleStore()

const joysticks = ref<Map<number, Joystick>>(new Map())
const updateCallbacks = ref<controllerUpdateCallback[]>([])
const protocolMappings = useBlueOsStorage(protocolMappingsKey, cockpitStandardToProtocols)
Expand Down Expand Up @@ -162,6 +165,11 @@ export const useControllerStore = defineStore('controller', () => {

if (value === 'hidden') {
console.warn('Window/tab hidden. Disabling joystick forwarding.')
if (vehicleStore.isArmed) {
const criticalMessage =
'Critical: Cockpit minimized while vehicle is armed. Joystick inputs will not work. Ensure vehicle safety.'
alertStore.pushAlert(new Alert(AlertLevel.Critical, criticalMessage))
}
enableForwarding.value = false
} else {
console.info('Window/tab visible. Enabling joystick forwarding.')
Expand Down
26 changes: 20 additions & 6 deletions src/views/ConfigurationAlertsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,24 @@
class="flex flex-col justify-around align-start ml-5 max-h-[85vh] overflow-y-auto"
:class="interfaceStore.isOnSmallScreen ? 'max-w-[70vw]' : 'max-w-[40vw]'"
>
<v-switch
v-model="alertStore.enableVoiceAlerts"
label="Enable voice alerts"
color="white"
class="mt-2 -mb-2 ml-3"
/>
<div class="flex w-full justify-between pr-10">
<v-switch
v-model="alertStore.enableVoiceAlerts"
label="Enable voice alerts"
color="white"
class="mt-2 -mb-2 ml-3"
/>
<v-checkbox
v-model="alertStore.enabledAlertLevels.find((level) => level.level === AlertLevel.Critical)!.enabled"
v-tooltip="
'Critical system alerts work separately from your voice alert settings. These alerts are rare but really important, so we recommend keeping them on.'
"
label="Critical system alerts"
hide-details
color="white"
class="mt-1"
/>
</div>
<ExpansiblePanel :is-expanded="!interfaceStore.isOnPhoneScreen">
<template #title> Enable voice on specific alert levels:</template>
<template #info
Expand All @@ -26,6 +38,7 @@
class="mx-2 min-w-[100px]"
>
<v-checkbox
v-if="enabledLevel.level !== AlertLevel.Critical"
v-model="enabledLevel.enabled"
:label="capitalize(enabledLevel.level)"
hide-details
Expand Down Expand Up @@ -55,6 +68,7 @@ import Dropdown from '@/components/Dropdown.vue'
import ExpansiblePanel from '@/components/ExpansiblePanel.vue'
import { useAlertStore } from '@/stores/alert'
import { useAppInterfaceStore } from '@/stores/appInterface'
import { AlertLevel } from '@/types/alert'
import BaseConfigurationView from './BaseConfigurationView.vue'
Expand Down

0 comments on commit bc85ef8

Please sign in to comment.