mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +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:
@@ -49,14 +49,14 @@ class Analytics {
|
||||
/// Whether to show the user the analytics opt in prompt.
|
||||
var shouldShowAnalyticsPrompt: Bool {
|
||||
// Only show the prompt once, and when analytics are enabled in BuildSettings.
|
||||
!ElementSettings.shared.hasSeenAnalyticsPrompt && BuildSettings.analyticsConfiguration.isEnabled
|
||||
!ServiceLocator.shared.settings.hasSeenAnalyticsPrompt && ServiceLocator.shared.settings.analyticsConfiguration.isEnabled
|
||||
}
|
||||
|
||||
/// Opts in to analytics tracking with the supplied user session.
|
||||
/// - Parameter userSession: The user session to use to when reading/generating the analytics ID.
|
||||
/// The session will be ignored if not running.
|
||||
func optIn(with userSession: UserSessionProtocol) {
|
||||
ElementSettings.shared.enableAnalytics = true
|
||||
ServiceLocator.shared.settings.enableAnalytics = true
|
||||
startIfEnabled()
|
||||
|
||||
Task { await useAnalyticsSettings(from: userSession) }
|
||||
@@ -64,7 +64,7 @@ class Analytics {
|
||||
|
||||
/// Stops analytics tracking and calls `reset` to clear any IDs and event queues.
|
||||
func optOut() {
|
||||
ElementSettings.shared.enableAnalytics = false
|
||||
ServiceLocator.shared.settings.enableAnalytics = false
|
||||
|
||||
// The order is important here. PostHog ignores the reset if stopped.
|
||||
reset()
|
||||
@@ -76,7 +76,7 @@ class Analytics {
|
||||
|
||||
/// Starts the analytics client if the user has opted in, otherwise does nothing.
|
||||
func startIfEnabled() {
|
||||
guard ElementSettings.shared.enableAnalytics, !isRunning else { return }
|
||||
guard ServiceLocator.shared.settings.enableAnalytics, !isRunning else { return }
|
||||
|
||||
client.start()
|
||||
// monitoringClient.start()
|
||||
@@ -96,8 +96,8 @@ class Analytics {
|
||||
/// - Parameter userSession: The user session to read analytics settings from.
|
||||
func useAnalyticsSettings(from userSession: UserSessionProtocol) async {
|
||||
guard
|
||||
ElementSettings.shared.enableAnalytics,
|
||||
!ElementSettings.shared.isIdentifiedForAnalytics
|
||||
ServiceLocator.shared.settings.enableAnalytics,
|
||||
!ServiceLocator.shared.settings.isIdentifiedForAnalytics
|
||||
else { return }
|
||||
|
||||
let service = AnalyticsService(userSession: userSession)
|
||||
@@ -122,7 +122,7 @@ class Analytics {
|
||||
// monitoringClient.reset()
|
||||
|
||||
MXLog.debug("Reset.")
|
||||
ElementSettings.shared.isIdentifiedForAnalytics = false
|
||||
ServiceLocator.shared.settings.isIdentifiedForAnalytics = false
|
||||
|
||||
// Stop collecting crash logs
|
||||
// MXLogger.logCrashes(false)
|
||||
@@ -147,7 +147,7 @@ class Analytics {
|
||||
|
||||
client.identify(id: id)
|
||||
MXLog.debug("Identified.")
|
||||
ElementSettings.shared.isIdentifiedForAnalytics = true
|
||||
ServiceLocator.shared.settings.isIdentifiedForAnalytics = true
|
||||
}
|
||||
|
||||
/// Capture an event in the `client`.
|
||||
|
||||
@@ -18,7 +18,7 @@ import PostHog
|
||||
|
||||
extension PHGPostHogConfiguration {
|
||||
static var standard: PHGPostHogConfiguration? {
|
||||
let analyticsConfiguration = BuildSettings.analyticsConfiguration
|
||||
let analyticsConfiguration = ServiceLocator.shared.settings.analyticsConfiguration
|
||||
guard analyticsConfiguration.isEnabled else { return nil }
|
||||
|
||||
let postHogConfiguration = PHGPostHogConfiguration(apiKey: analyticsConfiguration.apiKey, host: analyticsConfiguration.host)
|
||||
|
||||
Reference in New Issue
Block a user