After much testing, I found that the current event listeners for pwa in AS do not provide any advance notice of a reload. I did find, with using local 127.0.0,1 server, that pwa can take up to 10 seconds after initial start to perform the reload. EG, you might as well consider it can happen at anytime in your app.
The best way to hook into AS for PWA, in my opine, is to replace the location.reload(); in appstudioFunctions.js in the program files nsb/library folder. Any changes you make must be saved and AS restarted for them to take effect in a deploy.
I replaced the reload line with pwaReload(); and then added the following function to my code.js in the AS project code. (I also put a dummy pwaReload() function in asF that just does the reload, for projects where I’m not worried about this hook).
function pwaReload() {
alert('Reload about to happen');
location.reload();
};
and this worked very nice. However, if you turn the log persistence on in chrome console, you notice you get a violation error with xxx ms timeout is too long. 1) it’s just a warning 2) it’s caused by the alert. you really should not put a blocking function in an event handler and you’re getting warned about it. So, I decided to change it to a form notifying the user of the update. with a wait, so they have time to read it.
function pwaReload() {
ChangeForm(Reload, 'hide', 'show', 0);
setTimeout(ReloadTimer, 3000);
};
function ReloadTimer() {
location.reload();
};
This all looked just great. But when it executes it does not remove the original form. The current form style.display property during the event has the value none and the ChangeForm also sets it to none, without error. And ChangeForm sets the Reload form style.display to block, as it should, and the event sees this property correctly as none before it changes it to block, which the event handler can also see.
But, the actual style.display property of the current form was really block and it doesn’t get changed to none, it stays block. The result is the original form that was displayed has the Reload form appended to it. All other properties seem to be working fine.
To solve this temporarily, until someone figures out what I was doing wrong, etc. was to hide all of the children of the current form. This works, but I think it’s a bit ugly.
function pwaReload() {
for (pwaxi = 0; pwaxi < NSB.currentForm.childElementCount; pwaxi++) {
NSB.currentForm.children[pwaxi].style.display = 'none';
};
ChangeForm(Reload, 'hide', 'show', 0);
setTimeout(ReloadTimer, 3000);
};
function ReloadTimer() {
location.reload();
};
Does anyone have any ideas of why I can not set, nor AS ChangeForm can not set, the style.display property of the current form.
Thanks in advance.