User Tools

Site Tools


script_external_editor_script_importer

====== 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_external_editor_script_importer [2015/04/11 01:56]
cdfa
script_external_editor_script_importer [2017/07/06 13:15] (current)
cdfa 1.3
Line 1: Line 1:
 ====== About the script ====== ====== About the script ======
-  * Purpose : automatically import .js files elsewhere on your device into lightning launcher when they have changed. This allows you to use external script editors! +  * Purpose: automatically import .js files elsewhere on your device into lightning launcher when they have changed. This allows you to use external script editors! 
-  * Author : cdfa +  * Author: cdfa 
-  * Link: none yet+  * Version: 1.3 
 +  * Link: https://​plus.google.com/​100430440392224314007/​posts/​KAoKQ317trG 
 + 
 +======Changelog===== 
 +1.3 
 +  * Add support for subfolders 
 + 
 +1.2 
 +  * fixed importing of large scripts 
 +  * updated to new api 
 ====== How to use the script ====== ====== How to use the script ======
 Recommended to run the script on resumed event of the container which is your test environment,​ but you can use it really anytime anywhere. Recommended to run the script on resumed event of the container which is your test environment,​ but you can use it really anytime anywhere.
 +
 ====== Script code ====== ====== Script code ======
-<code+<sxh javascript
-//Old tag +var scriptFolder = "/​storage/​sdcard0/​LightningLauncher/​script"; 
-  ​var scriptFolder = "/​storage/​emulated/0/​LightningLauncher/​script";​+var importPath = "/";
  
-LL.bindClass("​java.lang.StringBuilder") +bindClass("​java.io.FileReader") 
-LL.bindClass("​java.io.FileReader") +bindClass("​java.io.BufferedReader") 
-LL.bindClass("​java.io.BufferedReader") +bindClass("​java.io.File") 
-LL.bindClass("​java.io.File") +bindClass("​java.lang.StringBuilder") 
-LL.bindClass("​java.text.SimpleDateFormat")+bindClass("​android.widget.Toast")
  
-scriptNames ​[] +var context ​getActiveScreen().getContext()
-folder = new File(scriptFolder) + 
-files = folder.listFiles() +function read(filePath){ 
-for(i=0;​i<​files.length;​i++){ +  ​try{ 
-  ​name files[i].getName() +    var r=new BufferedReader(new FileReader(filePath));  
-  ​length ​name.length +    var snew StringBuilder() ;  
-  if(name.substring(length-3,​length)==".js"){ +    var l;  
-    ​scriptNames[scriptNames.length] = name+    while((l=r.readLine())!=null)s.append(l+"​\n"); 
 +    return s;  
 +  }catch(e){ 
 +    ​alert(e) 
 +    return ""; ​
   }   }
 } }
  
-for(i=0;​i<​scriptNames.length;​i++){ +function updateScripts(folder){ 
-  var script=LL.getScriptByName(scriptNames[i].substring(0,​scriptNames[i].length-3)); +  ​folder.listFiles().forEach(function(file){ 
-  ​file ​new File(scriptFolder,scriptNames[i]+    ​var fileName ​file.getName(
-  ​lmdate ​file.lastModified() +    var length = fileName.length 
-  ​tagdate ​script.getTag("​lmdate"​+    if(file.isDirectory()){ 
-  if(lmdate>​tagdate||typeof tagdate ​== "undefined"){ +      updateScripts(file);​ 
-    ​text ​new StringBuilder(); +    }else if(fileName.substring(length-3,length)=="​.js"​){ 
- +      var name fileName.slice(0,-3); 
-    ​try ​+      var path folder.getPath().substring(scriptFolder.length);​ 
-      ​br ​new BufferedReader(new FileReader(file)); +      var script=getScriptByPathAndName(path, name); 
-      ​var line +      if(script==null){ 
- +        Toast.makeText(context, ​"creating new script: ​"+name, Toast.LENGTH_SHORT).show(); 
-      ​while ((line ​br.readLine()) !null) { +        ​script ​createScript(path, name,"",​0); 
-        ​text.append(line); +        var tagdate=0; 
-        ​text.append('​\n'​);+      }else
 +        var tagdate ​script.getTag("​lmdate"​); 
 +      ​} 
 +      ​var lmdate ​file.lastModified() 
 +      if(lmdate>​tagdate||typeof tagdate ​== "​undefined"​){ 
 +        ​updatedScripts.push(name); 
 +        ​script.setText(read(folder.getPath()+"/"​+fileName)); 
 +        script.setTag("​lmdate",​time)
       }       }
-      br.close(); 
-      script.setText(text);​ 
-      date = new Date() 
-      script.setTag("​lmdate",​date.getTime()) 
     }     }
-    catch (err+  });
-      throw(err) +
-    } +
-  }+
 } }
-</​code>​ 
  
-<sxh javascript>​ +//var scriptNames = [] 
-//New tag, line completion and colors +var time new Date().getTime(); 
-var scriptFolder ​"/​storage/​emulated/​0/​LightningLauncher/​script"​;+var updatedScripts = []; 
 +var folder = new File(scriptFolder) 
 +updateScripts(folder)
  
-LL.bindClass("java.lang.StringBuilder"​) +ifupdatedScripts.length>0)Toast.makeText(context, "Updated scripts: ​"+JSON.stringifyupdatedScripts), Toast.LENGTH_SHORT).show();
-LL.bindClass("​java.io.FileReader"​) +
-LL.bindClass("​java.io.BufferedReader"​) +
-LL.bindClass("​java.io.File"​) +
-LL.bindClass("​java.text.SimpleDateFormat"​) +
- +
-scriptNames = [] +
-folder = new File(scriptFolder) +
-files = folder.listFiles() +
-for(i=0;​i<​files.length;​i++)+
-  name = files[i].getName(+
-  length = name.length +
-  if(name.substring(length-3,length)==".js"){ +
-    scriptNames[scriptNames.length] = name +
-  } +
-+
- +
-for(i=0;​i<​scriptNames.length;​i++){ +
-  var script=LL.getScriptByName(scriptNames[i].substring(0,​scriptNames[i].length-3)); +
-  file = new File(scriptFolder,scriptNames[i]) +
-  lmdate = file.lastModified() +
-  tagdate = script.getTag("​lmdate"​) +
-  if(lmdate>​tagdate||typeof tagdate == "​undefined"​){ +
-    text = new StringBuilder(); +
- +
-    try { +
-      br = new BufferedReader(new FileReader(file));​ +
-      var line +
- +
-      while ((line = br.readLine()) != null) { +
-        text.append(line);​ +
-        text.append('​\n'​);​ +
-      } +
-      br.close();​ +
-      script.setText(text);​ +
-      date = new Date() +
-      script.setTag("​lmdate",​date.getTime()) +
-    } +
-    catch (err) { +
-      throw(err) +
-    } +
-  } +
-}+
 </​sxh>​ </​sxh>​
script_external_editor_script_importer.1428717389.txt.gz · Last modified: 2015/04/11 01:56 by cdfa