I made it even better. Forget about needing a "reloader" app for every app you want to refresh. One is enough. Here's how, for anyone who may be interested:
- Create a bare app with no components or queries.
- Take note of this app's Uuid, by inspecting and copying the retoolContext.appUuid global (at the bottom of the left inspector pane).
- On the main screen, add a Screen Event handler, set it to "Load" and "Run Script".
- Add in the following script that reads a value from local storage:
- Go to the app you want to add reload functionality to and create an action wherever you want to trigger the reload from. For me, it's a left action for the main app screen, and it's set to run the following script:
navigator.openApp("MYAPPUUID"); //replace MYAPPUID with the actual uuid of Force Reloader app from retoolContext global
- That's it, give it a try.
The logic is simple. We create an action that first sets a value in localstorage with the current app's uuid, then we open the reloader app. The reloader app reads the previous app id value from localstorage and opens the app corresponding to that appid.
If you want to add reload functionality to another app, simply redo the above step 4 in that app.
It's important mentioning that now every time you will attempt to open or even edit the Reloader app, it will redirect to whatever app uuid was last set as value in localstorage. There are ways to overcome this, but it would probably be best to add in a flag check to determine whether the redirect/reload should happen.
Thus, the script in step 4 should have a new line added:
navigator.openApp("*MYAPPUUID*"); //replace *MYAPPUID* with the actual uuid of Force Reloader app from retoolContext global
And the screen load event in step 5 (in the reloader app), should include a condition to run only when the disableRedirect flag is false (or otherwise put, do not run if disableRedirect flag is true).
With this approach, if you ever need to make further changes to the reloader app, simply modify the code of step 4 (of any app you added reload functionality to) by setting the disableRedirectToApp flag to true, and tapping the associated action that calls the reloader app.
This will cause the run condition of the screen load event of the reloader app to fail, allowing you to open the reloader app without it automatically redirecting to another app.
To restore reload functionalityafter, remember to switch back the localStorage.disableRedirectToApp flag to false.