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 2, 2024
1 parent 6ceade7 commit 831e8ab
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/stores/controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useDocumentVisibility } from '@vueuse/core'
import { Notification } from 'electron'
import { saveAs } from 'file-saver'
import { defineStore } from 'pinia'
import { v4 as uuid4 } from 'uuid'
Expand Down Expand Up @@ -28,6 +29,7 @@ import {
} from '@/types/joystick'

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

export type controllerUpdateCallback = (
state: JoystickState,
Expand All @@ -42,6 +44,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,13 +166,32 @@ export const useControllerStore = defineStore('controller', () => {

if (value === 'hidden') {
console.warn('Window/tab hidden. Disabling joystick forwarding.')
if (vehicleStore.isArmed) {
alertStore.pushAlert(
new Alert(
AlertLevel.Warning,
'Warning: Vehicle armed and Cockpit minimized. Joystick inputs are stopped. Ensure vehicle safety.'
)
)
showElectronDesktopNotification(
'Vehicle armed and Cockpit minimized. Joystick inputs are stopped. Ensure vehicle safety.'
)
}
enableForwarding.value = false
} else {
console.info('Window/tab visible. Enabling joystick forwarding.')
enableForwarding.value = true
}
})

const showElectronDesktopNotification = (message: string): void => {
const notification = new Notification({
title: 'Cockpit warning!',
body: message,
})
notification.show()
}

const { showDialog } = useInteractionDialog()

const processJoystickStateEvent = (event: JoystickEvent): void => {
Expand Down

0 comments on commit 831e8ab

Please sign in to comment.