From d5d9b38ed6d2b1f25c740272a8b2776d340a18ae Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Fri, 18 Mar 2022 18:36:49 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Reworked=20"Fix=20My=20Val?= =?UTF-8?q?et"=20to=20use=20built-in=20switcher?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PHP Monitor.xcodeproj/project.pbxproj | 4 +-- phpmon/Common/Core/Actions.swift | 26 ++++++-------------- phpmon/Domain/Menu/MainMenu+FixMyValet.swift | 14 +++++------ 3 files changed, 16 insertions(+), 28 deletions(-) diff --git a/PHP Monitor.xcodeproj/project.pbxproj b/PHP Monitor.xcodeproj/project.pbxproj index 22958eb..5a2b9f2 100644 --- a/PHP Monitor.xcodeproj/project.pbxproj +++ b/PHP Monitor.xcodeproj/project.pbxproj @@ -1302,7 +1302,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 720; + CURRENT_PROJECT_VERSION = 730; DEBUG = YES; DEVELOPMENT_TEAM = 8M54J5J787; ENABLE_HARDENED_RUNTIME = YES; @@ -1328,7 +1328,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 720; + CURRENT_PROJECT_VERSION = 730; DEBUG = NO; DEVELOPMENT_TEAM = 8M54J5J787; ENABLE_HARDENED_RUNTIME = YES; diff --git a/phpmon/Common/Core/Actions.swift b/phpmon/Common/Core/Actions.swift index 8346655..8d9f3fe 100644 --- a/phpmon/Common/Core/Actions.swift +++ b/phpmon/Common/Core/Actions.swift @@ -124,25 +124,13 @@ class Actions { If this does not solve the issue, the user may need to install additional extensions and/or run `composer global update`. */ - public static func fixMyValet() + public static func fixMyValet(completed: @escaping () -> Void) { - brew("services restart dnsmasq", sudo: true) - - PhpEnv.shared.detectPhpVersions().forEach { (version) in - let formula = (version == PhpEnv.brewPhpVersion) ? "php" : "php@\(version)" - brew("unlink php@\(version)") - brew("services stop \(formula)") - brew("services stop \(formula)", sudo: true) - } - - brew("services stop dnsmasq") - brew("services stop php") - brew("services stop nginx") - - brew("link php --overwrite --force") - - brew("services restart dnsmasq", sudo: true) - brew("services restart php", sudo: true) - brew("services restart nginx", sudo: true) + InternalSwitcher().performSwitch(to: PhpEnv.brewPhpVersion, completion: { + brew("services restart dnsmasq", sudo: true) + brew("services restart php", sudo: true) + brew("services restart nginx", sudo: true) + completed() + }) } } diff --git a/phpmon/Domain/Menu/MainMenu+FixMyValet.swift b/phpmon/Domain/Menu/MainMenu+FixMyValet.swift index cf1c532..c1e1067 100644 --- a/phpmon/Domain/Menu/MainMenu+FixMyValet.swift +++ b/phpmon/Domain/Menu/MainMenu+FixMyValet.swift @@ -32,13 +32,13 @@ extension MainMenu { return } - asyncExecution { - Actions.fixMyValet() - } success: { - if previousVersion == PhpEnv.brewPhpVersion { - self.presentAlertForSameVersion() - } else { - self.presentAlertForDifferentVersion(version: previousVersion) + Actions.fixMyValet { + DispatchQueue.main.async { + if previousVersion == PhpEnv.brewPhpVersion { + self.presentAlertForSameVersion() + } else { + self.presentAlertForDifferentVersion(version: previousVersion) + } } } }