Skip to content

Commit

Permalink
feat: New appRestorationVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-coye committed Jun 24, 2024
1 parent a643dbc commit ac35859
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions Sources/InfomaniakCore/Account/UserDefaults+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,31 @@ public extension UserDefaults {
self.rawValue = rawValue
}

// TODO: Clean hotfix
static let legacyIsFirstLaunch = Keys(rawValue: "isFirstLaunch")
static let currentUserId = Keys(rawValue: "currentUserId")
static let appRestorationVersion = Keys(rawValue: "appRestorationVersion")
}

func key(_ key: Keys) -> String {
return key.rawValue
}
}

// MARK: - Internal extension

extension UserDefaults.Keys {
static let launchCounter = UserDefaults.Keys(rawValue: "launchCounter")
}

extension UserDefaults {
var launchCounter: Int {
get {
return integer(forKey: key(.launchCounter))
}
set {
set(newValue, forKey: key(.launchCounter))
}
}

var currentUserId: Int {
get {
Expand All @@ -44,34 +61,25 @@ public extension UserDefaults {
}
}

// TODO: Clean hotfix
var legacyIsFirstLaunch: Bool {
get {
if object(forKey: key(.legacyIsFirstLaunch)) != nil {
return bool(forKey: key(.legacyIsFirstLaunch))
} else {
guard let isFirstLaunch = object(forKey: key(.legacyIsFirstLaunch)) else {
return true
}

return isFirstLaunch
}
set {
set(newValue, forKey: key(.legacyIsFirstLaunch))
}
}
}

// MARK: - Internal extension

extension UserDefaults.Keys {
static let launchCounter = UserDefaults.Keys(rawValue: "launchCounter")
}

extension UserDefaults {
var launchCounter: Int {
var appRestorationVersion: Int? {
get {
return integer(forKey: key(.launchCounter))
return object(forKey: key(.appRestorationVersion))
}
set {
set(newValue, forKey: key(.launchCounter))
set(newValue, forKey: key(.appRestorationVersion))
}
}
}

0 comments on commit ac35859

Please sign in to comment.