first commit
This commit is contained in:
parent
a098b17f71
commit
ede81a0a6d
14 changed files with 184 additions and 3 deletions
|
@ -6,6 +6,96 @@
|
|||
//
|
||||
|
||||
import SwiftUI
|
||||
import Foundation
|
||||
|
||||
func oldshell(_ command: String) -> String {
|
||||
let task = Process()
|
||||
let pipe = Pipe()
|
||||
|
||||
task.standardOutput = pipe
|
||||
task.standardError = pipe
|
||||
task.arguments = ["-c", command]
|
||||
task.launchPath = "/bin/zsh"
|
||||
task.standardInput = nil
|
||||
task.launch()
|
||||
|
||||
let data = pipe.fileHandleForReading.readDataToEndOfFile()
|
||||
let output = String(data: data, encoding: .utf8)!
|
||||
return output
|
||||
}
|
||||
|
||||
func runShellCommandAsync(command: String, outputText: Binding<String>, showButton: Binding<Bool>?) {
|
||||
DispatchQueue.global(qos: .background).async {
|
||||
let task = Process()
|
||||
let pipe = Pipe()
|
||||
|
||||
task.standardOutput = pipe
|
||||
task.standardError = pipe
|
||||
task.arguments = ["-c", command]
|
||||
task.launchPath = "/bin/zsh"
|
||||
task.standardInput = nil
|
||||
|
||||
task.environment = [
|
||||
"GUILE_LOAD_PATH": "/opt/homebrew/share/guile/site/3.0:/usr/local/share/guile/site/3.0/",
|
||||
"GUILE_LOAD_COMPILED_PATH": "/opt/homebrew/lib/guile/3.0/site-ccache:/usr/local/lib/guile/3.0/site-ccache/",
|
||||
"GUILE_SYSTEM_EXTENSIONS_PATH": "/opt/homebrew/lib/guile/3.0/extensions:/usr/local/lib/guile/3.0/extensions/",
|
||||
"PATH": "$PATH:/opt/homebrew/bin:/usr/bin:/usr/local/bin:/bin"
|
||||
]
|
||||
|
||||
task.launch()
|
||||
|
||||
let fileHandle = pipe.fileHandleForReading
|
||||
fileHandle.waitForDataInBackgroundAndNotify()
|
||||
|
||||
var observer: NSObjectProtocol?
|
||||
|
||||
observer = NotificationCenter.default.addObserver(forName: .NSFileHandleDataAvailable, object: fileHandle, queue: nil) { _ in
|
||||
let data = fileHandle.availableData
|
||||
if let output = String(data: data, encoding: .utf8), !output.isEmpty {
|
||||
DispatchQueue.main.async {
|
||||
outputText.wrappedValue += output
|
||||
}
|
||||
}
|
||||
fileHandle.waitForDataInBackgroundAndNotify()
|
||||
}
|
||||
|
||||
task.waitUntilExit()
|
||||
|
||||
if let observer = observer {
|
||||
NotificationCenter.default.removeObserver(observer)
|
||||
}
|
||||
|
||||
if showButton != nil {
|
||||
showButton?.wrappedValue = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func shell(_ command: String) -> String {
|
||||
let task = Process()
|
||||
let pipe = Pipe()
|
||||
|
||||
task.standardOutput = pipe
|
||||
task.standardError = pipe
|
||||
task.arguments = ["-c", command]
|
||||
task.launchPath = "/bin/zsh"
|
||||
task.standardInput = nil
|
||||
|
||||
task.environment = [
|
||||
"GUILE_LOAD_PATH": "/opt/homebrew/share/guile/site/3.0:/usr/local/share/guile/site/3.0/",
|
||||
"GUILE_LOAD_COMPILED_PATH": "/opt/homebrew/lib/guile/3.0/site-ccache:/usr/local/lib/guile/3.0/site-ccache/",
|
||||
"GUILE_SYSTEM_EXTENSIONS_PATH": "/opt/homebrew/lib/guile/3.0/extensions:/usr/local/lib/guile/3.0/extensions/",
|
||||
"PATH": "$PATH:/opt/homebrew/bin:/usr/bin:/usr/local/bin:/bin"
|
||||
]
|
||||
|
||||
task.launch()
|
||||
|
||||
let data = pipe.fileHandleForReading.readDataToEndOfFile()
|
||||
let output = String(data: data, encoding: .utf8) ?? "Error reading output"
|
||||
|
||||
return output.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
}
|
||||
|
||||
|
||||
@main
|
||||
struct MSG_DesktopApp: App {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue