Skip to content

Commit 506e971

Browse files
committed
[#698] Resolve comments
1 parent 1ada24e commit 506e971

8 files changed

Lines changed: 58 additions & 46 deletions

File tree

template/Modules/Data/Sources/Extensions/Container+Data.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ extension Container {
4747
.singleton
4848
}
4949

50-
public var ratingPromptStorage: Factory<RatingPromptStorageProtocol> {
51-
self { RatingPromptStorage(userDefaultsManager: self.userDefaultsManager()) }.singleton
50+
public var ratingPromptRepository: Factory<RatingPromptRepositoryProtocol> {
51+
self { RatingPromptRepository(userDefaultsManager: self.userDefaultsManager()) }.singleton
5252
}
5353
}

template/Modules/Data/Sources/Repositories/RatingPromptStorage.swift renamed to template/Modules/Data/Sources/Repositories/RatingPromptRepository.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,64 @@
11
import Domain
22
import Foundation
33

4-
actor RatingPromptStorage: RatingPromptStorageProtocol {
5-
4+
actor RatingPromptRepository: RatingPromptRepositoryProtocol {
5+
66
private let userDefaultsManager: UserDefaultsManagerProtocol
7-
7+
88
init(userDefaultsManager: UserDefaultsManagerProtocol) {
99
self.userDefaultsManager = userDefaultsManager
1010
}
11-
11+
1212
func getRatingPromptData() async -> RatingPromptData {
1313
let appLaunchCount = userDefaultsManager.getIntValue(for: UserDefaultsKey.ratingPromptAppLaunchCount.rawValue)
1414
let firstLaunchDateData = userDefaultsManager.getDataValue(for: UserDefaultsKey.ratingPromptFirstLaunchDate.rawValue)
1515
let lastPromptedVersion = userDefaultsManager.getStringValue(for: UserDefaultsKey.ratingPromptLastPromptedVersion.rawValue)
1616
let significantEventCount = userDefaultsManager.getIntValue(for: UserDefaultsKey.ratingPromptSignificantEventCount.rawValue)
17-
17+
1818
var firstLaunchDate: Date?
1919
if let dateData = firstLaunchDateData {
2020
firstLaunchDate = try? JSONDecoder().decode(Date.self, from: dateData)
2121
}
22-
22+
2323
return RatingPromptData(
2424
appLaunchCount: appLaunchCount,
2525
firstLaunchDate: firstLaunchDate,
2626
lastPromptedVersion: lastPromptedVersion,
2727
significantEventCount: significantEventCount
2828
)
2929
}
30-
30+
3131
func recordAppLaunch() async {
3232
let currentCount = userDefaultsManager.getIntValue(for: UserDefaultsKey.ratingPromptAppLaunchCount.rawValue)
3333
userDefaultsManager.set(currentCount + 1, for: UserDefaultsKey.ratingPromptAppLaunchCount.rawValue)
34-
34+
3535
if userDefaultsManager.getDataValue(for: UserDefaultsKey.ratingPromptFirstLaunchDate.rawValue) == nil {
3636
let now = Date()
3737
if let dateData = try? JSONEncoder().encode(now) {
3838
userDefaultsManager.set(dateData, for: UserDefaultsKey.ratingPromptFirstLaunchDate.rawValue)
3939
}
4040
}
41-
41+
4242
userDefaultsManager.synchronize()
4343
}
44-
44+
4545
func recordSignificantEvent() async {
4646
let currentCount = userDefaultsManager.getIntValue(for: UserDefaultsKey.ratingPromptSignificantEventCount.rawValue)
4747
userDefaultsManager.set(currentCount + 1, for: UserDefaultsKey.ratingPromptSignificantEventCount.rawValue)
4848
userDefaultsManager.synchronize()
4949
}
50-
50+
5151
func recordPromptShown(for appVersion: String) async {
5252
userDefaultsManager.set(appVersion, for: UserDefaultsKey.ratingPromptLastPromptedVersion.rawValue)
5353
userDefaultsManager.synchronize()
5454
}
55-
55+
5656
func resetCounters() async {
5757
userDefaultsManager.set(0, for: UserDefaultsKey.ratingPromptAppLaunchCount.rawValue)
5858
userDefaultsManager.set(0, for: UserDefaultsKey.ratingPromptSignificantEventCount.rawValue)
5959
userDefaultsManager.synchronize()
6060
}
61-
61+
6262
func clearAllData() async {
6363
let keys = [
6464
UserDefaultsKey.ratingPromptAppLaunchCount.rawValue,
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import Foundation
2+
3+
extension Bundle {
4+
5+
public var info: BundleInfo { BundleInfo(bundle: self) }
6+
}
7+
8+
public struct BundleInfo: Sendable {
9+
10+
fileprivate let bundle: Bundle
11+
12+
fileprivate init(bundle: Bundle) {
13+
self.bundle = bundle
14+
}
15+
16+
public var shortVersion: String? {
17+
bundle.infoDictionary?["CFBundleShortVersionString"] as? String
18+
}
19+
}

template/Modules/Domain/Sources/Interfaces/RatingPromptStorageProtocol.swift renamed to template/Modules/Domain/Sources/Interfaces/RatingPromptRepositoryProtocol.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import Foundation
22

33
/// Protocol for managing rating prompt data persistence
4-
public protocol RatingPromptStorageProtocol: Sendable {
5-
4+
public protocol RatingPromptRepositoryProtocol: Sendable {
5+
66
/// Retrieves current rating prompt data
77
func getRatingPromptData() async -> RatingPromptData
8-
8+
99
/// Increments app launch count and sets first launch date if needed
1010
func recordAppLaunch() async
11-
11+
1212
/// Increments significant event count
1313
func recordSignificantEvent() async
14-
14+
1515
/// Records that user was prompted for rating on current version
1616
func recordPromptShown(for appVersion: String) async
17-
17+
1818
/// Resets tracking counters (typically called after prompt is shown)
1919
func resetCounters() async
20-
20+
2121
/// Clears all rating prompt related data
2222
func clearAllData() async
2323
}

template/Modules/Domain/Sources/UseCases/CheckForceUpdateUseCase.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public struct CheckForceUpdateUseCase: CheckForceUpdateUseCaseProtocol, Sendable
3333
extension CheckForceUpdateUseCase {
3434

3535
public static func defaultCurrentVersion() -> AppVersion {
36-
let string = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? ""
36+
let string = Bundle.main.info.shortVersion ?? ""
3737
return AppVersion(string: string) ?? AppVersion(major: 1, minor: 0, patch: 0)
3838
}
3939
}

template/Modules/Domain/Sources/UseCases/RequestRatingPromptUseCase.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ public protocol RequestRatingPromptUseCaseProtocol: Sendable {
1414

1515
public struct RequestRatingPromptUseCase: RequestRatingPromptUseCaseProtocol {
1616

17-
private let storage: any RatingPromptStorageProtocol
17+
private let repository: any RatingPromptRepositoryProtocol
1818
private let shouldShowRatingPromptUseCase: any ShouldShowRatingPromptUseCaseProtocol
1919
private let presenter: any RatingPromptPresenterProtocol
2020
private let currentVersion: @Sendable () -> String
2121

2222
public init(
23-
storage: any RatingPromptStorageProtocol,
23+
repository: any RatingPromptRepositoryProtocol,
2424
shouldShowRatingPromptUseCase: any ShouldShowRatingPromptUseCaseProtocol,
2525
presenter: any RatingPromptPresenterProtocol,
2626
currentVersion: @Sendable @escaping () -> String = {
27-
Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "1.0.0"
27+
Bundle.main.info.shortVersion ?? "1.0.0"
2828
}
2929
) {
30-
self.storage = storage
30+
self.repository = repository
3131
self.shouldShowRatingPromptUseCase = shouldShowRatingPromptUseCase
3232
self.presenter = presenter
3333
self.currentVersion = currentVersion
@@ -40,10 +40,10 @@ public struct RequestRatingPromptUseCase: RequestRatingPromptUseCaseProtocol {
4040
let didRequestPrompt = await presenter.show()
4141
guard didRequestPrompt else { return false }
4242

43-
await storage.recordPromptShown(for: currentVersion())
43+
await repository.recordPromptShown(for: currentVersion())
4444

4545
if configuration.resetCounterAfterPrompt {
46-
await storage.resetCounters()
46+
await repository.resetCounters()
4747
}
4848

4949
return true

template/Modules/Domain/Sources/UseCases/ShouldShowRatingPromptUseCase.swift

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ public protocol ShouldShowRatingPromptUseCaseProtocol: Sendable {
1313
}
1414

1515
public struct ShouldShowRatingPromptUseCase: ShouldShowRatingPromptUseCaseProtocol, Sendable {
16-
17-
private let storage: any RatingPromptStorageProtocol
16+
17+
private let repository: any RatingPromptRepositoryProtocol
1818
private let currentVersion: String
19-
19+
2020
public init(
21-
storage: any RatingPromptStorageProtocol,
22-
currentVersion: String = Self.defaultCurrentVersion()
21+
repository: any RatingPromptRepositoryProtocol,
22+
currentVersion: String = Bundle.main.info.shortVersion ?? "1.0.0"
2323
) {
24-
self.storage = storage
24+
self.repository = repository
2525
self.currentVersion = currentVersion
2626
}
27-
27+
2828
public func callAsFunction(configuration: RatingPromptConfiguration) async -> Bool {
29-
let data = await storage.getRatingPromptData()
29+
let data = await repository.getRatingPromptData()
3030

3131
guard !data.hasBeenPromptedForCurrentVersion(currentVersion) else {
3232
return false
@@ -42,10 +42,3 @@ public struct ShouldShowRatingPromptUseCase: ShouldShowRatingPromptUseCaseProtoc
4242
return hasEnoughAppLaunches || hasEnoughSignificantEvents
4343
}
4444
}
45-
46-
extension ShouldShowRatingPromptUseCase {
47-
48-
public static func defaultCurrentVersion() -> String {
49-
Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "1.0.0"
50-
}
51-
}

template/Tuist/Interfaces/SwiftUI/Sources/Application/Dependencies/Container+Application.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ extension Container {
1313
}
1414

1515
var shouldShowRatingPromptUseCase: Factory<ShouldShowRatingPromptUseCaseProtocol> {
16-
self { ShouldShowRatingPromptUseCase(storage: self.ratingPromptStorage()) }
16+
self { ShouldShowRatingPromptUseCase(repository: self.ratingPromptRepository()) }
1717
}
1818

1919
var requestRatingPromptUseCase: Factory<RequestRatingPromptUseCaseProtocol> {
2020
self {
2121
RequestRatingPromptUseCase(
22-
storage: self.ratingPromptStorage(),
22+
repository: self.ratingPromptRepository(),
2323
shouldShowRatingPromptUseCase: self.shouldShowRatingPromptUseCase(),
2424
presenter: self.ratingPromptPresenter()
2525
)

0 commit comments

Comments
 (0)