Skip to content

Commit f1112c4

Browse files
author
Mihail Slavchev
committed
show error activity when no debug client is attached
1 parent a0e4161 commit f1112c4

File tree

9 files changed

+82
-60
lines changed

9 files changed

+82
-60
lines changed

build/project-template-gradle/src/main/java/com/tns/NativeScriptApplication.java

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,48 @@ public class NativeScriptApplication extends android.app.Application implements
77

88
private static NativeScriptApplication thiz;
99

10-
public NativeScriptApplication()
11-
{
10+
public NativeScriptApplication() {
1211
thiz = this;
1312
}
1413

1514
public void onCreate() {
1615
new RuntimeHelper(this).initRuntime();
17-
java.lang.Object[] params = null;
18-
com.tns.Platform.callJSMethod(this, "onCreate", void.class, params);
16+
if (Platform.isInitialized()) {
17+
java.lang.Object[] params = null;
18+
com.tns.Platform.callJSMethod(this, "onCreate", void.class, params);
19+
} else {
20+
super.onCreate();
21+
}
1922
}
2023

2124
public void onLowMemory() {
22-
java.lang.Object[] params = null;
23-
com.tns.Platform.callJSMethod(this, "onLowMemory", void.class, params);
25+
if (Platform.isInitialized()) {
26+
java.lang.Object[] params = null;
27+
com.tns.Platform.callJSMethod(this, "onLowMemory", void.class, params);
28+
} else {
29+
super.onLowMemory();
30+
}
2431
}
2532

2633
public void onTrimMemory(int level) {
27-
java.lang.Object[] params = new Object[1];
28-
params[0] = level;
29-
com.tns.Platform.callJSMethod(this, "onTrimMemory", void.class, params);
34+
if (Platform.isInitialized()) {
35+
java.lang.Object[] params = new Object[1];
36+
params[0] = level;
37+
com.tns.Platform.callJSMethod(this, "onTrimMemory", void.class, params);
38+
} else {
39+
super.onTrimMemory(level);
40+
}
3041
}
3142

32-
3343
public boolean equals__super(java.lang.Object other) {
3444
return super.equals(other);
3545
}
46+
3647
public int hashCode__super() {
3748
return super.hashCode();
3849
}
3950

4051
public static Application getInstance() {
4152
return thiz;
4253
}
43-
4454
}

build/project-template-gradle/src/main/java/com/tns/NativeScriptUncaughtExceptionHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void uncaughtException(Thread thread, Throwable ex)
3131
ex.printStackTrace();
3232
Platform.passUncaughtExceptionToJsNative(ex, errorMessage);
3333

34-
if (JsDebugger.isJsDebugerActive())
34+
if (JsDebugger.isJsDebuggerActive())
3535
{
3636
return;
3737
}

src/jni/JsDebugger.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ void JsDebugger::DebugBreak()
8282

8383
bool JsDebugger::IsDebuggerActive()
8484
{
85-
return s_jsDebugger != nullptr && enabled;
85+
return s_processedCommands;
8686
}
8787

8888
void JsDebugger::ProcessDebugMessages()
@@ -249,6 +249,8 @@ void JsDebugger::SendCommandToV8(uint16_t *cmd, int length)
249249
auto isolate = s_isolate;
250250

251251
v8::Debug::SendCommand(isolate, cmd, length, nullptr);
252+
253+
s_processedCommands = true;
252254
}
253255

254256
/* *
@@ -278,4 +280,4 @@ jclass JsDebugger::s_JsDebuggerClass = nullptr;
278280
jmethodID JsDebugger::s_EnqueueMessage = nullptr;
279281
jmethodID JsDebugger::s_EnqueueConsoleMessage = nullptr;
280282
jmethodID JsDebugger::s_EnableAgent = nullptr;
281-
283+
bool JsDebugger::s_processedCommands = false;

src/jni/JsDebugger.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ namespace tns
5151
static jmethodID s_EnqueueConsoleMessage;
5252
static jmethodID s_EnableAgent;
5353
static v8::Isolate *s_isolate;
54+
static bool s_processedCommands;
5455

5556
static const int INVALID_PORT = -1;
5657
};

src/jni/com_tns_JsDebugger.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ extern "C" void Java_com_tns_JsDebugger_debugBreak(JNIEnv *env, jobject obj)
9797
}
9898
}
9999

100-
extern "C" jboolean Java_com_tns_JsDebugger_isDebugerActive(JNIEnv *env, jobject obj)
100+
extern "C" jboolean Java_com_tns_JsDebugger_isDebuggerActive(JNIEnv *env, jobject obj)
101101
{
102102
try
103103
{

src/src/com/tns/JsDebugger.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class JsDebugger
4343

4444
private static native void sendCommand(byte[] command, int length);
4545

46-
private static native boolean isDebugerActive();
46+
private static native boolean isDebuggerActive();
4747

4848
private ThreadScheduler threadScheduler;
4949

@@ -612,8 +612,8 @@ public static boolean isDebuggableApp(Context context)
612612
return isDebuggableApp;
613613
}
614614

615-
public static boolean isJsDebugerActive()
615+
public static boolean isJsDebuggerActive()
616616
{
617-
return isDebugerActive();
617+
return isDebuggerActive();
618618
}
619619
}
Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,55 @@
1-
/*
2-
* Warning: this file may be auto-generated in future. Edit with caution.
3-
*/
41
package com.tns;
52

