mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-07 03:50:08 +02:00
👌 Add runComposerUpdateShellCommand
method
This commit is contained in:
@ -44,35 +44,40 @@ import Foundation
|
||||
|
||||
private func performComposerUpdate() async {
|
||||
do {
|
||||
let command = "\(Paths.composer!) global update"
|
||||
|
||||
DispatchQueue.main.async {
|
||||
self.window?.addToConsole("\(command)\n")
|
||||
}
|
||||
|
||||
let (process, _) = try await Shell.attach(
|
||||
command,
|
||||
didReceiveOutput: { [weak self] output in
|
||||
if output.hasError {
|
||||
DispatchQueue.main.async { self?.window?.addToConsole(output.err) }
|
||||
}
|
||||
if !output.out.isEmpty {
|
||||
DispatchQueue.main.async { self?.window?.addToConsole(output.out) }
|
||||
}
|
||||
},
|
||||
withTimeout: .minutes(5)
|
||||
)
|
||||
|
||||
if process.terminationStatus <= 0 {
|
||||
composerUpdateSucceeded()
|
||||
} else {
|
||||
composerUpdateFailed()
|
||||
}
|
||||
try await runComposerUpdateShellCommand()
|
||||
} catch {
|
||||
composerUpdateFailed()
|
||||
}
|
||||
}
|
||||
|
||||
private func runComposerUpdateShellCommand() async throws {
|
||||
let command = "\(Paths.composer!) global update"
|
||||
|
||||
self.window?.addToConsole("\(command)\n")
|
||||
|
||||
let (process, _) = try await Shell.attach(
|
||||
command,
|
||||
didReceiveOutput: { [weak self] output in
|
||||
guard let window = self?.window else { return }
|
||||
|
||||
if output.hasError {
|
||||
window.addToConsole(output.err)
|
||||
}
|
||||
|
||||
if !output.out.isEmpty {
|
||||
window.addToConsole(output.out)
|
||||
}
|
||||
},
|
||||
withTimeout: .minutes(5)
|
||||
)
|
||||
|
||||
if process.terminationStatus <= 0 {
|
||||
composerUpdateSucceeded()
|
||||
} else {
|
||||
composerUpdateFailed()
|
||||
}
|
||||
}
|
||||
|
||||
private func composerUpdateSucceeded() {
|
||||
// Closing the window should happen after a slight delay
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { [self] in
|
||||
|
@ -35,12 +35,14 @@ class TerminalProgressWindowController: NSWindowController, NSWindowDelegate {
|
||||
}
|
||||
|
||||
public func addToConsole(_ string: String) {
|
||||
guard let textView = self.progressView?.textView else {
|
||||
return
|
||||
}
|
||||
DispatchQueue.main.async {
|
||||
guard let textView = self.progressView?.textView else {
|
||||
return
|
||||
}
|
||||
|
||||
textView.string += string
|
||||
textView.scrollToEndOfDocument(nil)
|
||||
textView.string += string
|
||||
textView.scrollToEndOfDocument(nil)
|
||||
}
|
||||
}
|
||||
|
||||
public func setType(info: Bool = true) {
|
||||
|
Reference in New Issue
Block a user