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

👌 Keep track of last used global PHP version

This commit is contained in:
2023-01-09 19:19:18 +01:00
parent d8738b685f
commit 3c946a53e8
6 changed files with 52 additions and 2 deletions

View File

@ -51,6 +51,9 @@ class InternalSwitcher: PhpSwitcher {
await brew("services restart nginx", sudo: true)
Log.info("The new version(s) have been linked!")
// Persist which formula is linked so we can check at launch
Stats.persistCurrentGlobalPhpVersion(version: PhpEnv.phpInstall.formula)
})
}

View File

@ -264,6 +264,5 @@ class Startup {
subtitleText: "startup.errors.valet_version_not_supported.subtitle".localized(Valet.shared.version.text),
descriptionText: "startup.errors.valet_version_not_supported.desc".localized
)
]
}

View File

@ -121,6 +121,9 @@ extension MainMenu {
// Check for updates
await AppUpdateChecker.checkIfNewerVersionIsAvailable()
// Check if the linked version has changed between launches of phpmon
Stats.evaluateLastLinkedPhpVersion()
// We are ready!
Log.info("PHP Monitor is ready to serve!")
}

View File

@ -107,4 +107,5 @@ enum InternalStats: String {
case launchCount = "times_launched"
case switchCount = "times_switched_versions"
case didSeeSponsorEncouragement = "did_see_sponsor_encouragement"
case lastGlobalPhpVersion = "last_global_php_version"
}

View File

@ -80,7 +80,8 @@ class Preferences {
/// Stats
InternalStats.switchCount.rawValue: 0,
InternalStats.launchCount.rawValue: 0,
InternalStats.didSeeSponsorEncouragement.rawValue: false
InternalStats.didSeeSponsorEncouragement.rawValue: false,
InternalStats.lastGlobalPhpVersion.rawValue: ""
])
if UserDefaults.standard.bool(forKey: PreferenceName.wasLaunchedBefore.rawValue) {

View File

@ -48,6 +48,10 @@ class Stats {
)
}
public static var lastGlobalPhpVersion: String {
UserDefaults.standard.string(forKey: InternalStats.lastGlobalPhpVersion.rawValue) ?? ""
}
/**
Increment the successful launch count. This should only be
called when the user has not encountered ANY issues starting
@ -70,6 +74,16 @@ class Stats {
)
}
/**
Persist which PHP version was active when you last used the app.
*/
public static func persistCurrentGlobalPhpVersion(version: String) {
UserDefaults.standard.set(
version,
forKey: InternalStats.lastGlobalPhpVersion.rawValue
)
}
/**
Determine if the sponsor message should be displayed.
@ -127,4 +141,33 @@ class Stats {
}
}
public static func evaluateLastLinkedPhpVersion() {
let currentVersion = PhpEnv.phpInstall.version.short
let previousVersion = Stats.lastGlobalPhpVersion
// TODO: Add a preference to disable this
// Save the PHP version that is currently in use (only if unknown)
if Stats.lastGlobalPhpVersion == "" {
Stats.persistCurrentGlobalPhpVersion(version: currentVersion)
Log.info("Persisting the currently linked PHP version (first time only).")
} else {
Log.info("Previously, the globally linked PHP version was: \(previousVersion).")
if previousVersion != currentVersion {
Log.info("Currently, that version is: \(currentVersion). This is a mismatch.")
Task { @MainActor in
BetterAlert()
.withInformation(
title: "startup.version_mismatch.title".localized,
subtitle: "startup.version_mismatch.subtitle".localized,
description: "startup.version_mismatch.desc".localized
)
.withPrimary(text: "OK")
// TODO: Add secondary button to switch to that version (if possible)
.show()
}
}
}
}
}