@cuby-ui/ar 0.0.8 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ npx cap sync
|
|
|
13
13
|
|
|
14
14
|
<docgen-index>
|
|
15
15
|
|
|
16
|
-
* [`startAR(
|
|
16
|
+
* [`startAR()`](#startar)
|
|
17
17
|
* [`logMessage(...)`](#logmessage)
|
|
18
18
|
|
|
19
19
|
</docgen-index>
|
|
@@ -21,33 +21,29 @@ npx cap sync
|
|
|
21
21
|
<docgen-api>
|
|
22
22
|
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
|
|
23
23
|
|
|
24
|
-
### startAR(
|
|
24
|
+
### startAR()
|
|
25
25
|
|
|
26
26
|
```typescript
|
|
27
|
-
startAR(
|
|
27
|
+
startAR() => void
|
|
28
28
|
```
|
|
29
29
|
|
|
30
30
|
Launches the AR activity.
|
|
31
31
|
|
|
32
|
-
| Param | Type |
|
|
33
|
-
| ------------- | ---------------------------------- |
|
|
34
|
-
| **`options`** | <code>{ message?: string; }</code> |
|
|
35
|
-
|
|
36
32
|
--------------------
|
|
37
33
|
|
|
38
34
|
|
|
39
35
|
### logMessage(...)
|
|
40
36
|
|
|
41
37
|
```typescript
|
|
42
|
-
logMessage(options: { message: string; }) =>
|
|
38
|
+
logMessage(options: { message: string; duration?: number; }) => void
|
|
43
39
|
```
|
|
44
40
|
|
|
45
41
|
Sends a message to native code to be logged. Returns a small status
|
|
46
42
|
object on success.
|
|
47
43
|
|
|
48
|
-
| Param | Type
|
|
49
|
-
| ------------- |
|
|
50
|
-
| **`options`** | <code>{ message: string; }</code> |
|
|
44
|
+
| Param | Type | Description |
|
|
45
|
+
| ------------- | ---------------------------------------------------- | ------------------------------------------------------------------- |
|
|
46
|
+
| **`options`** | <code>{ message: string; duration?: number; }</code> | The message to log and optional duration in seconds (default is 5). |
|
|
51
47
|
|
|
52
48
|
--------------------
|
|
53
49
|
|
|
Binary file
|
|
@@ -1,50 +1,73 @@
|
|
|
1
1
|
package com.cuby.plugins.cubyar;
|
|
2
2
|
|
|
3
|
-
import static com.cuby.cubyar.NativeLogger.logMessage;
|
|
4
3
|
import static com.cuby.cubyar.GEngineHelper.isGEngineReady;
|
|
5
|
-
|
|
6
4
|
import android.Manifest;
|
|
7
5
|
import android.annotation.SuppressLint;
|
|
8
6
|
import android.app.Activity;
|
|
9
7
|
import android.content.Intent;
|
|
10
|
-
import android.content.pm.PackageManager;
|
|
11
|
-
import android.os.Handler;
|
|
12
|
-
import android.os.Looper;
|
|
13
8
|
import android.util.Log;
|
|
14
|
-
import android.widget.Toast;
|
|
15
|
-
|
|
16
|
-
import androidx.core.app.ActivityCompat;
|
|
17
|
-
import androidx.core.content.ContextCompat;
|
|
18
|
-
|
|
19
9
|
import com.cuby.cubyar.NativeLogger;
|
|
10
|
+
import com.getcapacitor.PermissionState;
|
|
20
11
|
import com.getcapacitor.Plugin;
|
|
21
12
|
import com.getcapacitor.PluginCall;
|
|
22
13
|
import com.getcapacitor.PluginMethod;
|
|
23
14
|
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
15
|
+
import com.getcapacitor.annotation.Permission;
|
|
24
16
|
import com.getcapacitor.JSObject;
|
|
17
|
+
import com.getcapacitor.annotation.PermissionCallback;
|
|
25
18
|
|
|
26
|
-
@CapacitorPlugin(name = "NativeBridge"
|
|
19
|
+
@CapacitorPlugin(name = "NativeBridge", permissions = {
|
|
20
|
+
@Permission(strings = { Manifest.permission.CAMERA }, alias = "camera")
|
|
21
|
+
})
|
|
27
22
|
public class NativeBridge extends Plugin {
|
|
28
|
-
|
|
29
|
-
private static final int CAMERA_REQUEST_CODE = 1234;
|
|
30
|
-
private PluginCall savedCall;
|
|
31
|
-
|
|
32
23
|
private static final String LOG_TAG = "CubyARPlugin";
|
|
24
|
+
private boolean isPermissionDenied = false;
|
|
33
25
|
|
|
34
26
|
@PluginMethod
|
|
35
27
|
public void startAR(PluginCall call) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
28
|
+
PermissionState state = getPermissionState("camera");
|
|
29
|
+
|
|
30
|
+
isPermissionDenied = false;
|
|
31
|
+
|
|
32
|
+
if (state == PermissionState.GRANTED) {
|
|
33
|
+
launchUnrealAR();
|
|
34
|
+
call.resolve();
|
|
35
|
+
} else {
|
|
36
|
+
requestPermissionForAlias("camera", call, "cameraPermsCallback");
|
|
45
37
|
}
|
|
46
38
|
|
|
47
|
-
|
|
39
|
+
// Wait until the Unreal Engine is fully initialized
|
|
40
|
+
long startTime = System.currentTimeMillis();
|
|
41
|
+
long timeoutInSeconds = 5_000;
|
|
42
|
+
|
|
43
|
+
while (!isGEngineReady() &&
|
|
44
|
+
(System.currentTimeMillis() - startTime < timeoutInSeconds) &&
|
|
45
|
+
!isPermissionDenied) {
|
|
46
|
+
try {
|
|
47
|
+
Thread.sleep(100);
|
|
48
|
+
} catch (InterruptedException e) {
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (isGEngineReady()) {
|
|
54
|
+
Log.i(LOG_TAG, "Unreal Engine initialized");
|
|
55
|
+
} else {
|
|
56
|
+
Log.e(LOG_TAG, "Timeout waiting for Unreal Engine initialization");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
@PermissionCallback
|
|
61
|
+
private void cameraPermsCallback(PluginCall call) {
|
|
62
|
+
if (getPermissionState("camera") == PermissionState.GRANTED) {
|
|
63
|
+
new Thread(() -> {
|
|
64
|
+
launchUnrealAR();
|
|
65
|
+
getActivity().runOnUiThread(call::resolve);
|
|
66
|
+
}).start();
|
|
67
|
+
} else {
|
|
68
|
+
isPermissionDenied = true;
|
|
69
|
+
call.reject("Camera permission denied");
|
|
70
|
+
}
|
|
48
71
|
}
|
|
49
72
|
|
|
50
73
|
@SuppressLint("QueryPermissionsNeeded")
|
|
@@ -58,12 +81,6 @@ public class NativeBridge extends Plugin {
|
|
|
58
81
|
activity.startActivity(intent);
|
|
59
82
|
|
|
60
83
|
Log.i(LOG_TAG, "Unreal AR activity launched successfully");
|
|
61
|
-
|
|
62
|
-
// Wait until the Unreal Engine is fully initialized.
|
|
63
|
-
// This loop blocks execution to ensure no engine functions
|
|
64
|
-
// are called before the engine is ready
|
|
65
|
-
while (!isGEngineReady())
|
|
66
|
-
;
|
|
67
84
|
} else {
|
|
68
85
|
Log.e(LOG_TAG, "GameActivity not found in package");
|
|
69
86
|
}
|
|
@@ -76,6 +93,7 @@ public class NativeBridge extends Plugin {
|
|
|
76
93
|
@PluginMethod
|
|
77
94
|
public void logMessage(PluginCall call) {
|
|
78
95
|
String message = call.getString("message");
|
|
96
|
+
double duration = call.getDouble("duration", 5.0);
|
|
79
97
|
|
|
80
98
|
if (message == null) {
|
|
81
99
|
call.reject("Missing 'message' parameter");
|
|
@@ -83,7 +101,7 @@ public class NativeBridge extends Plugin {
|
|
|
83
101
|
}
|
|
84
102
|
|
|
85
103
|
try {
|
|
86
|
-
NativeLogger.logMessage(message);
|
|
104
|
+
NativeLogger.logMessage(message, (float) duration);
|
|
87
105
|
|
|
88
106
|
JSObject ret = new JSObject();
|
|
89
107
|
ret.put("status", "logged");
|
package/dist/docs.json
CHANGED
|
@@ -7,15 +7,9 @@
|
|
|
7
7
|
"methods": [
|
|
8
8
|
{
|
|
9
9
|
"name": "startAR",
|
|
10
|
-
"signature": "(
|
|
11
|
-
"parameters": [
|
|
12
|
-
|
|
13
|
-
"name": "options",
|
|
14
|
-
"docs": "",
|
|
15
|
-
"type": "{ message?: string | undefined; } | undefined"
|
|
16
|
-
}
|
|
17
|
-
],
|
|
18
|
-
"returns": "Promise<void>",
|
|
10
|
+
"signature": "() => void",
|
|
11
|
+
"parameters": [],
|
|
12
|
+
"returns": "void",
|
|
19
13
|
"tags": [],
|
|
20
14
|
"docs": "Launches the AR activity.",
|
|
21
15
|
"complexTypes": [],
|
|
@@ -23,16 +17,21 @@
|
|
|
23
17
|
},
|
|
24
18
|
{
|
|
25
19
|
"name": "logMessage",
|
|
26
|
-
"signature": "(options: { message: string; }) =>
|
|
20
|
+
"signature": "(options: { message: string; duration?: number; }) => void",
|
|
27
21
|
"parameters": [
|
|
28
22
|
{
|
|
29
23
|
"name": "options",
|
|
30
|
-
"docs": "",
|
|
31
|
-
"type": "{ message: string; }"
|
|
24
|
+
"docs": "The message to log and optional duration in seconds (default is 5).",
|
|
25
|
+
"type": "{ message: string; duration?: number | undefined; }"
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
"returns": "void",
|
|
29
|
+
"tags": [
|
|
30
|
+
{
|
|
31
|
+
"name": "param",
|
|
32
|
+
"text": "options The message to log and optional duration in seconds (default is 5)."
|
|
32
33
|
}
|
|
33
34
|
],
|
|
34
|
-
"returns": "Promise<void>",
|
|
35
|
-
"tags": [],
|
|
36
35
|
"docs": "Sends a message to native code to be logged. Returns a small status\nobject on success.",
|
|
37
36
|
"complexTypes": [],
|
|
38
37
|
"slug": "logmessage"
|
|
@@ -2,14 +2,14 @@ export interface NativeBridgePlugin {
|
|
|
2
2
|
/**
|
|
3
3
|
* Launches the AR activity.
|
|
4
4
|
*/
|
|
5
|
-
startAR(
|
|
6
|
-
message?: string;
|
|
7
|
-
}): Promise<void>;
|
|
5
|
+
startAR(): void;
|
|
8
6
|
/**
|
|
9
7
|
* Sends a message to native code to be logged. Returns a small status
|
|
10
8
|
* object on success.
|
|
9
|
+
* @param options The message to log and optional duration in seconds (default is 5).
|
|
11
10
|
*/
|
|
12
11
|
logMessage(options: {
|
|
13
12
|
message: string;
|
|
14
|
-
|
|
13
|
+
duration?: number;
|
|
14
|
+
}): void;
|
|
15
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface NativeBridgePlugin {\n /**\n * Launches the AR activity.\n */\n startAR(
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface NativeBridgePlugin {\n /**\n * Launches the AR activity.\n */\n startAR(): void;\n\n /**\n * Sends a message to native code to be logged. Returns a small status\n * object on success.\n * @param options The message to log and optional duration in seconds (default is 5).\n */\n logMessage(options: { message: string; duration?: number; }): void;\n}\n"]}
|