mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-08 04:20:07 +02:00
✨ Parallelize unlinking PHP versions
This commit is contained in:
@ -218,6 +218,12 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
@objc func stopAllServices() {
|
||||
waitAndExecute {
|
||||
Actions.stopAllServices()
|
||||
}
|
||||
}
|
||||
|
||||
@objc func restartNginx() {
|
||||
waitAndExecute {
|
||||
Actions.restartNginx()
|
||||
@ -289,12 +295,7 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate {
|
||||
// Update the menu
|
||||
update()
|
||||
|
||||
// Switch the PHP version
|
||||
Actions.switchToPhpVersion(
|
||||
version: sender.version,
|
||||
availableVersions: App.shared.availablePhpVersions
|
||||
)
|
||||
|
||||
let completion = {
|
||||
// Mark as no longer busy
|
||||
App.shared.busy = false
|
||||
|
||||
@ -310,6 +311,14 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Switch the PHP version
|
||||
Actions.switchToPhpVersion(
|
||||
version: sender.version,
|
||||
availableVersions: App.shared.availablePhpVersions,
|
||||
completed: completion
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@objc func openAbout() {
|
||||
|
@ -78,6 +78,13 @@ class Actions {
|
||||
brew("services restart dnsmasq", sudo: true)
|
||||
}
|
||||
|
||||
public static func stopAllServices()
|
||||
{
|
||||
brew("services stop \(App.phpInstall!.formula)", sudo: true)
|
||||
brew("services stop nginx", sudo: true)
|
||||
brew("services stop dnsmasq", sudo: true)
|
||||
}
|
||||
|
||||
/**
|
||||
Switching to a new PHP version involves:
|
||||
- unlinking the current version
|
||||
@ -87,18 +94,42 @@ class Actions {
|
||||
Please note that depending on which version is installed,
|
||||
the version that is switched to may or may not be identical to `php` (without @version).
|
||||
*/
|
||||
public static func switchToPhpVersion(version: String, availableVersions: [String])
|
||||
{
|
||||
public static func switchToPhpVersion(
|
||||
version: String,
|
||||
availableVersions: [String],
|
||||
completed: @escaping () -> Void
|
||||
) {
|
||||
print("Switching to \(version)")
|
||||
let group = DispatchGroup()
|
||||
group.enter()
|
||||
|
||||
var versionsDisabled: [String: Bool] = [:]
|
||||
availableVersions.forEach { (available) in
|
||||
let formula = (available == App.shared.brewPhpVersion) ? "php" : "php@\(available)"
|
||||
brew("unlink \(formula)")
|
||||
brew("services stop \(formula)", sudo: true)
|
||||
versionsDisabled[available] = false
|
||||
}
|
||||
|
||||
let formula = (version == App.shared.brewPhpVersion) ? "php" : "php@\(version)"
|
||||
availableVersions.forEach { (available) in
|
||||
DispatchQueue.global(qos: .userInitiated).async {
|
||||
let formula = (available == App.shared.brewPhpVersion)
|
||||
? "php" : "php@\(available)"
|
||||
|
||||
brew("unlink \(formula)")
|
||||
brew("services stop \(formula)", sudo: true)
|
||||
|
||||
versionsDisabled[available] = true
|
||||
if !versionsDisabled.values.contains(false) {
|
||||
group.leave()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
group.notify(queue: .global(qos: .userInitiated)) {
|
||||
let formula = (version == App.shared.brewPhpVersion) ? "php" : "php@\(version)"
|
||||
brew("link \(formula) --overwrite --force")
|
||||
brew("services start \(formula)", sudo: true)
|
||||
|
||||
completed()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Finding Config Files
|
||||
|
@ -24,6 +24,7 @@
|
||||
"mi_restart_dnsmasq" = "Restart service: dnsmasq";
|
||||
"mi_restart_specific" = "Restart specific service";
|
||||
"mi_restart_all_services" = "Restart all services";
|
||||
"mi_stop_all_services" = "Stop all services";
|
||||
"mi_force_load_latest" = "Force load latest PHP version";
|
||||
"mi_php_refresh" = "Refresh information";
|
||||
|
||||
|
Reference in New Issue
Block a user