I want to open a text file where all the Licence stuff is written down, I want to do it like this in a macOS app, but the app Bundle does not work for some reason:
import SwiftUI
@main
struct menuHelpApp: App {
func androidTools(tool: URL, arguments: [String], completionHandler: @escaping (Int32, Data) -> Void) throws {
let group = DispatchGroup()
let pipe = Pipe()
var standardOutData = Data()
group.enter()
let proc = Process()
proc.executableURL = tool
proc.arguments = arguments
proc.standardOutput = pipe.fileHandleForWriting
proc.terminationHandler = { _ in
proc.terminationHandler = nil
group.leave()
}
group.enter()
DispatchQueue.global().async {
let data = pipe.fileHandleForReading.readDataToEndOfFile()
pipe.fileHandleForReading.closeFile()
DispatchQueue.main.async {
standardOutData = data
group.leave()
}
}
group.notify(queue: .main) {
completionHandler(proc.terminationStatus, standardOutData)
}
try proc.run()
pipe.fileHandleForWriting.closeFile()
}
var body: some Scene {
WindowGroup {
ContentView()
}
.commands {
CommandGroup(replacing: .help) {
let licenceUrl = Bundle.main.url(forResource: "textFiles/Licence", withExtension: "txt")
Button(action: {
try! androidTools(tool: URL(fileURLWithPath: "/usr/bin/open", relativeTo: nil), arguments: ["-a", "TextEdit", licenceUrl!.absoluteString]) { (status, outputData) in
let output = String(data: outputData, encoding: .utf8) ?? ""
print(output)
}
}) {
Text("AppSignerGui License")
}
}
}
}
}