Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Profiles function #6

Open
trekkim opened this issue Jul 23, 2021 · 0 comments
Open

Add Profiles function #6

trekkim opened this issue Jul 23, 2021 · 0 comments

Comments

@trekkim
Copy link

trekkim commented Jul 23, 2021

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
    }

}

Screenshot 2021-07-23 at 15 06 33

Thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant