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
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ public NativeScriptApplication() {

public void onCreate() {
super.onCreate();
new RuntimeHelper(this).initRuntime();
com.tns.Runtime runtime = RuntimeHelper.initRuntime(this);
if (runtime !=null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

also this check should not be needed

Copy link
Author

Choose a reason for hiding this comment

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

The check is needed, for example when showing error activity.

runtime.run();
}
}

public static Application getInstance() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,12 @@
import android.util.Log;
import java.io.IOException;

public class RuntimeHelper {
private final Application app;

public RuntimeHelper(Application app) {
this.app = app;
}
public final class RuntimeHelper {
private RuntimeHelper() {}

// hasErrorIntent tells you if there was an event (with an uncaught
// exception) raised from ErrorReport
public boolean hasErrorIntent() {
public static boolean hasErrorIntent(Application app) {
boolean hasErrorIntent = false;

try {
Expand All @@ -38,18 +34,19 @@ public boolean hasErrorIntent() {
return hasErrorIntent;
}

public void initRuntime()
public static Runtime initRuntime(Application app)
{
if (Runtime.isInitialized()) {
return;
return Runtime.getCurrentRuntime();
}

System.loadLibrary("NativeScript");

Runtime runtime = null;
Logger logger = new LogcatLogger(app);
Debugger debugger = AndroidJsDebugger.isDebuggableApp(this.app) ? new AndroidJsDebugger(app, logger) : null;
Debugger debugger = AndroidJsDebugger.isDebuggableApp(app) ? new AndroidJsDebugger(app, logger) : null;

boolean showErrorIntent = hasErrorIntent();
boolean showErrorIntent = hasErrorIntent(app);
if (!showErrorIntent) {
NativeScriptUncaughtExceptionHandler exHandler = new NativeScriptUncaughtExceptionHandler(logger, app);

Expand Down Expand Up @@ -110,12 +107,12 @@ public void initRuntime()
ThreadScheduler workThreadScheduler = new WorkThreadScheduler(new Handler(Looper.getMainLooper()));
Configuration config = new Configuration(workThreadScheduler, logger, debugger, appName, null, rootDir,
appDir, classLoader, dexDir, dexThumb, v8Config);
Runtime runtime = new Runtime(config);
runtime = new Runtime(config);

exHandler.setRuntime(runtime);

if (NativeScriptSyncService.isSyncEnabled(this.app)) {
NativeScriptSyncService syncService = new NativeScriptSyncService(runtime, logger, this.app);
if (NativeScriptSyncService.isSyncEnabled(app)) {
NativeScriptSyncService syncService = new NativeScriptSyncService(runtime, logger, app);

syncService.sync();
syncService.startServer();
Expand All @@ -141,14 +138,14 @@ public void initRuntime()

try {
// put this call in a try/catch block because with the latest changes in the modules it is not granted that NativeScriptApplication is extended through JavaScript.
Runtime.initInstance(this.app);
Runtime.initInstance(app);
}
catch (Exception e) {

}
runtime.run();
}
return runtime;
}

private final String logTag = "MyApp";
private static final String logTag = "MyApp";
}
2 changes: 1 addition & 1 deletion runtime/src/main/java/com/tns/Runtime.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public int getRuntimeId()
return this.runtimeId;
}

private static Runtime getCurrentRuntime()
public static Runtime getCurrentRuntime()
{
Runtime runtime = currentRuntime.get();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ public NativeScriptApplication() {

public void onCreate() {
super.onCreate();
new RuntimeHelper(this).initRuntime();
com.tns.Runtime runtime = RuntimeHelper.initRuntime(this);
if (runtime !=null) {
runtime.run();
}
}

public static Application getInstance() {
Expand Down
30 changes: 14 additions & 16 deletions test-app/app/src/main/java/com/tns/RuntimeHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@
import android.util.Log;
import java.io.IOException;

public class RuntimeHelper {
private final Application app;

public RuntimeHelper(Application app) {
this.app = app;
public final class RuntimeHelper {
private RuntimeHelper() {
}

// hasErrorIntent tells you if there was an event (with an uncaught
// exception) raised from ErrorReport
public boolean hasErrorIntent() {
private static boolean hasErrorIntent(Application app) {
boolean hasErrorIntent = false;

try {
Expand All @@ -38,18 +35,19 @@ public boolean hasErrorIntent() {
return hasErrorIntent;
}

public void initRuntime()
public static Runtime initRuntime(Application app)
{
if (Runtime.isInitialized()) {
return;
return Runtime.getCurrentRuntime();
}

System.loadLibrary("NativeScript");

Logger logger = new LogcatLogger(app);
Debugger debugger = AndroidJsDebugger.isDebuggableApp(this.app) ? new AndroidJsDebugger(app, logger) : null;
Debugger debugger = AndroidJsDebugger.isDebuggableApp(app) ? new AndroidJsDebugger(app, logger) : null;

boolean showErrorIntent = hasErrorIntent();
Runtime runtime = null;
boolean showErrorIntent = hasErrorIntent(app);
if (!showErrorIntent) {
NativeScriptUncaughtExceptionHandler exHandler = new NativeScriptUncaughtExceptionHandler(logger, app);

Expand Down Expand Up @@ -110,12 +108,12 @@ public void initRuntime()
ThreadScheduler workThreadScheduler = new WorkThreadScheduler(new Handler(Looper.getMainLooper()));
Configuration config = new Configuration(workThreadScheduler, logger, debugger, appName, null, rootDir,
appDir, classLoader, dexDir, dexThumb, v8Config);
Runtime runtime = new Runtime(config);
runtime = new Runtime(config);

exHandler.setRuntime(runtime);

if (NativeScriptSyncService.isSyncEnabled(this.app)) {
NativeScriptSyncService syncService = new NativeScriptSyncService(runtime, logger, this.app);
if (NativeScriptSyncService.isSyncEnabled(app)) {
NativeScriptSyncService syncService = new NativeScriptSyncService(runtime, logger, app);

syncService.sync();
syncService.startServer();
Expand All @@ -141,14 +139,14 @@ public void initRuntime()

try {
// put this call in a try/catch block because with the latest changes in the modules it is not granted that NativeScriptApplication is extended through JavaScript.
Runtime.initInstance(this.app);
Runtime.initInstance(app);
}
catch (Exception e) {

}
runtime.run();
}
return runtime;
}

private final String logTag = "MyApp";
private static final String logTag = "MyApp";
}