63
import android.app.Application;
74

85
@JavaScriptImplementation(javaScriptFile = "app/MyApp.js")
9-
public class NativeScriptApplication extends android.app.Application implements com.tns.NativeScriptHashCodeProvider
10-
{
11-
public NativeScriptApplication()
12-
{
13-
}
14-
15-
protected void attachBaseContext(android.content.Context param_0) {
16-
super.attachBaseContext(param_0);
17-
18-
if (Util.isDebuggableApp(param_0))
19-
{
20-
// TODO:
21-
//android.os.Debug.waitForDebugger();
22-
}
23-
6+
public class NativeScriptApplication extends android.app.Application implements com.tns.NativeScriptHashCodeProvider {
7+
8+
private static NativeScriptApplication thiz;
9+
10+
public NativeScriptApplication()
11+
{
12+
thiz = this;
13+
}
14+
15+
public void onCreate() {
2416
new RuntimeHelper(this).initRuntime();
25-
26-
Platform.initInstance(this);
27-
}
28-
29-
public void onCreate()
30-
{
31-
appInstance = this;
32-
java.lang.Object[] params = null;
33-
com.tns.Platform.callJSMethod(this, "onCreate", void.class, params);
34-
}
35-
36-
private static Application appInstance;
37-
public static Application getInstance(){
38-
return appInstance;
39-
}
40-
41-
public boolean equals__super(java.lang.Object other) {
42-
return super.equals(other);
43-
}
44-
public int hashCode__super() {
45-
return super.hashCode();
46-
}
47-
}
17+
if (Platform.isInitialized()) {
18+
java.lang.Object[] params = null;
19+
com.tns.Platform.callJSMethod(this, "onCreate", void.class, params);
20+
} else {
21+
super.onCreate();
22+
}
23+
}
24+
25+
public void onLowMemory() {
26+
if (Platform.isInitialized()) {
27+
java.lang.Object[] params = null;
28+
com.tns.Platform.callJSMethod(this, "onLowMemory", void.class, params);
29+
} else {
30+
super.onLowMemory();
31+
}
32+
}
33+
34+
public void onTrimMemory(int level) {
35+
if (Platform.isInitialized()) {
36+
java.lang.Object[] params = new Object[1];
37+
params[0] = level;
38+
com.tns.Platform.callJSMethod(this, "onTrimMemory", void.class, params);
39+
} else {
40+
super.onTrimMemory(level);
41+
}
42+
}
43+
44+
public boolean equals__super(java.lang.Object other) {
45+
return super.equals(other);
46+
}
47+
48+
public int hashCode__super() {
49+
return super.hashCode();
50+
}
51+
52+
public static Application getInstance() {
53+
return thiz;
54+
}
55+
}

test-app/src/com/tns/NativeScriptUncaughtExceptionHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void uncaughtException(Thread thread, Throwable ex)
3131
ex.printStackTrace();
3232
Platform.passUncaughtExceptionToJsNative(ex, errorMessage);
3333

34-
if (JsDebugger.isJsDebugerActive())
34+
if (JsDebugger.isJsDebuggerActive())
3535
{
3636
return;
3737
}

test-app/src/com/tns/RuntimeHelper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ public void initRuntime()
110110
ThreadScheduler workThreadScheduler = new WorkThreadScheduler(new Handler(Looper.getMainLooper()));
111111
Platform.init(this.app, workThreadScheduler, logger, appName, null, rootDir, appDir, /* debuggerSetupDir, */ classLoader, dexDir, dexThumb);
112112
Platform.runScript(new File(appDir, "internal/ts_helpers.js"));
113+
Platform.initInstance(this.app);
113114
Platform.run();
114115
}
115116
}

0 commit comments

Comments
 (0)