Skip to content

Commit

Permalink
After we successfully clean, we sometimes ask for review
Browse files Browse the repository at this point in the history
  • Loading branch information
vashpan committed Aug 31, 2019
1 parent 8d66ba9 commit 285266e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
4 changes: 4 additions & 0 deletions DevCleaner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
7110B4992030F17B00EDBFA3 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7110B4972030F17B00EDBFA3 /* Main.storyboard */; };
712F999E20D65229003927BC /* Donations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 712F999D20D65229003927BC /* Donations.swift */; };
712F99A020D6810A003927BC /* MessageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 712F999F20D6810A003927BC /* MessageView.swift */; };
7140B617231A81DC005768A7 /* ReviewRequests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7140B616231A81DC005768A7 /* ReviewRequests.swift */; };
714AB65F22DA87FA00A7FBB7 /* DeviceLogsFileEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 714AB65E22DA87FA00A7FBB7 /* DeviceLogsFileEntry.swift */; };
7155325E2061AFD80025EB75 /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7155325D2061AFD80025EB75 /* Logger.swift */; };
715E8C3D216566FD0059A2E5 /* Weak.swift in Sources */ = {isa = PBXBuildFile; fileRef = 715E8C3C216566FD0059A2E5 /* Weak.swift */; };
Expand Down Expand Up @@ -63,6 +64,7 @@
7110B49B2030F17B00EDBFA3 /* DevCleaner.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = DevCleaner.entitlements; sourceTree = "<group>"; };
712F999D20D65229003927BC /* Donations.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Donations.swift; sourceTree = "<group>"; };
712F999F20D6810A003927BC /* MessageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageView.swift; sourceTree = "<group>"; };
7140B616231A81DC005768A7 /* ReviewRequests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReviewRequests.swift; sourceTree = "<group>"; };
714AB65E22DA87FA00A7FBB7 /* DeviceLogsFileEntry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceLogsFileEntry.swift; sourceTree = "<group>"; };
7155325D2061AFD80025EB75 /* Logger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = "<group>"; };
715E8C3C216566FD0059A2E5 /* Weak.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Weak.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -189,6 +191,7 @@
7162E12C209905BC00081E4E /* Preferences.swift */,
712F999D20D65229003927BC /* Donations.swift */,
718D4ABD23140ABA001E9382 /* Files.swift */,
7140B616231A81DC005768A7 /* ReviewRequests.swift */,
);
path = Managers;
sourceTree = "<group>";
Expand Down Expand Up @@ -417,6 +420,7 @@
7155325E2061AFD80025EB75 /* Logger.swift in Sources */,
71FD37D7206AD6BE0042812D /* ArchiveFileEntry.swift in Sources */,
71C8ACE020A62B8000E7A13B /* ScanReminders.swift in Sources */,
7140B617231A81DC005768A7 /* ReviewRequests.swift in Sources */,
7100BEE222F6E771002E82B2 /* Signposts.swift in Sources */,
716667D0221A26BA004D4FC4 /* FileManager+HomeFolder.swift in Sources */,
718D4ABE23140ABA001E9382 /* Files.swift in Sources */,
Expand Down
18 changes: 18 additions & 0 deletions DevCleaner/Managers/Preferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public final class Preferences {
public static let notificationsPeriod = "DCNotificationsPeriodKey"
public static let dryRunEnabled = "DCDryRunEnabledKey"
public static let totalBytesCleaned = "DCTotalBytesCleaned"
public static let cleansSinceLastReview = "DCCleansSinceLastReview"
public static let customArchivesFolder = "DCCustomArchivesFolderKey"
public static let customDerivedDataFolder = "DCCustomDerivedDataFolderKey"
public static let appFolder = "DCAppFolder"
Expand Down Expand Up @@ -157,6 +158,23 @@ public final class Preferences {
}
}

public var cleansSinceLastReview: Int {
get {
if let value = UserDefaults.standard.object(forKey: Keys.cleansSinceLastReview) as? NSNumber {
return value.intValue
}

return 0
}

set {
let numberValue = NSNumber(value: newValue)
UserDefaults.standard.set(numberValue, forKey: Keys.cleansSinceLastReview)

self.informAllObserversAboutChange(keyThatChanged: Keys.cleansSinceLastReview)
}
}

public var customArchivesFolder: URL? {
get {
if let archivesPath = UserDefaults.standard.object(forKey: Keys.customArchivesFolder) as? String {
Expand Down
35 changes: 35 additions & 0 deletions DevCleaner/Managers/ReviewRequests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// ReviewRequests.swift
// DevCleaner
//
// Created by Konrad Kołakowski on 31/08/2019.
// Copyright © 2019 One Minute Games. All rights reserved.
//

import Foundation
import StoreKit

public final class ReviewRequests {
// MARK: Properties
public static let shared = ReviewRequests()

// MARK: Constants
private static let bytesNeededForReviewRequest: Int64 = 20 * 1024 * 1024 * 1024 // 20GB
private static let cleansNeededForReviewRequest = 3

// MARK: Showing review request
public func requestReviewIfNeeded() {
let totalBytesCleaned = Preferences.shared.totalBytesCleaned
let totalCleansPerformedSinceLastRequest = Preferences.shared.cleansSinceLastReview

// desired rules:
// we show it either if we passed TOTAL of 20GB of cleaned bytes, which may be even on the first run of the app
// or, if we clean smaller amounts, after 3 cleans
// after we pass those 20GB total cleaned amount, we ask everytime we clean basically
if totalBytesCleaned > ReviewRequests.bytesNeededForReviewRequest || totalCleansPerformedSinceLastRequest >= ReviewRequests.cleansNeededForReviewRequest {
SKStoreReviewController.requestReview()

Preferences.shared.cleansSinceLastReview = 0
}
}
}

0 comments on commit 285266e

Please sign in to comment.