Prompt before closing SlimeVR when trackers are still connected (#862)

This commit is contained in:
Éric Bonin authored and GitHub committed 2023-11-02 23:46:28 -03:00
1 parent 871ffa5571
commit 1fb32e8458
5 files changed
+119 -4

No files matched your search

+11
View File
@@ -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 ->
+27 -4
View File
@@ -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<string | null>(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({
</div>
<div
className="flex items-center justify-center hover:bg-background-60 rounded-full w-7 h-7"
onClick={async () => {
await invoke('update_window_state');
getCurrent().close();
onClick={() => {
if (
config?.connectedTrackersWarning &&
connectedIMUTrackers.length > 0
) {
setConnectedTrackerWarning(true);
} else {
closeApp();
}
}}
>
<CloseIcon></CloseIcon>
@@ -214,6 +232,11 @@ export function TopBar({
</div>
)}
</div>
<TrackersStillOnModal
isOpen={showConnectedTrackersWarning}
accept={() => closeApp()}
cancel={() => setConnectedTrackerWarning(false)}
></TrackersStillOnModal>
</>
);
}
@@ -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 (
<BaseModal isOpen={isOpen} onRequestClose={cancel}>
<div className="flex flex-col gap-3">
<>
<div className="flex flex-col items-center gap-3 fill-accent-background-20">
<div className="flex flex-col items-center gap-2">
<Typography variant="main-title">
{l10n.getString('trackers_still_on-modal-title')}
</Typography>
<Typography variant="standard">
{l10n.getString('trackers_still_on-modal-description')}
</Typography>
</div>
</div>
<Button variant="primary" onClick={accept}>
{l10n.getString('trackers_still_on-modal-confirm')}
</Button>
<Button variant="tertiary" onClick={cancel}>
{l10n.getString('trackers_still_on-modal-cancel')}
</Button>
</>
</div>
</BaseModal>
);
}
@@ -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}
/>
</div>
<Typography bold>
{l10n.getString(
'settings-general-interface-connected_trackers_warning'
)}
</Typography>
<div className="flex flex-col pt-1 pb-2">
<Typography color="secondary">
{l10n.getString(
'settings-general-interface-connected_trackers_warning-description'
)}
</Typography>
</div>
<div className="grid sm:grid-cols-2 pb-4">
<CheckBox
control={control}
outlined
name="notifications.connectedTrackersWarning"
label={l10n.getString(
'settings-general-interface-connected_trackers_warning-label'
)}
/>
</div>
</>
</SettingsPagePaneLayout>
+2
View File
@@ -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'],