Move where the developer options are shown and store them in the app settings.

This commit is contained in:
Stefan Ceriu
2025-04-30 14:01:28 +03:00
committed by Stefan Ceriu
parent eaa6dd9240
commit 0c5be93a75
11 changed files with 65 additions and 39 deletions
@@ -58,6 +58,7 @@ final class AppSettings {
case enableOnlySignedDeviceIsolationMode case enableOnlySignedDeviceIsolationMode
case knockingEnabled case knockingEnabled
case threadsEnabled case threadsEnabled
case developerOptionsEnabled
} }
private static var suiteName: String = InfoPlistReader.main.appGroupIdentifier private static var suiteName: String = InfoPlistReader.main.appGroupIdentifier
@@ -328,6 +329,9 @@ final class AppSettings {
@UserPreference(key: UserDefaultsKeys.threadsEnabled, defaultValue: false, storageType: .userDefaults(store)) @UserPreference(key: UserDefaultsKeys.threadsEnabled, defaultValue: false, storageType: .userDefaults(store))
var threadsEnabled var threadsEnabled
@UserPreference(key: UserDefaultsKeys.threadsEnabled, defaultValue: isDevelopmentBuild, storageType: .userDefaults(store))
var developerOptionsEnabled
#endif #endif
// MARK: - Shared // MARK: - Shared
@@ -11,6 +11,8 @@ import SwiftUI
typealias SettingsScreenViewModelType = StateStoreViewModelV2<SettingsScreenViewState, SettingsScreenViewAction> typealias SettingsScreenViewModelType = StateStoreViewModelV2<SettingsScreenViewState, SettingsScreenViewAction>
class SettingsScreenViewModel: SettingsScreenViewModelType, SettingsScreenViewModelProtocol { class SettingsScreenViewModel: SettingsScreenViewModelType, SettingsScreenViewModelProtocol {
private let appSettings: AppSettings
private var actionsSubject: PassthroughSubject<SettingsScreenViewModelAction, Never> = .init() private var actionsSubject: PassthroughSubject<SettingsScreenViewModelAction, Never> = .init()
var actions: AnyPublisher<SettingsScreenViewModelAction, Never> { var actions: AnyPublisher<SettingsScreenViewModelAction, Never> {
@@ -18,14 +20,20 @@ class SettingsScreenViewModel: SettingsScreenViewModelType, SettingsScreenViewMo
} }
init(userSession: UserSessionProtocol, appSettings: AppSettings, isBugReportServiceEnabled: Bool) { init(userSession: UserSessionProtocol, appSettings: AppSettings, isBugReportServiceEnabled: Bool) {
self.appSettings = appSettings
super.init(initialViewState: .init(deviceID: userSession.clientProxy.deviceID, super.init(initialViewState: .init(deviceID: userSession.clientProxy.deviceID,
userID: userSession.clientProxy.userID, userID: userSession.clientProxy.userID,
showAccountDeactivation: userSession.clientProxy.canDeactivateAccount, showAccountDeactivation: userSession.clientProxy.canDeactivateAccount,
showDeveloperOptions: AppSettings.isDevelopmentBuild, showDeveloperOptions: appSettings.developerOptionsEnabled,
showAnalyticsSettings: appSettings.canPromptForAnalytics, showAnalyticsSettings: appSettings.canPromptForAnalytics,
isBugReportServiceEnabled: isBugReportServiceEnabled), isBugReportServiceEnabled: isBugReportServiceEnabled),
mediaProvider: userSession.mediaProvider) mediaProvider: userSession.mediaProvider)
appSettings.$developerOptionsEnabled
.weakAssign(to: \.state.showDeveloperOptions, on: self)
.store(in: &cancellables)
userSession.clientProxy.userAvatarURLPublisher userSession.clientProxy.userAvatarURLPublisher
.receive(on: DispatchQueue.main) .receive(on: DispatchQueue.main)
.weakAssign(to: \.state.userAvatarURL, on: self) .weakAssign(to: \.state.userAvatarURL, on: self)
@@ -105,7 +113,7 @@ class SettingsScreenViewModel: SettingsScreenViewModelType, SettingsScreenViewMo
case .advancedSettings: case .advancedSettings:
actionsSubject.send(.advancedSettings) actionsSubject.send(.advancedSettings)
case .enableDeveloperOptions: case .enableDeveloperOptions:
state.showDeveloperOptions = true appSettings.developerOptionsEnabled.toggle()
case .developerOptions: case .developerOptions:
actionsSubject.send(.developerOptions) actionsSubject.send(.developerOptions)
case .deactivateAccount: case .deactivateAccount:
@@ -31,6 +31,10 @@ struct SettingsScreen: View {
generalSection generalSection
signOutSection signOutSection
if context.viewState.showDeveloperOptions {
developerOptionsSection
}
} }
.compoundList() .compoundList()
.navigationTitle(L10n.commonSettings) .navigationTitle(L10n.commonSettings)
@@ -164,15 +168,6 @@ struct SettingsScreen: View {
context.send(viewAction: .advancedSettings) context.send(viewAction: .advancedSettings)
}) })
.accessibilityIdentifier(A11yIdentifiers.settingsScreen.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: { } footer: {
VStack(spacing: 0) { if !context.viewState.showDeveloperOptions {
versionText versionSection
.frame(maxWidth: .infinity)
if let deviceID = context.viewState.deviceID {
Text(deviceID)
}
} }
.compoundListSectionFooter() }
.textSelection(.enabled) }
.padding(.top, 24)
.onTapGesture(count: 7) { private var developerOptionsSection: some View {
context.send(viewAction: .enableDeveloperOptions) 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 { private var versionText: Text {
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:82aceb5956ac84373d141855acaa16a962034001d2b4a01c4bd30a347505e2f8 oid sha256:52523db2aba7eb976442148c2d5f91d5671051c098b05eb2f9c7be430c3c1694
size 160152 size 156627
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:0ce61dcd6449607c67a4aa12d96140e1159afce33481351a16e7af9f90c5e932 oid sha256:9e3fffd292f64c9ba2f8a8faddc5189ae50ee47270a19228a6e7907dcf4b0bcc
size 166763 size 163130
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:967c85e91f106b89c44f17facb9ac369bbca2e19e33b1cd6875108aba2fd5b49 oid sha256:b5eacf4f9bda7c545775d6942dbbb74006f22b1f4d389b673dc7dd7f8815815e
size 106646 size 101949
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:eab5bec1eb422c8918f0e7c634d2b1cd3b1190dc001547db99159395241fea3e oid sha256:1467462e53d7b012683e8ca0b8081d35f807b5cc2162188401fe5093890e4ce6
size 123586 size 117295
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:e94e7fe94e45f550c49a15fdbf99833b84122dfb06b7f76489a565cc83f7cc41 oid sha256:df937f8fbee24daf78f83310fda04cecbaa46a0138717a6b9dff637ed3b4e675
size 165407 size 161130
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:fd2114c1b2ce2c9c0ab24d012e5a1baa176e1d68e0489861c75e28903d5ef10e oid sha256:680feb663bf4c1157a62b7c5ba81161368e6f2e740f862aea2d6a3a1bd43c103
size 173127 size 167872
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:2e8fa5cb469e8275db6e375661334676da5d12bc890fe203182f9639c1c3c607 oid sha256:2ae451c9873060a79d7653089af4823cf5cf686c7c47d3b68d52de0545b27b19
size 110502 size 107060
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:e32ea079775f12a7c821b4236156b4f7500eeb1ed27ad63985fdbb9e1aa00908 oid sha256:c08dff4a65638a354ad8ff3947e011d229fee99e2b7d6c7c0384ee39371fb5c2
size 126900 size 123855