User Tools

Site Tools


script_webview_with_refresh

====== Differences ====== This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
script_webview_with_refresh [2015/05/17 19:26]
jappie [WV-resume] corrected var nu
script_webview_with_refresh [2015/05/20 14:44] (current)
jappie [WV-resume] reload reloaded
Line 6: Line 6:
 ====== How to use the script ====== ====== How to use the script ======
   * make sure the Internet permission is added to the launcher through the installation of the plugin found at [[http://​www.pierrox.net/​android/​applications/​lightning_launcher/​permissions/​|http://​www.pierrox.net/​android/​applications/​lightning_launcher/​permissions/​]].   * make sure the Internet permission is added to the launcher through the installation of the plugin found at [[http://​www.pierrox.net/​android/​applications/​lightning_launcher/​permissions/​|http://​www.pierrox.net/​android/​applications/​lightning_launcher/​permissions/​]].
-  * Import ​the script'​s from here. +  * Import ​all three script'​s from here. 
-  * Set '​WV-create'​ script on Custom View '​created'​ event. +  * Set '​WV-create'​ script on  Custom View '​created'​-event. 
-  * Set '​WV-resume'​ script ​to event resume +  * Set '​WV-resume'​ script ​on  Custom View 'resume'​-event. 
-  * Set '​WV-pause'​ script ​to event pause+  * Set '​WV-pause' ​ script ​on  Custom View 'pause'​-event.
  
 ====== Script code ====== ====== Script code ======
Line 39: Line 39:
 <​code>​ <​code>​
 var refresh_interval_minutes = 60; var refresh_interval_minutes = 60;
- 
  
 var myItem = LL.getEvent().getItem();​ var myItem = LL.getEvent().getItem();​
 var myId   = myItem.getId();​ var myId   = myItem.getId();​
 var myView = myItem.getView();​ var myView = myItem.getView();​
-var last   = myItem.getTag(myId)||0;​ 
  
 function refreshWV() ​ function refreshWV() ​
 { // prevent event flooding { // prevent event flooding
   var nu   = new Date();   var nu   = new Date();
 +  var last = myItem.getTag(myId)||0;​
 +
   if ((nu - last) > (refresh_interval_minutes *60000))   if ((nu - last) > (refresh_interval_minutes *60000))
-  { myView.reload();​+  { //myView.reload(); <-- seams to crash when it failed to load before. 
 +    //​myView.loadUrl(myView.getUrl());​ <-- alternative,​ if everything else fails 
 +    myView.loadUrl( "​javascript:​window.location.reload( true )" ​);
     myItem.setTag(myId,​ nu);     myItem.setTag(myId,​ nu);
 +  }  ​
   // store the timeout id so that it can be cleared when pausing the item   // store the timeout id so that it can be cleared when pausing the item
     myItem.setTag("​WV",​ setTimeout(refreshWV,​ 30000));     myItem.setTag("​WV",​ setTimeout(refreshWV,​ 30000));
  
-}+
  
 refreshWV();​ refreshWV();​
 </​code>​ </​code>​
- 
 ======= WV-pause ======= ======= WV-pause =======
 <​code>​ <​code>​
script_webview_with_refresh.1431890806.txt.gz · Last modified: 2015/05/17 19:26 by jappie