mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-07 20:10:08 +02:00
🐛 Introduce SLOW SHELL and fix a few issues
This commit is contained in:
@ -73,6 +73,11 @@
|
|||||||
value = ""
|
value = ""
|
||||||
isEnabled = "NO">
|
isEnabled = "NO">
|
||||||
</EnvironmentVariable>
|
</EnvironmentVariable>
|
||||||
|
<EnvironmentVariable
|
||||||
|
key = "SLOW_SHELL_MODE"
|
||||||
|
value = ""
|
||||||
|
isEnabled = "YES">
|
||||||
|
</EnvironmentVariable>
|
||||||
<EnvironmentVariable
|
<EnvironmentVariable
|
||||||
key = "PAINT_PHPMON_SWIFTUI_VIEWS"
|
key = "PAINT_PHPMON_SWIFTUI_VIEWS"
|
||||||
value = ""
|
value = ""
|
||||||
|
@ -11,12 +11,21 @@ import Foundation
|
|||||||
|
|
||||||
class Filesystem {
|
class Filesystem {
|
||||||
|
|
||||||
|
/**
|
||||||
|
Checks if a given path is a file *and* executable.
|
||||||
|
*/
|
||||||
|
public static func isExecutableFile(_ path: String) -> Bool {
|
||||||
|
return FileManager.default.isExecutableFile(
|
||||||
|
atPath: path.replacingTildeWithHomeDirectory
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Checks if a file or directory exists at the provided path.
|
Checks if a file or directory exists at the provided path.
|
||||||
*/
|
*/
|
||||||
public static func exists(_ path: String) -> Bool {
|
public static func exists(_ path: String) -> Bool {
|
||||||
return FileManager.default.fileExists(
|
return FileManager.default.fileExists(
|
||||||
atPath: path.replacingOccurrences(of: "~", with: Paths.homePath)
|
atPath: path.replacingTildeWithHomeDirectory
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,7 +35,7 @@ class Filesystem {
|
|||||||
public static func fileExists(_ path: String) -> Bool {
|
public static func fileExists(_ path: String) -> Bool {
|
||||||
var isDirectory: ObjCBool = true
|
var isDirectory: ObjCBool = true
|
||||||
let exists = FileManager.default.fileExists(
|
let exists = FileManager.default.fileExists(
|
||||||
atPath: path.replacingOccurrences(of: "~", with: Paths.homePath),
|
atPath: path.replacingTildeWithHomeDirectory,
|
||||||
isDirectory: &isDirectory
|
isDirectory: &isDirectory
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -39,7 +48,7 @@ class Filesystem {
|
|||||||
public static func directoryExists(_ path: String) -> Bool {
|
public static func directoryExists(_ path: String) -> Bool {
|
||||||
var isDirectory: ObjCBool = true
|
var isDirectory: ObjCBool = true
|
||||||
let exists = FileManager.default.fileExists(
|
let exists = FileManager.default.fileExists(
|
||||||
atPath: path.replacingOccurrences(of: "~", with: Paths.homePath),
|
atPath: path.replacingTildeWithHomeDirectory,
|
||||||
isDirectory: &isDirectory
|
isDirectory: &isDirectory
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -59,3 +68,11 @@ class Filesystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension String {
|
||||||
|
|
||||||
|
var replacingTildeWithHomeDirectory: String {
|
||||||
|
return self.replacingOccurrences(of: "~", with: Paths.homePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -27,7 +27,9 @@ class PhpHelper {
|
|||||||
|
|
||||||
Task { // Create the appropriate folders and check if the files exist
|
Task { // Create the appropriate folders and check if the files exist
|
||||||
do {
|
do {
|
||||||
await Shell.quiet("mkdir -p ~/.config/phpmon/bin")
|
if !Filesystem.directoryExists("~/.config/phpmon/bin") {
|
||||||
|
await Shell.quiet("mkdir -p ~/.config/phpmon/bin")
|
||||||
|
}
|
||||||
|
|
||||||
if Filesystem.fileExists(destination) {
|
if Filesystem.fileExists(destination) {
|
||||||
let contents = try String(contentsOfFile: destination)
|
let contents = try String(contentsOfFile: destination)
|
||||||
@ -62,7 +64,9 @@ class PhpHelper {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Make sure the file is executable
|
// Make sure the file is executable
|
||||||
await Shell.quiet("chmod +x \(destination)")
|
if !Filesystem.isExecutableFile(destination) {
|
||||||
|
await Shell.quiet("chmod +x \(destination)")
|
||||||
|
}
|
||||||
|
|
||||||
// Create a symlink if the folder is not in the PATH
|
// Create a symlink if the folder is not in the PATH
|
||||||
if !inPath {
|
if !inPath {
|
||||||
|
@ -85,6 +85,10 @@ class PhpExtension {
|
|||||||
await sed(file: file, original: line, replacement: newLine)
|
await sed(file: file, original: line, replacement: newLine)
|
||||||
|
|
||||||
enabled.toggle()
|
enabled.toggle()
|
||||||
|
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
MainMenu.shared.rebuild(async: false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Static Methods
|
// MARK: - Static Methods
|
||||||
|
@ -88,6 +88,14 @@ class SystemShell: Shellable {
|
|||||||
let outputPipe = Pipe()
|
let outputPipe = Pipe()
|
||||||
let errorPipe = Pipe()
|
let errorPipe = Pipe()
|
||||||
|
|
||||||
|
// Seriously slow down how long it takes for the shell to return output
|
||||||
|
// (in order to debug or identify async issues)
|
||||||
|
if ProcessInfo.processInfo.environment["SLOW_SHELL_MODE"] != nil {
|
||||||
|
print("[SLOW SHELL] \(command)")
|
||||||
|
let delayInSeconds = 3
|
||||||
|
try! await Task.sleep(nanoseconds: UInt64(delayInSeconds * 1_000_000_000))
|
||||||
|
}
|
||||||
|
|
||||||
task.standardOutput = outputPipe
|
task.standardOutput = outputPipe
|
||||||
task.standardError = errorPipe
|
task.standardError = errorPipe
|
||||||
task.launch()
|
task.launch()
|
||||||
|
@ -99,7 +99,6 @@ class TestableConfigurations {
|
|||||||
: .instant("Unable to find application named 'Sublime Merge'", .stdErr),
|
: .instant("Unable to find application named 'Sublime Merge'", .stdErr),
|
||||||
"/usr/bin/open -Ra \"iTerm\""
|
"/usr/bin/open -Ra \"iTerm\""
|
||||||
: .instant("Unable to find application named 'iTerm'", .stdErr),
|
: .instant("Unable to find application named 'iTerm'", .stdErr),
|
||||||
|
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -33,8 +33,15 @@ public class TestableShell: Shellable {
|
|||||||
didReceiveOutput: @escaping (String, ShellStream) -> Void,
|
didReceiveOutput: @escaping (String, ShellStream) -> Void,
|
||||||
withTimeout timeout: TimeInterval
|
withTimeout timeout: TimeInterval
|
||||||
) async throws -> (Process, ShellOutput) {
|
) async throws -> (Process, ShellOutput) {
|
||||||
// TODO: Add delay to track down issues
|
|
||||||
// TODO: Remove assertion
|
// Seriously slow down the shell's return rate in order to debug or identify async issues
|
||||||
|
if ProcessInfo.processInfo.environment["SLOW_SHELL_MODE"] != nil {
|
||||||
|
print("[SLOW SHELL] \(command)")
|
||||||
|
let delayInSeconds = 3
|
||||||
|
try! await Task.sleep(nanoseconds: UInt64(delayInSeconds * 1_000_000_000))
|
||||||
|
}
|
||||||
|
|
||||||
|
// This assertion will only fire during test builds
|
||||||
assert(expectations.keys.contains(command), "No response declared for command: \(command)")
|
assert(expectations.keys.contains(command), "No response declared for command: \(command)")
|
||||||
|
|
||||||
guard let expectation = expectations[command] else {
|
guard let expectation = expectations[command] else {
|
||||||
|
@ -118,6 +118,6 @@ extension MainMenu {
|
|||||||
preference: .notifyAboutVersionChange
|
preference: .notifyAboutVersionChange
|
||||||
)
|
)
|
||||||
|
|
||||||
Task { await PhpEnv.phpInstall.notifyAboutBrokenPhpFpm() }
|
Task { PhpEnv.phpInstall.notifyAboutBrokenPhpFpm() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,9 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate, PhpSwitcherDelegate
|
|||||||
@MainActor @objc func reloadPhpMonitorMenuInForeground() async {
|
@MainActor @objc func reloadPhpMonitorMenuInForeground() async {
|
||||||
refreshActiveInstallation()
|
refreshActiveInstallation()
|
||||||
refreshIcon()
|
refreshIcon()
|
||||||
rebuild(async: false)
|
DispatchQueue.main.async {
|
||||||
|
self.rebuild(async: false)
|
||||||
|
}
|
||||||
await ServicesManager.loadHomebrewServices()
|
await ServicesManager.loadHomebrewServices()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user