jasonelle-archive / jasonelle-v2

🛸 🏘️ Jasonelle issues, releases, discussions and wiki repository.
https://jasonelle.com
Mozilla Public License 2.0
422 stars 58 forks source link

$agent actions break success chaining #65

Open rolloclarke opened 5 years ago

rolloclarke commented 5 years ago

Describe the bug If an action triggers another action which is of type $agent.request and $return.success is returned, the original action's success is never executed.

So the yay success alert of action1 is never executed:

"action1": {
    "type": "trigger",
    "options": {
        "name": "action2"
    },
    "success": {
        "type": "$util.alert",
        "options": {
            "title": "YAY",
            "description": "yay"
        }
    }
},
"action2": {
    "type": "$agent.request",
    "options": {
        "id": "someid",
        "method": "whatever"
    },
    "success": {
        "type": "$return.success"
    }
}

This is true of all agent actions not just $agent.request

The problem is In JasonAgentAction the caller event object is ignored, and never passed through to the JasonAgentService, and so all the JasonHelper.next(...) calls are made with empty event objects.

clsource commented 5 years ago

thanks for reporting :)

clsource commented 3 years ago

Upon some testing it seems that At least Android needs a little time. Around 100 ms before responding to an action so the system can process it.

Example from $media.permissions

// We need at least 100 ms to call the success with the result
            // If not then it will be omitted since it will too fast 
            // for the system to process.
            new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
                @Override
                public void run() {
                    try {
                        JSONObject ret = new JSONObject();
                        ret.put("files", ContextCompat.checkSelfPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED);
                        ret.put("camera", ContextCompat.checkSelfPermission(context, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED);
                        JasonHelper.next("success", action, ret, event, context);
                    }  catch (Exception e) {
                        Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString());
                    }
                }
            }, 100); // Millisecond 1000 = 1 sec

https://raw.githubusercontent.com/jasonelle/jasonette-android/f1329f999a29e39bba53cdd78066d3ed2ff315e1/app/src/main/java/com/jasonette/seed/Action/JasonMediaAction.java