prole/prole-app/Sources/PFScriptBridge.swift
chrisfu d1e4cb5db3 Remove inline shell from app; bundle external init script; fix build and packaging
•
Strip all embedded shell from LaunchAgentManager.swift; use external etc/init-port-fowards.sh copied from app Resources at runtime; set executable perms
•
Set defaultHelperScript to empty to eliminate inline script
•
Build script: bundle init-port-fowards.sh into Prole.app/Contents/Resources and chmod +x; capture spm_build_binary path via tail -n1
•
Fix malformed multiline XML in PortMappingsXML.save()
•
Preferences: handle new .agentPF tab in didSelect and windowDidResize
Result: Prole.app builds cleanly on arm64; no inline shell remains; embedded dylibs packaged and codesigned
2025-12-15 00:39:52 -08:00

43 lines
1.6 KiB
Swift

import Foundation
// Thin wrapper to call etc/init-port-fowards.sh for status/restart.
enum PFScriptBridge {
private static var scriptURL: URL {
// Resolve script path:
// 1) PROLE_HOME env var if set
// 2) default to ~/dev/prole (matches existing scripts)
let env = ProcessInfo.processInfo.environment
let fm = FileManager.default
if let home = env["PROLE_HOME"], !home.isEmpty {
return URL(fileURLWithPath: home).appendingPathComponent("etc/init-port-fowards.sh")
}
let defaultHome = fm.homeDirectoryForCurrentUser.appendingPathComponent("dev/prole")
return defaultHome.appendingPathComponent("etc/init-port-fowards.sh")
}
@discardableResult
static func restart() -> (code: Int32, out: String, err: String) {
return runScript(arg: "restart")
}
static func status() -> (code: Int32, out: String, err: String) {
return runScript(arg: "status")
}
private static func runScript(arg: String) -> (code: Int32, out: String, err: String) {
let p = Process()
p.executableURL = scriptURL
p.arguments = [arg]
let outPipe = Pipe(); let errPipe = Pipe()
p.standardOutput = outPipe
p.standardError = errPipe
do { try p.run() } catch {
return (-1, "", String(describing: error))
}
p.waitUntilExit()
let out = String(data: outPipe.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8) ?? ""
let err = String(data: errPipe.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8) ?? ""
return (p.terminationStatus, out, err)
}
}