Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use platform specific mute setting for sounds #52088

Merged
merged 7 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/libs/Sound/BaseSound.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import Onyx from 'react-native-onyx';
import getPlatform from '@libs/getPlatform';
import ONYXKEYS from '@src/ONYXKEYS';

let isMuted = false;

Onyx.connect({
key: ONYXKEYS.USER,
callback: (val) => (isMuted = !!val?.isMutedAllSounds),
key: ONYXKEYS.NVP_MUTED_PLATFORMS,
callback: (val) => {
const platform = getPlatform(true);
isMuted = !!val?.[platform];
},
});

const SOUNDS = {
Expand Down
6 changes: 5 additions & 1 deletion src/libs/getPlatform/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import * as Browser from '@libs/Browser';
import CONST from '@src/CONST';
import type Platform from './types';

export default function getPlatform(): Platform {
export default function getPlatform(treatMWebDifferently = false): Platform {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind renaming this param to shouldMobileWebBeDistinctFromWeb?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. And I was thinking for a smaller name because treatMWebDifferently was already mouthful.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable naming is one of the hardest things! Luckily code-minifiers usually render the name length insignificant in the end, so I prefer more clarity. Thanks!

if (treatMWebDifferently && Browser.isMobile()) {
return CONST.PLATFORM.MOBILEWEB;
}
return CONST.PLATFORM.WEB;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import useThemeStyles from '@hooks/useThemeStyles';
import * as FileUtils from '@libs/fileDownload/FileUtils';
import getPhotoSource from '@libs/fileDownload/getPhotoSource';
import getCurrentPosition from '@libs/getCurrentPosition';
import getPlatform from '@libs/getPlatform';
import * as IOUUtils from '@libs/IOUUtils';
import Log from '@libs/Log';
import Navigation from '@libs/Navigation/Navigation';
Expand Down Expand Up @@ -74,7 +75,9 @@ function IOURequestStepScan({
const policy = usePolicy(report?.policyID);
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);
const [skipConfirmation] = useOnyx(`${ONYXKEYS.COLLECTION.SKIP_CONFIRMATION}${transactionID ?? -1}`);
const [user] = useOnyx(ONYXKEYS.USER);
const platform = getPlatform(true);
const [mutedPlatforms = {}] = useOnyx(ONYXKEYS.NVP_MUTED_PLATFORMS);
const isPlatformMuted = mutedPlatforms[platform];
const [cameraPermissionStatus, setCameraPermissionStatus] = useState<string | null>(null);
const [didCapturePhoto, setDidCapturePhoto] = useState(false);
const [isLoadingReceipt, setIsLoadingReceipt] = useState(false);
Expand Down Expand Up @@ -489,7 +492,7 @@ function IOURequestStepScan({
camera?.current
?.takePhoto({
flash: flash && hasFlash ? 'on' : 'off',
enableShutterSound: !user?.isMutedAllSounds,
enableShutterSound: !isPlatformMuted,
})
.then((photo: PhotoFile) => {
// Store the receipt on the transaction object in Onyx
Expand Down Expand Up @@ -535,7 +538,7 @@ function IOURequestStepScan({
didCapturePhoto,
flash,
hasFlash,
user?.isMutedAllSounds,
isPlatformMuted,
translate,
transactionID,
isEditing,
Expand Down
3 changes: 1 addition & 2 deletions src/pages/settings/Preferences/PreferencesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import * as Browser from '@libs/Browser';
import getPlatform from '@libs/getPlatform';
import LocaleUtils from '@libs/LocaleUtils';
import Navigation from '@libs/Navigation/Navigation';
Expand All @@ -25,7 +24,7 @@ import ROUTES from '@src/ROUTES';
function PreferencesPage() {
const [priorityMode] = useOnyx(ONYXKEYS.NVP_PRIORITY_MODE);

const platform = Browser.isMobile() ? CONST.PLATFORM.MOBILEWEB : getPlatform();
const platform = getPlatform(true);
const [mutedPlatforms = {}] = useOnyx(ONYXKEYS.NVP_MUTED_PLATFORMS);
const isPlatformMuted = mutedPlatforms[platform];
const [user] = useOnyx(ONYXKEYS.USER);
Expand Down
3 changes: 0 additions & 3 deletions src/types/onyx/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ type User = {
/** Whether we should use the staging version of the secure API server */
shouldUseStagingServer?: boolean;

/** Whether user muted all sounds in application */
isMutedAllSounds?: boolean;

/** Is the user account validated? */
validated: boolean;

Expand Down
Loading