add: module storages
This commit is contained in:
@@ -65,7 +65,7 @@ require("__general__")(__runtime__, this);
|
||||
|
||||
(function(scope){
|
||||
var modules = ['app', 'automator', 'console', 'dialogs', 'io', 'selector', 'shell', 'web', 'ui',
|
||||
"images", "timers", "events", "engines", "RootAutomator", "http"];
|
||||
"images", "timers", "events", "engines", "RootAutomator", "http", "storages"];
|
||||
var len = modules.length;
|
||||
for(var i = 0; i < len; i++) {
|
||||
var m = modules[i];
|
||||
@@ -230,7 +230,7 @@ JSON = {};
|
||||
var partial;
|
||||
var value = holder[key];
|
||||
|
||||
if(value.getClass){
|
||||
if(value && value.getClass){
|
||||
return gson.toJson(value);
|
||||
}
|
||||
|
||||
|
||||
40
autojs/src/main/assets/modules/__storages__.js
Normal file
40
autojs/src/main/assets/modules/__storages__.js
Normal file
@@ -0,0 +1,40 @@
|
||||
|
||||
module.exports = function(__runtime__, scope){
|
||||
var storages = {};
|
||||
storages.create = function(name){
|
||||
return new LocalStorage(name);
|
||||
}
|
||||
|
||||
storages.remove = function(name){
|
||||
this.create(name).clear();
|
||||
}
|
||||
|
||||
return storages;
|
||||
|
||||
function LocalStorage(name){
|
||||
this._storage = new com.stardust.autojs.core.storage.LocalStorage(context, name);
|
||||
this.put = function(key, value){
|
||||
if(typeof(value) == 'undefined'){
|
||||
throw new TypeError('value cannot be undefined');
|
||||
}
|
||||
this._storage.put(key, JSON.stringify(value));
|
||||
}
|
||||
this.get = function(key, defaultValue){
|
||||
var value = this._storage.getString(key, null);
|
||||
if(!value){
|
||||
return defaultValue;
|
||||
}
|
||||
return JSON.parse(value);
|
||||
}
|
||||
this.remove = function(key){
|
||||
this._storage.remove(key);
|
||||
}
|
||||
this.contains = function(key){
|
||||
return this._storage.contains(key);
|
||||
}
|
||||
this.clear = function(key){
|
||||
this._storage.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user