mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 19:44:05 +00:00
Resetting the app after deletion and cleanup settings (#372)
* Fixes #361 - Reset everything if the app has been deleted since the last run * Cleaned up and renamed the ElementSettings to ApplicationSettings. Removed its singleton and moved it to the service locator. * Moved the ApplicationSettings to the Application folder * Merged together the BuildSettings and ApplicationSettings * Reset the UserDefaults too when resetting the application state * Rename ServiceLocator.applicationSettings to just settings * Fix indentation * Rename ApplicationSettings to AppSettings * Various tweaks following code review * Fix unit tests
This commit is contained in:
@@ -30,7 +30,7 @@ final class AnalyticsPromptCoordinator: CoordinatorProtocol {
|
||||
init(parameters: AnalyticsPromptCoordinatorParameters) {
|
||||
self.parameters = parameters
|
||||
|
||||
viewModel = AnalyticsPromptViewModel(termsURL: BuildSettings.analyticsConfiguration.termsURL)
|
||||
viewModel = AnalyticsPromptViewModel(termsURL: ServiceLocator.shared.settings.analyticsConfiguration.termsURL)
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
@@ -55,7 +55,7 @@ struct AnalyticsPromptStrings {
|
||||
|
||||
// Replace the placeholder with a link.
|
||||
var link = AttributedString(ElementL10n.analyticsOptInContentLink)
|
||||
link.link = BuildSettings.analyticsConfiguration.termsURL
|
||||
link.link = ServiceLocator.shared.settings.analyticsConfiguration.termsURL
|
||||
optInContent.replaceSubrange(range, with: link)
|
||||
|
||||
self.optInContent = optInContent
|
||||
|
||||
@@ -114,7 +114,7 @@ struct AnalyticsPrompt: View {
|
||||
// MARK: - Previews
|
||||
|
||||
struct AnalyticsPrompt_Previews: PreviewProvider {
|
||||
static let viewModel = AnalyticsPromptViewModel(termsURL: BuildSettings.analyticsConfiguration.termsURL)
|
||||
static let viewModel = AnalyticsPromptViewModel(termsURL: ServiceLocator.shared.settings.analyticsConfiguration.termsURL)
|
||||
static var previews: some View {
|
||||
AnalyticsPrompt(context: viewModel.context)
|
||||
.tint(.element.accent)
|
||||
|
||||
@@ -61,7 +61,7 @@ class AuthenticationCoordinator: CoordinatorProtocol {
|
||||
private func startAuthentication() async {
|
||||
startLoading()
|
||||
|
||||
switch await authenticationService.configure(for: BuildSettings.defaultHomeserverAddress) {
|
||||
switch await authenticationService.configure(for: ServiceLocator.shared.settings.defaultHomeserverAddress) {
|
||||
case .success:
|
||||
stopLoading()
|
||||
showLoginScreen()
|
||||
|
||||
+3
-3
@@ -23,7 +23,7 @@ class ServerSelectionViewModel: ServerSelectionViewModelType, ServerSelectionVie
|
||||
|
||||
init(homeserverAddress: String, isModallyPresented: Bool) {
|
||||
let bindings = ServerSelectionBindings(homeserverAddress: homeserverAddress,
|
||||
slidingSyncProxyAddress: ElementSettings.shared.slidingSyncProxyBaseURLString)
|
||||
slidingSyncProxyAddress: ServiceLocator.shared.settings.slidingSyncProxyBaseURLString)
|
||||
|
||||
super.init(initialViewState: ServerSelectionViewState(bindings: bindings,
|
||||
isModallyPresented: isModallyPresented))
|
||||
@@ -33,8 +33,8 @@ class ServerSelectionViewModel: ServerSelectionViewModelType, ServerSelectionVie
|
||||
switch viewAction {
|
||||
case .confirm:
|
||||
if !state.bindings.slidingSyncProxyAddress.isEmpty,
|
||||
state.bindings.slidingSyncProxyAddress != ElementSettings.shared.slidingSyncProxyBaseURLString {
|
||||
ElementSettings.shared.slidingSyncProxyBaseURLString = state.bindings.slidingSyncProxyAddress
|
||||
state.bindings.slidingSyncProxyAddress != ServiceLocator.shared.settings.slidingSyncProxyBaseURLString {
|
||||
ServiceLocator.shared.settings.slidingSyncProxyBaseURLString = state.bindings.slidingSyncProxyAddress
|
||||
}
|
||||
|
||||
callback?(.confirm(homeserverAddress: state.bindings.homeserverAddress))
|
||||
|
||||
@@ -68,7 +68,7 @@ class BugReportViewModel: BugReportViewModelType, BugReportViewModelProtocol {
|
||||
let result = try await bugReportService.submitBugReport(text: context.reportText,
|
||||
includeLogs: context.sendingLogsEnabled,
|
||||
includeCrashLog: true,
|
||||
githubLabels: BuildSettings.bugReportGHLabels,
|
||||
githubLabels: ServiceLocator.shared.settings.bugReportGHLabels,
|
||||
files: files)
|
||||
MXLog.info("SubmitBugReport succeeded, result: \(result.reportUrl)")
|
||||
callback?(.submitFinished)
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
import SwiftUI
|
||||
|
||||
struct RoomScreen: View {
|
||||
@ObservedObject private var settings = ElementSettings.shared
|
||||
@ObservedObject private var settings = ServiceLocator.shared.settings
|
||||
@ObservedObject var context: RoomScreenViewModel.Context
|
||||
@State private var showReactionsMenuForItemId = ""
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ enum TimelineStyle: String, CaseIterable {
|
||||
// MARK: - Environment
|
||||
|
||||
private struct TimelineStyleKey: EnvironmentKey {
|
||||
static let defaultValue = BuildSettings.defaultRoomTimelineStyle
|
||||
static let defaultValue = TimelineStyle.bubbles
|
||||
}
|
||||
|
||||
extension EnvironmentValues {
|
||||
|
||||
@@ -50,8 +50,6 @@ final class SettingsCoordinator: CoordinatorProtocol {
|
||||
self.toggleAnalytics()
|
||||
case .reportBug:
|
||||
self.presentBugReportScreen()
|
||||
case .crash:
|
||||
self.parameters.bugReportService.crash()
|
||||
case .logout:
|
||||
self.callback?(.logout)
|
||||
}
|
||||
@@ -67,7 +65,7 @@ final class SettingsCoordinator: CoordinatorProtocol {
|
||||
// MARK: - Private
|
||||
|
||||
private func toggleAnalytics() {
|
||||
if ElementSettings.shared.enableAnalytics {
|
||||
if ServiceLocator.shared.settings.enableAnalytics {
|
||||
Analytics.shared.optOut()
|
||||
} else {
|
||||
Analytics.shared.optIn(with: parameters.userSession)
|
||||
|
||||
@@ -21,7 +21,6 @@ enum SettingsViewModelAction {
|
||||
case close
|
||||
case toggleAnalytics
|
||||
case reportBug
|
||||
case crash
|
||||
case logout
|
||||
}
|
||||
|
||||
@@ -33,13 +32,12 @@ struct SettingsViewState: BindableState {
|
||||
}
|
||||
|
||||
struct SettingsViewStateBindings {
|
||||
var enableAnalytics = ElementSettings.shared.enableAnalytics
|
||||
var enableAnalytics = ServiceLocator.shared.settings.enableAnalytics
|
||||
}
|
||||
|
||||
enum SettingsViewAction {
|
||||
case close
|
||||
case toggleAnalytics
|
||||
case reportBug
|
||||
case crash
|
||||
case logout
|
||||
}
|
||||
|
||||
@@ -51,8 +51,6 @@ class SettingsViewModel: SettingsViewModelType, SettingsViewModelProtocol {
|
||||
callback?(.toggleAnalytics)
|
||||
case .reportBug:
|
||||
callback?(.reportBug)
|
||||
case .crash:
|
||||
callback?(.crash)
|
||||
case .logout:
|
||||
callback?(.logout)
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import SwiftUI
|
||||
struct SettingsScreen: View {
|
||||
@State private var showingLogoutConfirmation = false
|
||||
@Environment(\.colorScheme) private var colorScheme
|
||||
@ObservedObject private var settings = ElementSettings.shared
|
||||
@ObservedObject private var settings = ServiceLocator.shared.settings
|
||||
|
||||
@ScaledMetric private var avatarSize = AvatarSize.user(on: .settings).value
|
||||
@ScaledMetric private var menuIconSize = 30.0
|
||||
@@ -110,30 +110,20 @@ struct SettingsScreen: View {
|
||||
.listRowSeparator(.hidden)
|
||||
.foregroundColor(.element.primaryContent)
|
||||
.accessibilityIdentifier("reportBugButton")
|
||||
|
||||
if BuildSettings.settingsCrashButtonVisible {
|
||||
Button("Crash app",
|
||||
role: .destructive) { context.send(viewAction: .crash)
|
||||
}
|
||||
.listRowInsets(listRowInsets)
|
||||
.accessibilityIdentifier("crashButton")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var userInterfaceSection: some View {
|
||||
if BuildSettings.settingsShowTimelineStyle {
|
||||
Section {
|
||||
Picker(ElementL10n.settingsTimelineStyle, selection: $settings.timelineStyle) {
|
||||
ForEach(TimelineStyle.allCases, id: \.self) { style in
|
||||
Text(style.description)
|
||||
.tag(style)
|
||||
}
|
||||
Section {
|
||||
Picker(ElementL10n.settingsTimelineStyle, selection: $settings.timelineStyle) {
|
||||
ForEach(TimelineStyle.allCases, id: \.self) { style in
|
||||
Text(style.description)
|
||||
.tag(style)
|
||||
}
|
||||
.listRowInsets(listRowInsets)
|
||||
.accessibilityIdentifier("timelineStylePicker")
|
||||
}
|
||||
.listRowInsets(listRowInsets)
|
||||
.accessibilityIdentifier("timelineStylePicker")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user