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

♻️ PHP Guard changes

This commit is contained in:
2023-02-20 18:13:51 +01:00
parent 32a44524ef
commit 2d4112708e
2 changed files with 39 additions and 35 deletions

View File

@ -9,6 +9,7 @@
import Foundation import Foundation
import Cocoa import Cocoa
@MainActor
class BetterAlert { class BetterAlert {
var windowController: NSWindowController! var windowController: NSWindowController!

View File

@ -143,47 +143,50 @@ class Stats {
public static func evaluateLastLinkedPhpVersion() { public static func evaluateLastLinkedPhpVersion() {
guard let linked = PhpEnv.phpInstall else { guard let linked = PhpEnv.phpInstall else {
// TODO: Actually notify the user that no version is linked. return Log.warn("<PG> PHP Guard is unable to determine the current PHP version!")
Log.info("No version is currently linked.")
return
} }
let currentVersion = linked.version.short let currentVersion = linked.version.short
let previousVersion = Stats.lastGlobalPhpVersion let previousVersion = Stats.lastGlobalPhpVersion
// Save the PHP version that is currently in use (only if unknown) Log.info("<PG> The currently linked version of PHP is: \(currentVersion).")
if Stats.lastGlobalPhpVersion == "" {
if previousVersion == "" {
Stats.persistCurrentGlobalPhpVersion(version: currentVersion) Stats.persistCurrentGlobalPhpVersion(version: currentVersion)
Log.info("Persisting the currently linked PHP version (first time only).") return Log.warn("<PG> PHP Guard is saving the currently linked PHP version (first time only).")
} else { }
Log.info("Previously, the globally linked PHP version was: \(previousVersion).") Log.info("<PG> Previously, the globally linked PHP version was: \(previousVersion).")
if previousVersion != currentVersion {
Log.info("Currently, that version is: \(currentVersion). This is a mismatch.") if previousVersion == currentVersion {
Task { @MainActor in return Log.info("<PG> PHP Guard did not notice any changes in the linked PHP version.")
BetterAlert() }
.withInformation(
title: "startup.version_mismatch.title".localized, // At this point, the version is *not* a match
subtitle: "startup.version_mismatch.subtitle".localized( Log.info("<PG> PHP Guard noticed a different PHP version. An alert will be displayed!")
currentVersion,
previousVersion Task { @MainActor in
), BetterAlert()
description: "startup.version_mismatch.desc".localized() .withInformation(
) title: "startup.version_mismatch.title".localized,
.withPrimary(text: "startup.version_mismatch.button_switch_back".localized( subtitle: "startup.version_mismatch.subtitle".localized(
previousVersion currentVersion,
), action: { alert in previousVersion
alert.close(with: .OK) ),
Task { MainMenu.shared.switchToAnyPhpVersion(previousVersion) } description: "startup.version_mismatch.desc".localized()
}) )
.withTertiary(text: "startup.version_mismatch.button_stay".localized( .withPrimary(text: "startup.version_mismatch.button_switch_back".localized(
currentVersion previousVersion
), action: { alert in ), action: { alert in
Stats.persistCurrentGlobalPhpVersion(version: currentVersion) alert.close(with: .OK)
alert.close(with: .OK) Task { MainMenu.shared.switchToAnyPhpVersion(previousVersion) }
}) })
.show() .withTertiary(text: "startup.version_mismatch.button_stay".localized(
} currentVersion
} ), action: { alert in
Stats.persistCurrentGlobalPhpVersion(version: currentVersion)
alert.close(with: .OK)
})
.show()
} }
} }
} }