From 0c5be93a751366a353fdc6ec2b3519ead0fea7c0 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Wed, 30 Apr 2025 14:01:28 +0300 Subject: [PATCH] Move where the developer options are shown and store them in the app settings. --- .../Sources/Application/AppSettings.swift | 4 ++ .../SettingsScreenViewModel.swift | 12 +++- .../SettingsScreen/View/SettingsScreen.swift | 56 ++++++++++++------- ...sScreen.Bug-report-disabled-iPad-en-GB.png | 4 +- ...Screen.Bug-report-disabled-iPad-pseudo.png | 4 +- ...en.Bug-report-disabled-iPhone-16-en-GB.png | 4 +- ...n.Bug-report-disabled-iPhone-16-pseudo.png | 4 +- .../settingsScreen.Default-iPad-en-GB.png | 4 +- .../settingsScreen.Default-iPad-pseudo.png | 4 +- ...settingsScreen.Default-iPhone-16-en-GB.png | 4 +- ...ettingsScreen.Default-iPhone-16-pseudo.png | 4 +- 11 files changed, 65 insertions(+), 39 deletions(-) diff --git a/ElementX/Sources/Application/AppSettings.swift b/ElementX/Sources/Application/AppSettings.swift index d33da3139..7ac083e13 100644 --- a/ElementX/Sources/Application/AppSettings.swift +++ b/ElementX/Sources/Application/AppSettings.swift @@ -58,6 +58,7 @@ final class AppSettings { case enableOnlySignedDeviceIsolationMode case knockingEnabled case threadsEnabled + case developerOptionsEnabled } private static var suiteName: String = InfoPlistReader.main.appGroupIdentifier @@ -328,6 +329,9 @@ final class AppSettings { @UserPreference(key: UserDefaultsKeys.threadsEnabled, defaultValue: false, storageType: .userDefaults(store)) var threadsEnabled + @UserPreference(key: UserDefaultsKeys.threadsEnabled, defaultValue: isDevelopmentBuild, storageType: .userDefaults(store)) + var developerOptionsEnabled + #endif // MARK: - Shared diff --git a/ElementX/Sources/Screens/Settings/SettingsScreen/SettingsScreenViewModel.swift b/ElementX/Sources/Screens/Settings/SettingsScreen/SettingsScreenViewModel.swift index 3de4e676f..e1f3cd01d 100644 --- a/ElementX/Sources/Screens/Settings/SettingsScreen/SettingsScreenViewModel.swift +++ b/ElementX/Sources/Screens/Settings/SettingsScreen/SettingsScreenViewModel.swift @@ -11,6 +11,8 @@ import SwiftUI typealias SettingsScreenViewModelType = StateStoreViewModelV2 class SettingsScreenViewModel: SettingsScreenViewModelType, SettingsScreenViewModelProtocol { + private let appSettings: AppSettings + private var actionsSubject: PassthroughSubject = .init() var actions: AnyPublisher { @@ -18,14 +20,20 @@ class SettingsScreenViewModel: SettingsScreenViewModelType, SettingsScreenViewMo } init(userSession: UserSessionProtocol, appSettings: AppSettings, isBugReportServiceEnabled: Bool) { + self.appSettings = appSettings + super.init(initialViewState: .init(deviceID: userSession.clientProxy.deviceID, userID: userSession.clientProxy.userID, showAccountDeactivation: userSession.clientProxy.canDeactivateAccount, - showDeveloperOptions: AppSettings.isDevelopmentBuild, + showDeveloperOptions: appSettings.developerOptionsEnabled, showAnalyticsSettings: appSettings.canPromptForAnalytics, isBugReportServiceEnabled: isBugReportServiceEnabled), mediaProvider: userSession.mediaProvider) + appSettings.$developerOptionsEnabled + .weakAssign(to: \.state.showDeveloperOptions, on: self) + .store(in: &cancellables) + userSession.clientProxy.userAvatarURLPublisher .receive(on: DispatchQueue.main) .weakAssign(to: \.state.userAvatarURL, on: self) @@ -105,7 +113,7 @@ class SettingsScreenViewModel: SettingsScreenViewModelType, SettingsScreenViewMo case .advancedSettings: actionsSubject.send(.advancedSettings) case .enableDeveloperOptions: - state.showDeveloperOptions = true + appSettings.developerOptionsEnabled.toggle() case .developerOptions: actionsSubject.send(.developerOptions) case .deactivateAccount: diff --git a/ElementX/Sources/Screens/Settings/SettingsScreen/View/SettingsScreen.swift b/ElementX/Sources/Screens/Settings/SettingsScreen/View/SettingsScreen.swift index 63e0973d9..24263be45 100644 --- a/ElementX/Sources/Screens/Settings/SettingsScreen/View/SettingsScreen.swift +++ b/ElementX/Sources/Screens/Settings/SettingsScreen/View/SettingsScreen.swift @@ -31,6 +31,10 @@ struct SettingsScreen: View { generalSection signOutSection + + if context.viewState.showDeveloperOptions { + developerOptionsSection + } } .compoundList() .navigationTitle(L10n.commonSettings) @@ -164,15 +168,6 @@ struct SettingsScreen: View { context.send(viewAction: .advancedSettings) }) .accessibilityIdentifier(A11yIdentifiers.settingsScreen.advancedSettings) - - if context.viewState.showDeveloperOptions { - ListRow(label: .default(title: L10n.commonDeveloperOptions, - icon: \.code), - kind: .navigationLink { - context.send(viewAction: .developerOptions) - }) - .accessibilityIdentifier(A11yIdentifiers.settingsScreen.developerOptions) - } } } @@ -195,21 +190,40 @@ struct SettingsScreen: View { }) } } footer: { - VStack(spacing: 0) { - versionText - .frame(maxWidth: .infinity) - - if let deviceID = context.viewState.deviceID { - Text(deviceID) - } + if !context.viewState.showDeveloperOptions { + versionSection } - .compoundListSectionFooter() - .textSelection(.enabled) - .padding(.top, 24) - .onTapGesture(count: 7) { - context.send(viewAction: .enableDeveloperOptions) + } + } + + private var developerOptionsSection: some View { + Section { + ListRow(label: .default(title: L10n.commonDeveloperOptions, + icon: \.code), + kind: .navigationLink { + context.send(viewAction: .developerOptions) + }) + .accessibilityIdentifier(A11yIdentifiers.settingsScreen.developerOptions) + } footer: { + versionSection + } + } + + private var versionSection: some View { + VStack(spacing: 0) { + versionText + .frame(maxWidth: .infinity) + + if let deviceID = context.viewState.deviceID { + Text(deviceID) } } + .compoundListSectionFooter() + .textSelection(.enabled) + .padding(.top, 24) + .onTapGesture(count: 7) { + context.send(viewAction: .enableDeveloperOptions) + } } private var versionText: Text { diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/settingsScreen.Bug-report-disabled-iPad-en-GB.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/settingsScreen.Bug-report-disabled-iPad-en-GB.png index 0171afe5e..2d1f6dc5b 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/settingsScreen.Bug-report-disabled-iPad-en-GB.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/settingsScreen.Bug-report-disabled-iPad-en-GB.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:82aceb5956ac84373d141855acaa16a962034001d2b4a01c4bd30a347505e2f8 -size 160152 +oid sha256:52523db2aba7eb976442148c2d5f91d5671051c098b05eb2f9c7be430c3c1694 +size 156627 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/settingsScreen.Bug-report-disabled-iPad-pseudo.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/settingsScreen.Bug-report-disabled-iPad-pseudo.png index 83e424484..d865b32de 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/settingsScreen.Bug-report-disabled-iPad-pseudo.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/settingsScreen.Bug-report-disabled-iPad-pseudo.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0ce61dcd6449607c67a4aa12d96140e1159afce33481351a16e7af9f90c5e932 -size 166763 +oid sha256:9e3fffd292f64c9ba2f8a8faddc5189ae50ee47270a19228a6e7907dcf4b0bcc +size 163130 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/settingsScreen.Bug-report-disabled-iPhone-16-en-GB.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/settingsScreen.Bug-report-disabled-iPhone-16-en-GB.png index 48ee1be07..8ec0f7517 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/settingsScreen.Bug-report-disabled-iPhone-16-en-GB.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/settingsScreen.Bug-report-disabled-iPhone-16-en-GB.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:967c85e91f106b89c44f17facb9ac369bbca2e19e33b1cd6875108aba2fd5b49 -size 106646 +oid sha256:b5eacf4f9bda7c545775d6942dbbb74006f22b1f4d389b673dc7dd7f8815815e +size 101949 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/settingsScreen.Bug-report-disabled-iPhone-16-pseudo.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/settingsScreen.Bug-report-disabled-iPhone-16-pseudo.png index 3a5191c29..af3d5d470 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/settingsScreen.Bug-report-disabled-iPhone-16-pseudo.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/settingsScreen.Bug-report-disabled-iPhone-16-pseudo.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:eab5bec1eb422c8918f0e7c634d2b1cd3b1190dc001547db99159395241fea3e -size 123586 +oid sha256:1467462e53d7b012683e8ca0b8081d35f807b5cc2162188401fe5093890e4ce6 +size 117295 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/settingsScreen.Default-iPad-en-GB.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/settingsScreen.Default-iPad-en-GB.png index 0497327d5..0de91f6e1 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/settingsScreen.Default-iPad-en-GB.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/settingsScreen.Default-iPad-en-GB.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e94e7fe94e45f550c49a15fdbf99833b84122dfb06b7f76489a565cc83f7cc41 -size 165407 +oid sha256:df937f8fbee24daf78f83310fda04cecbaa46a0138717a6b9dff637ed3b4e675 +size 161130 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/settingsScreen.Default-iPad-pseudo.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/settingsScreen.Default-iPad-pseudo.png index d74e86b30..81feda706 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/settingsScreen.Default-iPad-pseudo.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/settingsScreen.Default-iPad-pseudo.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:fd2114c1b2ce2c9c0ab24d012e5a1baa176e1d68e0489861c75e28903d5ef10e -size 173127 +oid sha256:680feb663bf4c1157a62b7c5ba81161368e6f2e740f862aea2d6a3a1bd43c103 +size 167872 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/settingsScreen.Default-iPhone-16-en-GB.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/settingsScreen.Default-iPhone-16-en-GB.png index ae270dcec..f90ff88a7 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/settingsScreen.Default-iPhone-16-en-GB.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/settingsScreen.Default-iPhone-16-en-GB.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:2e8fa5cb469e8275db6e375661334676da5d12bc890fe203182f9639c1c3c607 -size 110502 +oid sha256:2ae451c9873060a79d7653089af4823cf5cf686c7c47d3b68d52de0545b27b19 +size 107060 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/settingsScreen.Default-iPhone-16-pseudo.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/settingsScreen.Default-iPhone-16-pseudo.png index 4648069b3..aaa277bdb 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/settingsScreen.Default-iPhone-16-pseudo.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/settingsScreen.Default-iPhone-16-pseudo.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e32ea079775f12a7c821b4236156b4f7500eeb1ed27ad63985fdbb9e1aa00908 -size 126900 +oid sha256:c08dff4a65638a354ad8ff3947e011d229fee99e2b7d6c7c0384ee39371fb5c2 +size 123855