Skip to content

Commit

Permalink
Merge pull request #52088 from c3024/use-platform-specific-mute-setting
Browse files Browse the repository at this point in the history
Use platform specific mute setting for sounds
  • Loading branch information
tgolen authored Nov 6, 2024
2 parents 0f03601 + 070eebc commit 9980299
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
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(shouldMobileWebBeDistinctFromWeb = false): Platform {
if (shouldMobileWebBeDistinctFromWeb && 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 @@ -75,7 +76,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 @@ -494,7 +497,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 @@ -540,7 +543,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

0 comments on commit 9980299

Please sign in to comment.