diff --git a/phpmon/Common/Core/Paths.swift b/phpmon/Common/Core/Paths.swift index 822ed4d..e1287b5 100644 --- a/phpmon/Common/Core/Paths.swift +++ b/phpmon/Common/Core/Paths.swift @@ -86,6 +86,11 @@ public class Paths { return "\(shared.baseDir.rawValue)/etc" } + public static var caskroomPath: String { + return "\(shared.baseDir.rawValue)/Caskroom/" + + (App.identifier.contains(".dev") ? "phpmon-dev" : "phpmon") + } + // MARK: - Flexible Binaries // (these can be in multiple locations, so we scan common places because) // (PHP Monitor will not use the user's own PATH) diff --git a/phpmon/Domain/App/AppUpdater.swift b/phpmon/Domain/App/AppUpdater.swift index 6ef3c74..1d1177a 100644 --- a/phpmon/Domain/App/AppUpdater.swift +++ b/phpmon/Domain/App/AppUpdater.swift @@ -80,6 +80,7 @@ class AppUpdater { .withPrimary( text: "updater.alerts.buttons.install".localized, action: { vc in + self.cleanupCaskroom() self.prepareForDownload() vc.close(with: .OK) } @@ -158,6 +159,20 @@ class AppUpdater { } } + private func cleanupCaskroom() { + let path = Paths.caskroomPath + + if FileSystem.directoryExists(path) { + Log.info("Removing the Caskroom directory for PHP Monitor...") + do { + try FileSystem.remove(path) + Log.info("Removed the Caskroom directory at `\(path)`.") + } catch { + Log.err("Automatically removing the Caskroom directory at `\(path)` failed.") + } + } + } + // MARK: - Checking if Self-Updater Worked public static func checkIfUpdateWasPerformed() { diff --git a/phpmon/Domain/Integrations/Homebrew/HomebrewDiagnostics.swift b/phpmon/Domain/Integrations/Homebrew/HomebrewDiagnostics.swift index 659f870..6de663d 100644 --- a/phpmon/Domain/Integrations/Homebrew/HomebrewDiagnostics.swift +++ b/phpmon/Domain/Integrations/Homebrew/HomebrewDiagnostics.swift @@ -32,6 +32,7 @@ class HomebrewDiagnostics { */ public static var customCaskInstalled: Bool = { return installedTaps.contains("nicoverbruggen/cask") + && FileSystem.directoryExists(Paths.caskroomPath) }() /** diff --git a/phpmon/Domain/Menu/MainMenu+Startup.swift b/phpmon/Domain/Menu/MainMenu+Startup.swift index c8c5d4e..feb1d09 100644 --- a/phpmon/Domain/Menu/MainMenu+Startup.swift +++ b/phpmon/Domain/Menu/MainMenu+Startup.swift @@ -39,8 +39,8 @@ extension MainMenu { // Determine install method Log.info(HomebrewDiagnostics.customCaskInstalled - ? "[BREW] The app has probably been installed via Homebrew Cask." - : "[BREW] The app has probably been installed directly." + ? "[BREW] The app has been installed via Homebrew Cask." + : "[BREW] The app has been installed directly (optimal)." ) Log.info(HomebrewDiagnostics.usesNginxFullFormula diff --git a/phpmon/Localizable.strings b/phpmon/Localizable.strings index 04260a2..6ede9f0 100644 --- a/phpmon/Localizable.strings +++ b/phpmon/Localizable.strings @@ -624,8 +624,8 @@ COMMON TROUBLESHOOTING TIPS "updater.alerts.newer_version_available.title" = "PHP Monitor v%@ is now available!"; "updater.alerts.newer_version_available.subtitle" = "Keeping PHP Monitor up-to-date is highly recommended, since newer versions usually fix bugs and include fixes to support the latest versions of Valet and PHP."; -"updater.installation_source.brew" = "The recommended method of installing updates to PHP Monitor is to simply press 'Install Update'.\n\n(You may also upgrade via the terminal by running `%@`, but this is not recommended.)"; -"updater.installation_source.direct" = "The recommended method of installing updates to PHP Monitor is to simply press 'Install Update'."; +"updater.installation_source.brew" = "The recommended method of installing updates to PHP Monitor is to simply press “Install Update”.\n\nSince you used Homebrew to install the app, you can also upgrade via the terminal by running `%@`, but this is not recommended.\n\n(Please note that installing via this built-in updater will remove PHP Monitor from Homebrew's Caskroom directory, to prevent duplicate updates from being downloaded and causing potential issues later.)"; +"updater.installation_source.direct" = "The recommended method of installing updates to PHP Monitor is to simply press “Install Update”."; "updater.alerts.buttons.release_notes" = "View Release Notes"; "updater.alerts.is_latest_version.title" = "PHP Monitor is up-to-date!";