Javascript pre-install script

EJ
Emanuel Jonsson
Gunnar Dafgård AB

I'm hoping someone can help me with this example script to be used as pre-install script in package studio to give the users a choise to click install when I update an app

I want to know where I should put in the bundleID or package name.

We can say that I want this to be used on soti surf (net.soti.surf).

#!/usr/bin/env js
var FIVE_MINUTES = 5 * 60 * 1000;
var ONE_HOUR = 60 * 60 * 1000;
var buttonLabels = ['Install now', 'Install in 5 minutes', 'Install in 1 hour'];

if (isAppRunningInForeground('com.acme.importantapp')) {
    mobicontrol.message.createInfoDialog('Would you like to install ImportantApp?')
        .withButtons(buttonLabels[0], buttonLabels[1], buttonLabels[2])
        .withCallback(onConfirm).show();
}

function onConfirm(result) {
    if (result.buttonIndex != null) {
        switch (buttonLabels[result.buttonIndex]) {
            case 'Install now':
                installImportantPcg();
                break;
            case 'Install in 5 minutes':
                setTimeout(installImportantPcg, FIVE_MINUTES);
                break;
            case 'Install in 1 hour':
                setTimeout(installImportantPcg, ONE_HOUR);
                break;
         }
    }
}

function installImportantPcg() {
    // Do nothing - the normal return from the script will launch the package installation
}

function isAppRunningInForeground(app) {
    return mobicontrol.app.foregroundActivities.filter(activity => activity.packageName == app).length > 0;
}

6 months ago
Android
ANSWERS
MD
Matt Dermody Diamond Contributor
6 months ago

Your pre-install script here is effectively just prompting the user to see if they want to pause the the install of the Package that is inevitably going to happen after the pre-install script continues executing. I don't think you need to reference the package name or bundle ID of the app that you're installing at all because the script itself is not performing the install, the script is just pausing the install. The install happens after the script completes as you'd have the APK in the package itself.

EJ
Emanuel Jonsson
6 months ago

I see. 

So for this to work I need to send the apk to the device and then run the script?

MD
Matt Dermody Diamond Contributor
6 months ago

No. It's a pre-install script. So you have a Package, with this script, configured to Pre-install, and then include the APK in the same Package as the primary payload. The Package will install the APK for you after the Pre-install script runs. 

K
KAMOD@soti.net
6 months ago

Hi Emanuel,

Thanks for posting on SOTI Pulse.  Thanks, Matt, for responding to the post. Your expertise and willingness to help are greatly appreciated!

Has your query been resolved? If this post did not assist you in resolving the issue completely, and you have additional questions, please do not hesitate to reach out or you can contact SOTI Support (support@soti.net) to open a new case, and one of our support engineers will be there to assist you.

Kind Regards
Technical Support | SOTI Inc. |1.905.624.9828 | support@soti.net | www.soti.net |

Similar Discussions