mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-10 05:00:06 +02:00
👌 Add runComposerUpdateShellCommand
method
This commit is contained in:
@@ -44,35 +44,40 @@ import Foundation
|
|||||||
|
|
||||||
private func performComposerUpdate() async {
|
private func performComposerUpdate() async {
|
||||||
do {
|
do {
|
||||||
let command = "\(Paths.composer!) global update"
|
try await runComposerUpdateShellCommand()
|
||||||
|
|
||||||
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()
|
|
||||||
}
|
|
||||||
} catch {
|
} catch {
|
||||||
composerUpdateFailed()
|
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() {
|
private func composerUpdateSucceeded() {
|
||||||
// Closing the window should happen after a slight delay
|
// Closing the window should happen after a slight delay
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { [self] in
|
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { [self] in
|
||||||
|
@@ -35,12 +35,14 @@ class TerminalProgressWindowController: NSWindowController, NSWindowDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public func addToConsole(_ string: String) {
|
public func addToConsole(_ string: String) {
|
||||||
guard let textView = self.progressView?.textView else {
|
DispatchQueue.main.async {
|
||||||
return
|
guard let textView = self.progressView?.textView else {
|
||||||
}
|
return
|
||||||
|
}
|
||||||
|
|
||||||
textView.string += string
|
textView.string += string
|
||||||
textView.scrollToEndOfDocument(nil)
|
textView.scrollToEndOfDocument(nil)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func setType(info: Bool = true) {
|
public func setType(info: Bool = true) {
|
||||||
|
Reference in New Issue
Block a user