diff --git a/src/stores/controller.ts b/src/stores/controller.ts index c9454594b..ce4d0237b 100644 --- a/src/stores/controller.ts +++ b/src/stores/controller.ts @@ -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' @@ -28,6 +29,7 @@ import { } from '@/types/joystick' import { useAlertStore } from './alert' +import { useMainVehicleStore } from './mainVehicle' export type controllerUpdateCallback = ( state: JoystickState, @@ -42,6 +44,8 @@ const cockpitStdMappingsKey = 'cockpit-standard-mappings-v2' export const useControllerStore = defineStore('controller', () => { const alertStore = useAlertStore() + const vehicleStore = useMainVehicleStore() + const joysticks = ref>(new Map()) const updateCallbacks = ref([]) const protocolMappings = useBlueOsStorage(protocolMappingsKey, cockpitStandardToProtocols) @@ -162,6 +166,17 @@ 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.') @@ -169,6 +184,14 @@ export const useControllerStore = defineStore('controller', () => { } }) + const showElectronDesktopNotification = (message: string): void => { + const notification = new Notification({ + title: 'Cockpit warning!', + body: message, + }) + notification.show() + } + const { showDialog } = useInteractionDialog() const processJoystickStateEvent = (event: JoystickEvent): void => {