1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-08 04:20:07 +02:00

👌 Keep track of times (successfully) switched

Some users might not reboot their computer and in that situation they
will never see the message in bba961269c.

This has been remedied by also checking how many times the version
switch has occurred.

The thresholds for the alert are now:

- Must have launched the app at least 7 times
OR
- Must have switched PHP versions at least 40 times

If the alert has been seen, it'll never be shown again. For more info
please consult the linked commit for the rationale behind this change.
This commit is contained in:
2022-01-30 19:27:44 +01:00
parent 28fb685bfc
commit f2452bbc70
3 changed files with 39 additions and 13 deletions

View File

@ -279,6 +279,7 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate {
self.switchToPhpVersion(sender.version)
}
// TODO (5.1): Investigate if `waitAndExecute` cannot be used here
@objc func switchToPhpVersion(_ version: String) {
setBusyImage()
PhpEnv.shared.isBusy = true
@ -315,6 +316,9 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate {
} else {
sendLocalNotification()
}
Stats.incrementSuccessfulSwitchCount()
Stats.evaluateSponsorMessageShouldBeDisplayed()
}
}

View File

@ -27,6 +27,7 @@ enum PreferenceName: String {
*/
enum InternalStats: String {
case launchCount = "times_launched"
case switchCount = "times_switched_versions"
case didSeeSponsorEncouragement = "did_see_sponsor_encouragement"
}
@ -61,13 +62,15 @@ class Preferences {
*/
static func handleFirstTimeLaunch() {
UserDefaults.standard.register(defaults: [
/// Preferences
PreferenceName.shouldDisplayDynamicIcon.rawValue: true,
PreferenceName.shouldDisplayPhpHintInIcon.rawValue: true,
PreferenceName.fullPhpVersionDynamicIcon.rawValue: false,
PreferenceName.autoServiceRestartAfterExtensionToggle.rawValue: true,
PreferenceName.autoComposerGlobalUpdateAfterSwitch.rawValue: false,
PreferenceName.allowProtocolForIntegrations.rawValue: true,
///
/// Stats
InternalStats.switchCount.rawValue: 0,
InternalStats.launchCount.rawValue: 0,
InternalStats.didSeeSponsorEncouragement.rawValue: false
])

View File

@ -13,11 +13,10 @@ class Stats {
/**
Keep track of how many times the app has been successfully launched.
This is used to determine whether it is time to show the sponsor
encouragement alert, but I'd like to include this stat in the
preferences window as well. "PHP Monitor has been started X
times." If the count is over 99, it should say "Think about
all of the time the app has saved you!"
encouragement alert, but I'd like to include this stat somewhere
else as well.
*/
public static var successfulLaunchCount: Int {
UserDefaults.standard.integer(
@ -25,6 +24,20 @@ class Stats {
)
}
/**
Keep track of how many times the app has successfully switched
between different PHP versions.
This is used to determine whether it is time to show the sponsor
encouragement alert, but I'd like to include this stat somewhere
else as well.
*/
public static var successfulSwitchCount: Int {
UserDefaults.standard.integer(
forKey: InternalStats.switchCount.rawValue
)
}
/**
Did the user see the sponsor encouragement / thank you message?
Annoying the user is the worst, so let's not show the message twice.
@ -41,23 +54,29 @@ class Stats {
up the application.
*/
public static func incrementSuccessfulLaunchCount() {
let count = Stats.successfulLaunchCount
UserDefaults.standard.set(
count + 1,
Stats.successfulLaunchCount + 1,
forKey: InternalStats.launchCount.rawValue
)
}
/**
Increment the successful switch count.
*/
public static func incrementSuccessfulSwitchCount() {
UserDefaults.standard.set(
Stats.successfulSwitchCount + 1,
forKey: InternalStats.switchCount.rawValue
)
}
public static func evaluateSponsorMessageShouldBeDisplayed() {
if Stats.didSeeSponsorEncouragement {
Log.info("Awesome, the user has already seen the sponsor message.")
return
return Log.info("Awesome, the user has already seen the sponsor message.")
}
if Stats.successfulLaunchCount < 7 {
Log.info("It is too soon to see the sponsor message.")
Log.info("The application has been launched successfully \(Stats.successfulLaunchCount) times.")
return
if Stats.successfulLaunchCount < 7 && Stats.successfulSwitchCount < 40 {
return Log.info("It is too soon to see the sponsor message (launched \(Stats.successfulLaunchCount) times, switched \(Stats.successfulSwitchCount) times).")
}
DispatchQueue.main.async {