@@ -50,6 +50,7 @@ public class NodeJS extends CordovaPlugin {
5050
5151 private static final String SHARED_PREFS = "NODEJS_MOBILE_PREFS" ;
5252 private static final String LAST_UPDATED_TIME = "NODEJS_MOBILE_APK_LastUpdateTime" ;
53+ private static final String FORCE_RESET = "NODEJS_MOBILE_RESET" ;
5354 private long lastUpdateTime = 1 ;
5455 private long previousLastUpdateTime = 0 ;
5556
@@ -107,7 +108,7 @@ public void pluginInitialize() {
107108 }
108109
109110 private void asyncInit () {
110- if (wasAPKUpdated () || isEmptyNodeModules ()) {
111+ if (wasAPKUpdated () || isReset ()) {
111112 try {
112113 initSemaphore .acquire ();
113114 new Thread (new Runnable () {
@@ -151,6 +152,8 @@ public boolean execute(String action, JSONArray data, CallbackContext callbackCo
151152 String scriptBody = data .getString (0 );
152153 JSONObject startOptions = data .getJSONObject (1 );
153154 this .startEngineWithScript (scriptBody , startOptions , callbackContext );
155+ } else if (action .equals ("reset" )) {
156+ this .setReset (callbackContext );
154157 } else {
155158 Log .e (LOGTAG , "Invalid action: " + action );
156159 return false ;
@@ -367,6 +370,28 @@ private boolean isEmptyNodeModules(){
367370 return !nodejsModulesFolder .exists ();
368371 }
369372
373+ private void setReset (CallbackContext callbackContext ) {
374+ SharedPreferences prefs = context .getSharedPreferences (SHARED_PREFS , Context .MODE_PRIVATE );
375+ SharedPreferences .Editor editor = prefs .edit ();
376+ editor .putBoolean (FORCE_RESET , true );
377+ editor .commit ();
378+ sendResult (true , "Reset done." , callbackContext );
379+ }
380+
381+ private void clearReset () {
382+ SharedPreferences prefs = context .getSharedPreferences (SHARED_PREFS , Context .MODE_PRIVATE );
383+ SharedPreferences .Editor editor = prefs .edit ();
384+ editor .remove (FORCE_RESET );
385+ editor .commit ();
386+ }
387+
388+ private void isReset () {
389+ SharedPreferences prefs = context .getSharedPreferences (SHARED_PREFS , Context .MODE_PRIVATE );
390+ boolean result = prefs .getBoolean (FORCE_RESET , false );
391+ clearReset ();
392+ return result ;
393+ }
394+
370395 private boolean wasAPKUpdated () {
371396 SharedPreferences prefs = context .getSharedPreferences (SHARED_PREFS , Context .MODE_PRIVATE );
372397 this .previousLastUpdateTime = prefs .getLong (LAST_UPDATED_TIME , 0 );
0 commit comments