Skip to content

Commit

Permalink
Fixes FXIOS-1584: Showing default browser card only on fresh install (#…
Browse files Browse the repository at this point in the history
…8132)

- Added InstallType enum to catch fresh and upgrade installs
  • Loading branch information
nbhasin2 committed Mar 12, 2021
1 parent 9841299 commit d641c13
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 15 deletions.
31 changes: 28 additions & 3 deletions Client/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,34 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UIViewControllerRestorati
_ = ChronTabsUserResearch()
// Leanplum setup

if let profile = self.profile, LeanPlumClient.shouldEnable(profile: profile) {
LeanPlumClient.shared.setup(profile: profile)
LeanPlumClient.shared.set(enabled: true)
if let profile = self.profile {
// Leanplum setup
if LeanPlumClient.shouldEnable(profile: profile) {
LeanPlumClient.shared.setup(profile: profile)
LeanPlumClient.shared.set(enabled: true)
}

let persistedCurrentVersion = InstallType.persistedCurrentVersion()
let introScreen = profile.prefs.intForKey(PrefsKeys.IntroSeen)
// upgrade install - Intro screen shown & persisted current version does not match
if introScreen != nil && persistedCurrentVersion != AppInfo.appVersion {
InstallType.set(type: .upgrade)
InstallType.updateCurrentVersion(version: AppInfo.appVersion)
}

// We need to check if the app is a clean install to use for
// preventing the What's New URL from appearing.
if introScreen == nil {
// fresh install - Intro screen not yet shown
InstallType.set(type: .fresh)
InstallType.updateCurrentVersion(version: AppInfo.appVersion)
// Profile and leanplum setup
profile.prefs.setString(AppInfo.appVersion, forKey: LatestAppVersionProfileKey)
LeanPlumClient.shared.track(event: .firstRun)
} else if profile.prefs.boolForKey(PrefsKeys.KeySecondRun) == nil {
profile.prefs.setBool(true, forKey: PrefsKeys.KeySecondRun)
LeanPlumClient.shared.track(event: .secondRun)
}
}

if #available(iOS 13.0, *) {
Expand Down
12 changes: 0 additions & 12 deletions Client/Application/LeanplumIntegration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -234,18 +234,6 @@ class LeanPlumClient {
// According to the doc all variables should be synced when lp start finishes
// Relying on this fact and sending the updated AB test variable
self.finishedStartingLeanplum?()
// We need to check if the app is a clean install to use for
// preventing the What's New URL from appearing.
if self.prefs?.intForKey(PrefsKeys.IntroSeen) == nil {
self.prefs?.setString(AppInfo.appVersion, forKey: LatestAppVersionProfileKey)
self.track(event: .firstRun)
self.lpState = .started(startedState: .firstRun)
} else if self.prefs?.boolForKey("SecondRun") == nil {
self.prefs?.setBool(true, forKey: "SecondRun")
self.track(event: .secondRun)
self.lpState = .started(startedState: .secondRun)
}

self.checkIfAppWasInstalled(key: PrefsKeys.HasFocusInstalled, isAppInstalled: self.focusInstalled(), lpEvent: .downloadedFocus)
self.checkIfAppWasInstalled(key: PrefsKeys.HasPocketInstalled, isAppInstalled: self.pocketInstalled(), lpEvent: .downloadedPocket)
self.recordSyncedClients(with: self.profile)
Expand Down
3 changes: 3 additions & 0 deletions Client/Frontend/Browser/BrowserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class BrowserViewController: UIViewController {

fileprivate var keyboardState: KeyboardState?
var hasTriedToPresentETPAlready = false
var hasTriedToPresentDBCardAlready = false
var pendingToast: Toast? // A toast that might be waiting for BVC to appear before displaying
var downloadToast: DownloadToast? // A toast that is showing the combined download progress

Expand Down Expand Up @@ -2127,6 +2128,8 @@ extension BrowserViewController {
// Default browser onboarding
func presentDBOnboardingViewController(_ force: Bool = false) {
guard #available(iOS 14.0, *) else { return }
guard !hasTriedToPresentDBCardAlready || force else { return }
hasTriedToPresentDBCardAlready = true
let shouldShow = DefaultBrowserOnboardingViewModel.shouldShowDefaultBrowserOnboarding(userPrefs: profile.prefs)
guard force || shouldShow else {
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,35 @@
import Foundation
import Shared

enum InstallType: String, Codable {
case fresh
case upgrade
case unknown

// Helper methods
static func get() -> InstallType {
guard let rawValue = UserDefaults.standard.string(forKey: PrefsKeys.InstallType), let type = InstallType(rawValue: rawValue) else {
return unknown
}
return type
}

static func set(type: InstallType) {
UserDefaults.standard.set(type.rawValue, forKey: PrefsKeys.InstallType)
}

static func persistedCurrentVersion() -> String {
guard let currentVersion = UserDefaults.standard.string(forKey: PrefsKeys.KeyCurrentInstallVersion) else {
return ""
}
return currentVersion
}

static func updateCurrentVersion(version: String) {
UserDefaults.standard.set(version, forKey: PrefsKeys.KeyCurrentInstallVersion)
}
}

// Data Model
struct DefaultBrowserOnboardingModel {
var titleImage: UIImage
Expand Down Expand Up @@ -45,6 +74,8 @@ class DefaultBrowserOnboardingViewModel {
}

static func shouldShowDefaultBrowserOnboarding(userPrefs: Prefs) -> Bool {
// Only show on fresh install
guard InstallType.get() == .fresh else { return false }
// Show on 3rd session
let maxSessionCount = 3
var shouldShow = false
Expand Down
3 changes: 3 additions & 0 deletions Shared/Prefs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public struct PrefsKeys {
public static let GoogleTopSiteAddedKey = "googleTopSiteAddedKey"
public static let GoogleTopSiteHideKey = "googleTopSiteHideKey"
public static let SessionCount = "sessionCount"
public static let InstallType = "InstallType"
public static let KeyCurrentInstallVersion = "KeyCurrentInstallVersion"
public static let KeySecondRun = "SecondRun"

//Activity Stream
public static let KeyTopSitesCacheIsValid = "topSitesCacheIsValid"
Expand Down

1 comment on commit d641c13

@firefoxci-taskcluster
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh oh! Looks like an error! Details

InterpreterError at template.tasks[0][1].extra[0].treeherder[1].symbol: unknown context value cron

Please sign in to comment.