Description
Hi Erik,
I was thinking about maybe mobileconfig check will be as well interesting.
Here is some adjustment i did in your code, but still not working but maybe help, as i'm not really expert in Swift :-)
PrimaryStatus:
`// Stage Status (Dynamic Row)
struct StageRow: View {
@ObservedObject var settings: HelloHelper
var installstage: DeviceStage
@State var installedPkg = false
@State var installedProfile = false
var body: some View {
HStack {
// Icon
// TODO: Figure out how to refresh AsyncImage if it fails to download the first time
if #available(macOS 12.0, *) {
AsyncImage(url: URL(string: installstage.iconPath)) { image in
image.resizable()
} placeholder: {
Utils().randomPlaceholderColor()
.opacity(0)
}
.aspectRatio(contentMode: .fit)
.scaledToFit()
.frame(width: 40, height: 40)
} else {
WebImage(url: URL(string: installstage.iconPath))
.renderingMode(.original)
.resizable()
.aspectRatio(contentMode: .fit)
.scaledToFit()
.frame(width: 40, height: 40)
}
// Stage Name
Text(installstage.title)
.font(.body)
.fontWeight(.bold)
Spacer()
// Current Stage Status
if Utils().pathExists(path: installstage.installedPath) || PkgInfo(receipt: installstage.installedPath) , Profile(receipt: installstage.installedPath) {
Image(systemName: "checkmark.circle.fill")
.foregroundColor(.green)
Text("Completed")
.frame(width: 75)
.onAppear {
settings.applicationState[installstage.id] = "installed"
}
} else {
// First stage - auto trigger installing
if settings.applicationState.isEmpty && installstage.id == 1 {
ProgressView()
.progressViewStyle(.circular)
.scaleEffect(0.4)
Text("Installing")
.frame(width: 75)
.onAppear {
settings.applicationState[installstage.id] = "installing"
settings.applicationInstalling = installstage.title
settings.applicationInstallingIconPath = installstage.iconPath
}
// Stage has already sent its state - no need to resend
} else if settings.applicationState[installstage.id] == "installing" {
ProgressView()
.progressViewStyle(.circular)
.scaleEffect(0.4)
Text("Installing")
.frame(width: 75)
// Previous stage has completed - trigger installing
} else if settings.applicationState[installstage.id-1] == "installed" {
ProgressView()
.progressViewStyle(.circular)
.scaleEffect(0.4)
Text("Installing")
.frame(width: 75)
.onAppear {
settings.applicationState[installstage.id] = "installing"
settings.applicationInstalling = installstage.title
settings.applicationInstallingIconPath = installstage.iconPath
}
// Catchall for pending
} else {
Image(systemName: "checkmark.circle.fill")
.foregroundColor(.secondary)
Text("Pending")
.frame(width: 75)
.onAppear {
settings.applicationState[installstage.id] = "pending"
}
}
}
}
}
func PkgInfo(receipt: String) -> Bool {
DispatchQueue.main.async {
self.installedPkg = Utils().pkgInfo(receipt: receipt)
}
return self.installedPkg
}
func Profile(receipt: String) -> Bool {
DispatchQueue.main.async {
self.installedProfile = Utils().profiles(receipt: receipt)
}
return self.installedProfile
}
}`
Utils:
func profiles(receipt: String) -> Bool {
let task = Process()
task.launchPath = "/usr/bin/profiles"
task.arguments = ["-P", receipt]
let outputPipe = Pipe()
let errorPipe = Pipe()
task.standardOutput = outputPipe
task.standardError = errorPipe
do {
try task.run()
} catch {
let msg = "Error processing profiles"
print(msg)
return false
}
task.waitUntilExit()
if task.terminationStatus != 0 {
return false
} else {
return true
}
}
Thx