diff --git a/PHP Monitor.xcodeproj/project.pbxproj b/PHP Monitor.xcodeproj/project.pbxproj index 8c3103a..84f4124 100644 --- a/PHP Monitor.xcodeproj/project.pbxproj +++ b/PHP Monitor.xcodeproj/project.pbxproj @@ -373,7 +373,6 @@ C471E84828F9BB650021E251 /* EnvironmentCheck.swift in Sources */ = {isa = PBXBuildFile; fileRef = C495F5AE28A42E080087F70A /* EnvironmentCheck.swift */; }; C471E84A28F9BB650021E251 /* AppVersion.swift in Sources */ = {isa = PBXBuildFile; fileRef = C40FE736282ABA4F00A302C2 /* AppVersion.swift */; }; C471E84B28F9BB650021E251 /* ServicesManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = C45E76132854A65300B4FE0C /* ServicesManager.swift */; }; - C471E84C28F9BB650021E251 /* EnvironmentManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4A6957528D23EE300A14CF8 /* EnvironmentManager.swift */; }; C471E84D28F9BB650021E251 /* Valet+Alerts.swift in Sources */ = {isa = PBXBuildFile; fileRef = C40C7F2727721FF600DDDCDC /* Valet+Alerts.swift */; }; C471E84E28F9BB650021E251 /* MainMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4811D2922D70F9A00B5F6B3 /* MainMenu.swift */; }; C471E84F28F9BB650021E251 /* MainMenu+Startup.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4C3ED402783497000AB15D8 /* MainMenu+Startup.swift */; }; @@ -462,7 +461,6 @@ C471E8AB28F9BB8F0021E251 /* EnvironmentCheck.swift in Sources */ = {isa = PBXBuildFile; fileRef = C495F5AE28A42E080087F70A /* EnvironmentCheck.swift */; }; C471E8AD28F9BB8F0021E251 /* AppVersion.swift in Sources */ = {isa = PBXBuildFile; fileRef = C40FE736282ABA4F00A302C2 /* AppVersion.swift */; }; C471E8AE28F9BB8F0021E251 /* ServicesManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = C45E76132854A65300B4FE0C /* ServicesManager.swift */; }; - C471E8AF28F9BB8F0021E251 /* EnvironmentManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4A6957528D23EE300A14CF8 /* EnvironmentManager.swift */; }; C471E8B028F9BB8F0021E251 /* Valet+Alerts.swift in Sources */ = {isa = PBXBuildFile; fileRef = C40C7F2727721FF600DDDCDC /* Valet+Alerts.swift */; }; C471E8B128F9BB8F0021E251 /* MainMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4811D2922D70F9A00B5F6B3 /* MainMenu.swift */; }; C471E8B228F9BB8F0021E251 /* MainMenu+Startup.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4C3ED402783497000AB15D8 /* MainMenu+Startup.swift */; }; @@ -589,8 +587,6 @@ C495F5B028A42E080087F70A /* EnvironmentCheck.swift in Sources */ = {isa = PBXBuildFile; fileRef = C495F5AE28A42E080087F70A /* EnvironmentCheck.swift */; }; C4998F0A2617633900B2526E /* PreferencesWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4998F092617633900B2526E /* PreferencesWindowController.swift */; }; C4998F0B2617633900B2526E /* PreferencesWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4998F092617633900B2526E /* PreferencesWindowController.swift */; }; - C4A6957628D23EE300A14CF8 /* EnvironmentManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4A6957528D23EE300A14CF8 /* EnvironmentManager.swift */; }; - C4A6957728D23EE300A14CF8 /* EnvironmentManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4A6957528D23EE300A14CF8 /* EnvironmentManager.swift */; }; C4A81CA428C67101008DD9D1 /* PMTableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4A81CA328C67101008DD9D1 /* PMTableView.swift */; }; C4A81CA528C67101008DD9D1 /* PMTableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4A81CA328C67101008DD9D1 /* PMTableView.swift */; }; C4AC51FC27E27F47008528CA /* DomainListKindCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4AC51FB27E27F47008528CA /* DomainListKindCell.swift */; }; @@ -996,7 +992,6 @@ C4998F092617633900B2526E /* PreferencesWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesWindowController.swift; sourceTree = ""; }; C49EAA5129B12A5A00AB28FC /* Measurements.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Measurements.swift; sourceTree = ""; }; C49EAA5629B1689200AB28FC /* App+BrewWatch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "App+BrewWatch.swift"; sourceTree = ""; }; - C4A6957528D23EE300A14CF8 /* EnvironmentManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnvironmentManager.swift; sourceTree = ""; }; C4A81CA328C67101008DD9D1 /* PMTableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PMTableView.swift; sourceTree = ""; }; C4AC51FB27E27F47008528CA /* DomainListKindCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DomainListKindCell.swift; sourceTree = ""; }; C4ACA38E25C754C100060C66 /* PhpExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhpExtension.swift; sourceTree = ""; }; @@ -1725,7 +1720,6 @@ C4D8016522B1584700C6DA1B /* Startup.swift */, C495F5AE28A42E080087F70A /* EnvironmentCheck.swift */, C40FE736282ABA4F00A302C2 /* AppVersion.swift */, - C4A6957528D23EE300A14CF8 /* EnvironmentManager.swift */, C409349C298EE8E900D25014 /* AppUpdater.swift */, ); path = App; @@ -2329,7 +2323,6 @@ C45B914E295608E300F4EC78 /* ValetServicesManager.swift in Sources */, C4D5576429C77CC5001A44CD /* PhpVersionManagerWC.swift in Sources */, C4E49DED28F764A00026AC4E /* TestableCommand.swift in Sources */, - C4A6957628D23EE300A14CF8 /* EnvironmentManager.swift in Sources */, C41E871A2763D42300161EE0 /* DomainListVC+ContextMenu.swift in Sources */, C40C7F2827721FF600DDDCDC /* Valet+Alerts.swift in Sources */, C463E380284930EE00422731 /* PresetHelper.swift in Sources */, @@ -2510,7 +2503,6 @@ C471E84A28F9BB650021E251 /* AppVersion.swift in Sources */, C471E84B28F9BB650021E251 /* ServicesManager.swift in Sources */, C4D4CB3929C109CF00DB9F93 /* InternalSwitcher+Valet.swift in Sources */, - C471E84C28F9BB650021E251 /* EnvironmentManager.swift in Sources */, C471E84D28F9BB650021E251 /* Valet+Alerts.swift in Sources */, C471E84E28F9BB650021E251 /* MainMenu.swift in Sources */, C40934A4298EEB2C00D25014 /* CaskFile.swift in Sources */, @@ -2706,7 +2698,6 @@ C471E8AB28F9BB8F0021E251 /* EnvironmentCheck.swift in Sources */, C471E8AD28F9BB8F0021E251 /* AppVersion.swift in Sources */, C471E8AE28F9BB8F0021E251 /* ServicesManager.swift in Sources */, - C471E8AF28F9BB8F0021E251 /* EnvironmentManager.swift in Sources */, C471E8B028F9BB8F0021E251 /* Valet+Alerts.swift in Sources */, C471E8B128F9BB8F0021E251 /* MainMenu.swift in Sources */, C471E8B228F9BB8F0021E251 /* MainMenu+Startup.swift in Sources */, @@ -3046,7 +3037,6 @@ C4B79EB729CA387F00A483EE /* BrewFormulaeHandler.swift in Sources */, C4B5853F2770FE3900DA4FBE /* Paths.swift in Sources */, C481F79A26164A7C004FBCFF /* Preferences.swift in Sources */, - C4A6957728D23EE300A14CF8 /* EnvironmentManager.swift in Sources */, C4E0F7EE27BEBDA9007475F2 /* NSWindowExtension.swift in Sources */, C4A81CA528C67101008DD9D1 /* PMTableView.swift in Sources */, C45E76152854A65300B4FE0C /* ServicesManager.swift in Sources */, diff --git a/phpmon/Common/Core/Helpers.swift b/phpmon/Common/Core/Helpers.swift index e35af77..bd2a7f8 100644 --- a/phpmon/Common/Core/Helpers.swift +++ b/phpmon/Common/Core/Helpers.swift @@ -8,13 +8,6 @@ // MARK: Common Shell Commands -/** - Runs a `valet` command. Defaults to running as superuser. - */ -func valet(_ command: String, sudo: Bool = true) async -> String { - return await Shell.pipe("\(sudo ? "sudo " : "")" + "\(Paths.valet) \(command)").out -} - /** Runs a `brew` command. Can run as superuser. */ diff --git a/phpmon/Domain/App/App.swift b/phpmon/Domain/App/App.swift index 1803555..a73922a 100644 --- a/phpmon/Domain/App/App.swift +++ b/phpmon/Domain/App/App.swift @@ -62,9 +62,6 @@ class App { // MARK: Variables - /** Technical information about the current environment. */ - var environment = EnvironmentManager() - /** The list of preferences that are currently active. */ var preferences: [PreferenceName: Bool]! diff --git a/phpmon/Domain/App/EnvironmentManager.swift b/phpmon/Domain/App/EnvironmentManager.swift deleted file mode 100644 index 3d5788c..0000000 --- a/phpmon/Domain/App/EnvironmentManager.swift +++ /dev/null @@ -1,22 +0,0 @@ -// -// EnvironmentManager.swift -// PHP Monitor -// -// Created by Nico Verbruggen on 14/09/2022. -// Copyright © 2023 Nico Verbruggen. All rights reserved. -// - -import Foundation - -public class EnvironmentManager { - static var values: [EnvironmentProperty: Bool] = [:] - - public func process() async { - Self.values[.hasValetInstalled] = Valet.shared.installed - } -} - -public enum EnvironmentProperty { - case hasHomebrewInstalled - case hasValetInstalled -} diff --git a/phpmon/Domain/Menu/MainMenu+Startup.swift b/phpmon/Domain/Menu/MainMenu+Startup.swift index 8a71c15..cab3f64 100644 --- a/phpmon/Domain/Menu/MainMenu+Startup.swift +++ b/phpmon/Domain/Menu/MainMenu+Startup.swift @@ -18,8 +18,6 @@ extension MainMenu { self.setStatusBar(image: NSImage(named: NSImage.Name("StatusBarIcon"))!) } - await App.shared.environment.process() - if await Startup().checkEnvironment() { await self.onEnvironmentPass() } else { diff --git a/phpmon/Domain/Menu/MainMenu+Switcher.swift b/phpmon/Domain/Menu/MainMenu+Switcher.swift index 3efbefa..cafc6f1 100644 --- a/phpmon/Domain/Menu/MainMenu+Switcher.swift +++ b/phpmon/Domain/Menu/MainMenu+Switcher.swift @@ -28,7 +28,7 @@ extension MainMenu { updatePhpVersionInStatusBar() rebuild() - if !PhpEnvironments.shared.validate(version) { + if Valet.installed && !PhpEnvironments.shared.validate(version) { self.suggestFixMyValet(failed: version) return } @@ -46,7 +46,15 @@ extension MainMenu { } // Check if Valet still works correctly - self.checkForPlatformIssues() + if Valet.installed { + self.checkForPlatformIssues() + } + + // Check if the silent switch occurred and reset it + if shouldSwitchSilently { + shouldSwitchSilently = false + return + } // Update stats Stats.incrementSuccessfulSwitchCount() @@ -115,7 +123,6 @@ extension MainMenu { @MainActor private func notifyAboutVersionChange(to version: String) { if shouldSwitchSilently { - shouldSwitchSilently = false return }