diff --git a/ts/background.preload.ts b/ts/background.preload.ts index 9d5ac8593e..af1c741f56 100644 --- a/ts/background.preload.ts +++ b/ts/background.preload.ts @@ -271,7 +271,7 @@ import { MessageModel } from './models/messages.preload.js'; import { waitForEvent } from './shims/events.dom.js'; import { sendSyncRequests } from './textsecure/syncRequests.preload.js'; import { handleServerAlerts } from './util/handleServerAlerts.preload.js'; -import { isLocalBackupsEnabled } from './util/isLocalBackupsEnabled.dom.js'; +import { isLocalBackupsEnabled } from './util/isLocalBackupsEnabled.preload.js'; import { NavTab, SettingsPage, ProfileEditorPage } from './types/Nav.std.js'; import { initialize as initializeDonationService } from './services/donations.preload.js'; import { MessageRequestResponseSource } from './types/MessageRequestResponseEvent.std.js'; diff --git a/ts/services/backups/index.preload.ts b/ts/services/backups/index.preload.ts index e116634a76..4f997f8cd8 100644 --- a/ts/services/backups/index.preload.ts +++ b/ts/services/backups/index.preload.ts @@ -83,7 +83,7 @@ import { import { FileStream } from './util/FileStream.node.js'; import { ToastType } from '../../types/Toast.dom.js'; import { isAdhoc, isNightly } from '../../util/version.std.js'; -import { isLocalBackupsEnabled } from '../../util/isLocalBackupsEnabled.dom.js'; +import { isLocalBackupsEnabled } from '../../util/isLocalBackupsEnabled.preload.js'; import type { ValidateLocalBackupStructureResultType } from './util/localBackup.node.js'; import { writeLocalBackupMetadata, diff --git a/ts/state/smart/Preferences.preload.tsx b/ts/state/smart/Preferences.preload.tsx index a7c761667e..eb930c25f7 100644 --- a/ts/state/smart/Preferences.preload.tsx +++ b/ts/state/smart/Preferences.preload.tsx @@ -117,6 +117,7 @@ import type { SmartPreferencesEditChatFolderPageProps } from './PreferencesEditC import type { ExternalProps as SmartNotificationProfilesProps } from './PreferencesNotificationProfiles.preload.js'; import { useMegaphonesActions } from '../ducks/megaphones.preload.js'; import type { ZoomFactorType } from '../../types/StorageKeys.std.js'; +import { isLocalBackupsEnabled } from '../../util/isLocalBackupsEnabled.preload.js'; const DEFAULT_NOTIFICATION_SETTING = 'message'; @@ -578,9 +579,7 @@ export function SmartPreferences(): React.JSX.Element | null { Settings.isContentProtectionSupported(OS); const isContentProtectionNeeded = Settings.isContentProtectionNeeded(OS); - const backupLocalBackupsEnabled = isFeaturedEnabledSelector({ - betaKey: 'desktop.localBackups.beta', - prodKey: 'desktop.localBackups.prod', + const backupLocalBackupsEnabled = isLocalBackupsEnabled({ currentVersion: version, remoteConfig: items.remoteConfig, }); diff --git a/ts/util/isLocalBackupsEnabled.dom.ts b/ts/util/isLocalBackupsEnabled.dom.ts deleted file mode 100644 index 7ed7c5f9d8..0000000000 --- a/ts/util/isLocalBackupsEnabled.dom.ts +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2025 Signal Messenger, LLC -// SPDX-License-Identifier: AGPL-3.0-only - -import { isFeaturedEnabledNoRedux } from './isFeatureEnabled.dom.js'; - -export function isLocalBackupsEnabled(): boolean { - return isFeaturedEnabledNoRedux({ - betaKey: 'desktop.localBackups.beta', - prodKey: 'desktop.localBackups.prod', - }); -} diff --git a/ts/util/isLocalBackupsEnabled.preload.ts b/ts/util/isLocalBackupsEnabled.preload.ts new file mode 100644 index 0000000000..dbe09081d4 --- /dev/null +++ b/ts/util/isLocalBackupsEnabled.preload.ts @@ -0,0 +1,44 @@ +// Copyright 2025 Signal Messenger, LLC +// SPDX-License-Identifier: AGPL-3.0-only + +import type { ReadonlyObjectDeep } from 'type-fest/source/readonly-deep.js'; +import { isEnabled, type ConfigMapType } from '../RemoteConfig.dom.js'; +import { + isFeaturedEnabledNoRedux, + isFeaturedEnabledSelector, +} from './isFeatureEnabled.dom.js'; +import { itemStorage } from '../textsecure/Storage.preload.js'; +import { isNightly } from './version.std.js'; +import { isTestOrMockEnvironment } from '../environment.std.js'; + +const IOS_USER_AGENT = 'OWI'; + +export function isLocalBackupsEnabled(reduxArgs?: { + currentVersion: string; + remoteConfig: ReadonlyObjectDeep | undefined; +}): boolean { + // This is a temporary guard until iOS supports importing local backups + // Android no longer sends its OWA agent string, so we have to rely on iOS + if ( + itemStorage.get('userAgent') === IOS_USER_AGENT && + !isNightly(window.getVersion()) && + !isTestOrMockEnvironment() && + !isEnabled('desktop.internalUser', reduxArgs?.remoteConfig) + ) { + return false; + } + + if (reduxArgs) { + return isFeaturedEnabledSelector({ + currentVersion: reduxArgs.currentVersion, + remoteConfig: reduxArgs.remoteConfig, + betaKey: 'desktop.localBackups.beta', + prodKey: 'desktop.localBackups.prod', + }); + } + + return isFeaturedEnabledNoRedux({ + betaKey: 'desktop.localBackups.beta', + prodKey: 'desktop.localBackups.prod', + }); +}