@@ -194,16 +194,7 @@ public static Runtime initRuntime(Application app) {
194
194
// runtime needs to be initialized before the NativeScriptSyncService is enabled because it uses runtime.runScript(...)
195
195
initLiveSync (runtime , logger , app );
196
196
197
- // CLI will create this file when initial sync is needed and then will remove it after syncing the fails and restarting the app
198
- File liveSyncFile = new File ("/data/local/tmp/" + app .getPackageName () + "-livesync-in-progress" );
199
- if (liveSyncFile .exists ()) {
200
- try {
201
- // wait for the livesync to complete
202
- Thread .sleep (30000 );
203
- } catch (Exception ex ) {
204
-
205
- }
206
- }
197
+ waitForLiveSync (app );
207
198
}
208
199
209
200
runtime .runScript (new File (appDir , "internal/ts_helpers.js" ));
@@ -239,6 +230,32 @@ public static Runtime initRuntime(Application app) {
239
230
}
240
231
}
241
232
233
+ private static void waitForLiveSync (Application app ) {
234
+ boolean needToWait = false ;
235
+
236
+ // CLI will create this file when initial sync is needed and then will remove it after syncing the fails and restarting the app
237
+ File liveSyncFile = new File ("/data/local/tmp/" + app .getPackageName () + "-livesync-in-progress" );
238
+ if (liveSyncFile .exists ()) {
239
+ needToWait = true ;
240
+ Long lastModified = liveSyncFile .lastModified ();
241
+ // we check for lastModified == 0 as this might happen if we cannot get the actual modified date
242
+ if (lastModified > 0 ) {
243
+ Long fileCreatedBeforeMillis = System .currentTimeMillis () - lastModified ;
244
+ // if last modified date is more than a minute before the current time discard the file as most probably this is a leftover
245
+ if (fileCreatedBeforeMillis > 60000 ) {
246
+ needToWait = false ;
247
+ }
248
+ }
249
+ }
250
+
251
+ if (needToWait ) {
252
+ try {
253
+ // wait for the livesync to complete and it should restart the app after deleting the livesync-in-progress file
254
+ Thread .sleep (30000 );
255
+ } catch (Exception ex ) { }
256
+ }
257
+ }
258
+
242
259
private static void registerTimezoneChangedListener (Context context , final Runtime runtime ) {
243
260
IntentFilter timezoneFilter = new IntentFilter (Intent .ACTION_TIMEZONE_CHANGED );
244
261
0 commit comments