|
18 | 18 | import java.lang.reflect.Field;
|
19 | 19 | import java.lang.reflect.InvocationTargetException;
|
20 | 20 | import java.lang.reflect.Method;
|
| 21 | +import java.nio.file.Files; |
| 22 | +import java.nio.file.Path; |
| 23 | +import java.nio.file.Paths; |
| 24 | +import java.nio.file.attribute.BasicFileAttributes; |
21 | 25 | import java.util.TimeZone;
|
22 | 26 |
|
23 | 27 | public final class RuntimeHelper {
|
@@ -194,16 +198,7 @@ public static Runtime initRuntime(Application app) {
|
194 | 198 | // runtime needs to be initialized before the NativeScriptSyncService is enabled because it uses runtime.runScript(...)
|
195 | 199 | initLiveSync(runtime, logger, app);
|
196 | 200 |
|
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 |
| - } |
| 201 | + waitForLiveSync(app); |
207 | 202 | }
|
208 | 203 |
|
209 | 204 | runtime.runScript(new File(appDir, "internal/ts_helpers.js"));
|
@@ -239,6 +234,32 @@ public static Runtime initRuntime(Application app) {
|
239 | 234 | }
|
240 | 235 | }
|
241 | 236 |
|
| 237 | + private static void waitForLiveSync(Application app) { |
| 238 | + boolean needToWait = false; |
| 239 | + |
| 240 | + // CLI will create this file when initial sync is needed and then will remove it after syncing the fails and restarting the app |
| 241 | + File liveSyncFile = new File("/data/local/tmp/" + app.getPackageName() + "-livesync-in-progress"); |
| 242 | + if(liveSyncFile.exists()) { |
| 243 | + needToWait = true; |
| 244 | + Long lastModified = liveSyncFile.lastModified(); |
| 245 | + // we check for lastModified == 0 as this might happen if we cannot get the actual modified date |
| 246 | + if(lastModified > 0) { |
| 247 | + Long fileCreatedBeforeMillis = System.currentTimeMillis() - lastModified; |
| 248 | + // if last modified date is more than a minute before the current time discard the file as most probably this is a leftover |
| 249 | + if (fileCreatedBeforeMillis > 60000) { |
| 250 | + needToWait = false; |
| 251 | + } |
| 252 | + } |
| 253 | + } |
| 254 | + |
| 255 | + if(needToWait) { |
| 256 | + try { |
| 257 | + // wait for the livesync to complete and it should restart the app after deleting the livesync-in-progress file |
| 258 | + Thread.sleep(30000); |
| 259 | + } catch (Exception ex) { } |
| 260 | + } |
| 261 | + } |
| 262 | + |
242 | 263 | private static void registerTimezoneChangedListener(Context context, final Runtime runtime) {
|
243 | 264 | IntentFilter timezoneFilter = new IntentFilter(Intent.ACTION_TIMEZONE_CHANGED);
|
244 | 265 |
|
|
0 commit comments