diff --git a/gui/public/i18n/en/translation.ftl b/gui/public/i18n/en/translation.ftl index 2376dd801..09feaf626 100644 --- a/gui/public/i18n/en/translation.ftl +++ b/gui/public/i18n/en/translation.ftl @@ -414,6 +414,9 @@ settings-general-interface-feedback_sound = Feedback sound settings-general-interface-feedback_sound-description = This option will play a sound when a reset is triggered. settings-general-interface-feedback_sound-label = Feedback sound settings-general-interface-feedback_sound-volume = Feedback sound volume +settings-general-interface-connected_trackers_warning = Connected trackers warning +settings-general-interface-connected_trackers_warning-description = This option will show a pop-up every time you try exiting SlimeVR while having one or more connected trackers. It reminds you to turn off your trackers when you are done to preserve battery life. +settings-general-interface-connected_trackers_warning-label = Connected trackers warning on SlimeVR exit ## Serial settings settings-serial = Serial Console @@ -838,6 +841,14 @@ onboarding-automatic_proportions-error_modal-confirm = Understood! ## Home home-no_trackers = No trackers detected or assigned +## Trackers Still On notification +trackers_still_on-modal-title = Trackers still on +trackers_still_on-modal-description = + One or more trackers are still on. + Do you still want to exit SlimeVR? +trackers_still_on-modal-confirm = Exit SlimeVR +trackers_still_on-modal-cancel = Hold on... + ## Status system status_system-StatusTrackerReset = It is recommended to perform a full reset as one or more trackers are unadjusted. status_system-StatusSteamVRDisconnected = { $type -> diff --git a/gui/src/components/TopBar.tsx b/gui/src/components/TopBar.tsx index fdbc65eab..9efd905bd 100644 --- a/gui/src/components/TopBar.tsx +++ b/gui/src/components/TopBar.tsx @@ -15,12 +15,15 @@ import { ProgressBar } from './commons/ProgressBar'; import { Typography } from './commons/Typography'; import { DownloadIcon } from './commons/icon/DownloadIcon'; import { open } from '@tauri-apps/plugin-shell'; -import { GH_REPO, VersionContext, DOCS_SITE } from '@/App'; +import { DOCS_SITE, GH_REPO, VersionContext } from '@/App'; import classNames from 'classnames'; import { QuestionIcon } from './commons/icon/QuestionIcon'; import { useBreakpoint, useIsTauri } from '@/hooks/breakpoint'; import { GearIcon } from './commons/icon/GearIcon'; import { invoke } from '@tauri-apps/api'; +import { useTrackers } from '@/hooks/tracker'; +import { TrackersStillOnModal } from './TrackersStillOnModal'; +import { useConfig } from '@/hooks/config'; export function VersionTag() { return ( @@ -49,11 +52,20 @@ export function TopBar({ const isTauri = useIsTauri(); const { isMobile } = useBreakpoint('mobile'); const { useRPCPacket, sendRPCPacket } = useWebsocketAPI(); + const { useConnectedIMUTrackers } = useTrackers(); + const connectedIMUTrackers = useConnectedIMUTrackers(); + const { config } = useConfig(); const version = useContext(VersionContext); const [localIp, setLocalIp] = useState(null); + const [showConnectedTrackersWarning, setConnectedTrackerWarning] = + useState(false); const doesMatchSettings = useMatch({ path: '/settings/*', }); + const closeApp = async () => { + await invoke('update_window_state'); + getCurrent().close(); + }; useEffect(() => { sendRPCPacket(RpcMessage.ServerInfosRequest, new ServerInfosRequestT()); @@ -197,9 +209,15 @@ export function TopBar({
{ - await invoke('update_window_state'); - getCurrent().close(); + onClick={() => { + if ( + config?.connectedTrackersWarning && + connectedIMUTrackers.length > 0 + ) { + setConnectedTrackerWarning(true); + } else { + closeApp(); + } }} > @@ -214,6 +232,11 @@ export function TopBar({
)} + closeApp()} + cancel={() => setConnectedTrackerWarning(false)} + > ); } diff --git a/gui/src/components/TrackersStillOnModal.tsx b/gui/src/components/TrackersStillOnModal.tsx new file mode 100644 index 000000000..769222fb7 --- /dev/null +++ b/gui/src/components/TrackersStillOnModal.tsx @@ -0,0 +1,51 @@ +import { useLocalization } from '@fluent/react'; +import { BaseModal } from './commons/BaseModal'; +import { Button } from './commons/Button'; +import { Typography } from './commons/Typography'; + +export function TrackersStillOnModal({ + isOpen = true, + cancel, + accept, +}: { + /** + * Is the parent/sibling component opened? + */ + isOpen: boolean; + /** + * Function to trigger when you still want to close the app + */ + accept: () => void; + /** + * Function to trigger when cancelling app close + */ + cancel?: () => void; +}) { + const { l10n } = useLocalization(); + + return ( + +
+ <> +
+
+ + {l10n.getString('trackers_still_on-modal-title')} + + + {l10n.getString('trackers_still_on-modal-description')} + +
+
+ + + + +
+
+ ); +} diff --git a/gui/src/components/settings/pages/InterfaceSettings.tsx b/gui/src/components/settings/pages/InterfaceSettings.tsx index 74089423a..47690f79f 100644 --- a/gui/src/components/settings/pages/InterfaceSettings.tsx +++ b/gui/src/components/settings/pages/InterfaceSettings.tsx @@ -28,6 +28,7 @@ interface InterfaceSettingsForm { watchNewDevices: boolean; feedbackSound: boolean; feedbackSoundVolume: number; + connectedTrackersWarning: boolean; }; } @@ -50,6 +51,9 @@ export function InterfaceSettings() { feedbackSound: config?.feedbackSound ?? defaultConfig.feedbackSound, feedbackSoundVolume: config?.feedbackSoundVolume ?? defaultConfig.feedbackSoundVolume, + connectedTrackersWarning: + config?.connectedTrackersWarning ?? + defaultConfig.connectedTrackersWarning, }, }, }); @@ -60,6 +64,7 @@ export function InterfaceSettings() { watchNewDevices: values.notifications.watchNewDevices, feedbackSound: values.notifications.feedbackSound, feedbackSoundVolume: values.notifications.feedbackSoundVolume, + connectedTrackersWarning: values.notifications.connectedTrackersWarning, theme: values.appearance.theme, fonts: values.appearance.fonts.split(','), textSize: values.appearance.textSize, @@ -151,6 +156,29 @@ export function InterfaceSettings() { step={0.1} /> + + + {l10n.getString( + 'settings-general-interface-connected_trackers_warning' + )} + +
+ + {l10n.getString( + 'settings-general-interface-connected_trackers_warning-description' + )} + +
+
+ +
diff --git a/gui/src/hooks/config.ts b/gui/src/hooks/config.ts index e4541a793..f6ff14c74 100644 --- a/gui/src/hooks/config.ts +++ b/gui/src/hooks/config.ts @@ -20,6 +20,7 @@ export interface Config { devSettings: DeveloperModeWidgetForm; feedbackSound: boolean; feedbackSoundVolume: number; + connectedTrackersWarning: boolean; theme: string; textSize: number; fonts: string[]; @@ -40,6 +41,7 @@ export const defaultConfig = { watchNewDevices: true, feedbackSound: true, feedbackSoundVolume: 0.5, + connectedTrackersWarning: true, theme: 'slime', textSize: 12, fonts: ['poppins'],