Skip to content

Commit

Permalink
Added debug menu to show type of leanplum settup (#6632)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbhasin2 committed May 19, 2020
1 parent dad7b34 commit 4682409
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
21 changes: 19 additions & 2 deletions Client/Application/LeanplumIntegration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,20 @@ struct LPSettings {
var productionKey: String
}

enum LPSetupType: String {
case debug
case production
case none
}

class LeanPlumClient {
static let shared = LeanPlumClient()

// Setup
private weak var profile: Profile?
private var prefs: Prefs? { return profile?.prefs }
private var enabled: Bool = true

private var setupType: LPSetupType = .none
// This defines an external Leanplum varible to enable/disable FxA prepush dialogs.
// The primary result is having a feature flag controlled by Leanplum, and falling back
// to prompting with native push permissions.
Expand All @@ -129,6 +135,10 @@ class LeanPlumClient {
func isLPEnabled() -> Bool {
return enabled && Leanplum.hasStarted()
}

func lpSetupType() -> LPSetupType {
return setupType
}

static func shouldEnable(profile: Profile) -> Bool {
return AppConstants.MOZ_ENABLE_LEANPLUM && (profile.prefs.boolForKey(AppConstants.PrefSendUsageData) ?? true)
Expand All @@ -155,6 +165,7 @@ class LeanPlumClient {
fileprivate func start() {
guard let settings = getSettings(), isLocaleSupported(), !Leanplum.hasStarted() else {
enabled = false
Sentry.shared.send(message: "LeanplumIntegration - Could not be started")
log.error("LeanplumIntegration - Could not be started")
return
}
Expand All @@ -163,9 +174,11 @@ class LeanPlumClient {
log.info("LeanplumIntegration - Setting up for Development")
Leanplum.setDeviceId(UIDevice.current.identifierForVendor?.uuidString)
Leanplum.setAppId(settings.appId, withDevelopmentKey: settings.developmentKey)
setupType = .debug
} else {
log.info("LeanplumIntegration - Setting up for Production")
Leanplum.setAppId(settings.appId, withProductionKey: settings.productionKey)
setupType = .production
}

Leanplum.syncResourcesAsync(true)
Expand Down Expand Up @@ -244,7 +257,11 @@ class LeanPlumClient {
func isFxAPrePushEnabled() -> Bool {
return AppConstants.MOZ_FXA_LEANPLUM_AB_PUSH_TEST && (useFxAPrePush?.boolValue() ?? false)
}


func isRunning() -> Bool {
return Leanplum.hasStarted()
}

/*
This is used to determine if an app was installed after firefox was installed
*/
Expand Down
8 changes: 8 additions & 0 deletions Client/Frontend/Settings/AppSettingsOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,14 @@ class ToggleOnboarding: HiddenSetting {
}
}

class LeanplumStatus: HiddenSetting {
let lplumSetupType = LeanPlumClient.shared.lpSetupType()

override var title: NSAttributedString? {
return NSAttributedString(string: "Leamplum Status: \(lplumSetupType) | Started: \(LeanPlumClient.shared.isRunning())", attributes: [NSAttributedString.Key.foregroundColor: UIColor.theme.tableView.rowText])
}
}

class SetOnboardingV2: HiddenSetting {
override var title: NSAttributedString? {
return NSAttributedString(string: NSLocalizedString("Debug: Set onboarding type to v2", comment: "Debug option"), attributes: [NSAttributedString.Key.foregroundColor: UIColor.theme.tableView.rowText])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ class AppSettingsTableViewController: SettingsTableViewController {
ForgetSyncAuthStateDebugSetting(settings: self),
SentryIDSetting(settings: self),
ChangeToChinaSetting(settings: self),
ToggleOnboarding(settings: self)
ToggleOnboarding(settings: self),
LeanplumStatus(settings: self)
])]

return settings
Expand Down

0 comments on commit 4682409

Please sign in to comment.