Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -181,45 +181,30 @@ public static Runtime initRuntime(Application app) {
} catch (IOException e) {
e.printStackTrace();
}
}

try {
Class NativeScriptSyncService = Class.forName("com.tns.NativeScriptSyncService");
Method isSyncEnabledMethod = NativeScriptSyncService.getMethod("isSyncEnabled", Context.class);
Boolean isSyncEnabled = (Boolean)isSyncEnabledMethod.invoke(NativeScriptSyncService, app);

// if app is in debuggable mode run livesync service
// runtime needs to be initialized before the NativeScriptSyncService is enabled because it uses runtime.runScript(...)
if (isSyncEnabled) {
try {
Class NativeScriptSyncService = Class.forName("com.tns.NativeScriptSyncService");

Constructor cons = NativeScriptSyncService.getConstructor(new Class[] {Runtime.class, Logger.class, Context.class});
Object syncService = cons.newInstance(runtime, logger, app);

Method syncMethod = NativeScriptSyncService.getMethod("sync");
syncMethod.invoke(syncService);

Method startServerMethod = NativeScriptSyncService.getMethod("startServer");
startServerMethod.invoke(syncService);

// preserve this instance as strong reference
// do not preserve in NativeScriptApplication field inorder to
// make the code more portable
// @@@
// Runtime.getOrCreateJavaObjectID(syncService);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this line not necessary anymore?

} else {
if (logger.isEnabled()) {
logger.write("NativeScript LiveSync is not enabled.");
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
}

} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
}

runtime.runScript(new File(appDir, "internal/ts_helpers.js"));
Expand Down
47 changes: 16 additions & 31 deletions test-app/app/src/main/java/com/tns/RuntimeHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,45 +181,30 @@ public static Runtime initRuntime(Application app) {
} catch (IOException e) {
e.printStackTrace();
}
}

try {
Class NativeScriptSyncService = Class.forName("com.tns.NativeScriptSyncService");
Method isSyncEnabledMethod = NativeScriptSyncService.getMethod("isSyncEnabled", Context.class);
Boolean isSyncEnabled = (Boolean)isSyncEnabledMethod.invoke(NativeScriptSyncService, app);

// if app is in debuggable mode run livesync service
// runtime needs to be initialized before the NativeScriptSyncService is enabled because it uses runtime.runScript(...)
if (isSyncEnabled) {
Constructor syncServiceConstructor = NativeScriptSyncService.getConstructor(new Class[] {Runtime.class, Logger.class, Context.class});
Object syncService = syncServiceConstructor.newInstance(runtime, logger, app);
try {
Class NativeScriptSyncService = Class.forName("com.tns.NativeScriptSyncService");

Constructor cons = NativeScriptSyncService.getConstructor(new Class[] {Runtime.class, Logger.class, Context.class});
Object syncService = cons.newInstance(runtime, logger, app);

Method syncMethod = NativeScriptSyncService.getMethod("sync");
syncMethod.invoke(syncService);

Method startServerMethod = NativeScriptSyncService.getMethod("startServer");
startServerMethod.invoke(syncService);

// preserve this instance as strong reference
// do not preserve in NativeScriptApplication field inorder to
// make the code more portable
// @@@
// Runtime.getOrCreateJavaObjectID(syncService);
} else {
if (logger.isEnabled()) {
logger.write("NativeScript LiveSync is not enabled.");
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
}

} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
}

runtime.runScript(new File(appDir, "internal/ts_helpers.js"));
Expand Down