@cuby-ui/ar 0.0.9 → 0.0.11
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
|
@@ -15,6 +15,8 @@ npx cap sync
|
|
|
15
15
|
|
|
16
16
|
* [`startAR()`](#startar)
|
|
17
17
|
* [`logMessage(...)`](#logmessage)
|
|
18
|
+
* [`addListener('click', ...)`](#addlistenerclick-)
|
|
19
|
+
* [Interfaces](#interfaces)
|
|
18
20
|
|
|
19
21
|
</docgen-index>
|
|
20
22
|
|
|
@@ -47,4 +49,32 @@ object on success.
|
|
|
47
49
|
|
|
48
50
|
--------------------
|
|
49
51
|
|
|
52
|
+
|
|
53
|
+
### addListener('click', ...)
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
addListener(eventName: 'click', listenerFunc: (event: { data: string; }) => void) => PluginListenerHandle
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Listens for click events from the native AR view.
|
|
60
|
+
|
|
61
|
+
| Param | Type | Description |
|
|
62
|
+
| ------------------ | -------------------------------------------------- | -------------------------------------------------------------------------------- |
|
|
63
|
+
| **`eventName`** | <code>'click'</code> | The name of the event to listen for (should be 'click'). |
|
|
64
|
+
| **`listenerFunc`** | <code>(event: { data: string; }) => void</code> | The function to call when the event occurs, receiving an event object with data. |
|
|
65
|
+
|
|
66
|
+
**Returns:** <code><a href="#pluginlistenerhandle">PluginListenerHandle</a></code>
|
|
67
|
+
|
|
68
|
+
--------------------
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
### Interfaces
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
#### PluginListenerHandle
|
|
75
|
+
|
|
76
|
+
| Prop | Type |
|
|
77
|
+
| ------------ | ----------------------------------------- |
|
|
78
|
+
| **`remove`** | <code>() => Promise<void></code> |
|
|
79
|
+
|
|
50
80
|
</docgen-api>
|
|
Binary file
|
|
@@ -1,50 +1,80 @@
|
|
|
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
19
|
@CapacitorPlugin(name = "NativeBridge", permissions = {
|
|
27
20
|
@Permission(strings = { Manifest.permission.CAMERA }, alias = "camera")
|
|
28
21
|
})
|
|
29
22
|
public class NativeBridge extends Plugin {
|
|
30
23
|
private static final String LOG_TAG = "CubyARPlugin";
|
|
24
|
+
private boolean isPermissionDenied = false;
|
|
25
|
+
|
|
26
|
+
public static NativeBridge instance;
|
|
27
|
+
|
|
28
|
+
@Override
|
|
29
|
+
public void load() {
|
|
30
|
+
super.load();
|
|
31
|
+
instance = this;
|
|
32
|
+
Log.i(LOG_TAG, "NativeBridge instance stored");
|
|
33
|
+
}
|
|
31
34
|
|
|
32
35
|
@PluginMethod
|
|
33
36
|
public void startAR(PluginCall call) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
PermissionState state = getPermissionState("camera");
|
|
38
|
+
|
|
39
|
+
isPermissionDenied = false;
|
|
40
|
+
|
|
41
|
+
if (state == PermissionState.GRANTED) {
|
|
37
42
|
launchUnrealAR();
|
|
38
43
|
call.resolve();
|
|
44
|
+
} else {
|
|
45
|
+
requestPermissionForAlias("camera", call, "cameraPermsCallback");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Wait until the Unreal Engine is fully initialized
|
|
49
|
+
long startTime = System.currentTimeMillis();
|
|
50
|
+
long timeoutInSeconds = 5_000;
|
|
51
|
+
|
|
52
|
+
while (!isGEngineReady() &&
|
|
53
|
+
(System.currentTimeMillis() - startTime < timeoutInSeconds) &&
|
|
54
|
+
!isPermissionDenied) {
|
|
55
|
+
try {
|
|
56
|
+
Thread.sleep(100);
|
|
57
|
+
} catch (InterruptedException e) {
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (isGEngineReady()) {
|
|
63
|
+
Log.i(LOG_TAG, "Unreal Engine initialized");
|
|
64
|
+
} else {
|
|
65
|
+
Log.e(LOG_TAG, "Timeout waiting for Unreal Engine initialization");
|
|
39
66
|
}
|
|
40
67
|
}
|
|
41
68
|
|
|
42
69
|
@PermissionCallback
|
|
43
|
-
private void
|
|
70
|
+
private void cameraPermsCallback(PluginCall call) {
|
|
44
71
|
if (getPermissionState("camera") == PermissionState.GRANTED) {
|
|
45
|
-
|
|
46
|
-
|
|
72
|
+
new Thread(() -> {
|
|
73
|
+
launchUnrealAR();
|
|
74
|
+
getActivity().runOnUiThread(call::resolve);
|
|
75
|
+
}).start();
|
|
47
76
|
} else {
|
|
77
|
+
isPermissionDenied = true;
|
|
48
78
|
call.reject("Camera permission denied");
|
|
49
79
|
}
|
|
50
80
|
}
|
|
@@ -60,12 +90,6 @@ public class NativeBridge extends Plugin {
|
|
|
60
90
|
activity.startActivity(intent);
|
|
61
91
|
|
|
62
92
|
Log.i(LOG_TAG, "Unreal AR activity launched successfully");
|
|
63
|
-
|
|
64
|
-
// Wait until the Unreal Engine is fully initialized.
|
|
65
|
-
// This loop blocks execution to ensure no engine functions
|
|
66
|
-
// are called before the engine is ready
|
|
67
|
-
while (!isGEngineReady())
|
|
68
|
-
;
|
|
69
93
|
} else {
|
|
70
94
|
Log.e(LOG_TAG, "GameActivity not found in package");
|
|
71
95
|
}
|
|
@@ -78,8 +102,7 @@ public class NativeBridge extends Plugin {
|
|
|
78
102
|
@PluginMethod
|
|
79
103
|
public void logMessage(PluginCall call) {
|
|
80
104
|
String message = call.getString("message");
|
|
81
|
-
|
|
82
|
-
: 5.0f;
|
|
105
|
+
double duration = call.getDouble("duration", 5.0);
|
|
83
106
|
|
|
84
107
|
if (message == null) {
|
|
85
108
|
call.reject("Missing 'message' parameter");
|
|
@@ -87,8 +110,9 @@ public class NativeBridge extends Plugin {
|
|
|
87
110
|
}
|
|
88
111
|
|
|
89
112
|
try {
|
|
90
|
-
NativeLogger.logMessage(message, duration);
|
|
91
|
-
|
|
113
|
+
NativeLogger.logMessage(message, (float) duration);
|
|
114
|
+
String data = NativeLogger.returnData();
|
|
115
|
+
Log.i(LOG_TAG, "Native data: " + data);
|
|
92
116
|
JSObject ret = new JSObject();
|
|
93
117
|
ret.put("status", "logged");
|
|
94
118
|
call.resolve(ret);
|
|
@@ -96,4 +120,16 @@ public class NativeBridge extends Plugin {
|
|
|
96
120
|
call.reject("Failed to log message via native code", e);
|
|
97
121
|
}
|
|
98
122
|
}
|
|
123
|
+
|
|
124
|
+
public String getNativeData() {
|
|
125
|
+
try {
|
|
126
|
+
String data = NativeLogger.returnData();
|
|
127
|
+
JSObject ret = new JSObject();
|
|
128
|
+
ret.put("data", data);
|
|
129
|
+
notifyListeners("click", ret);
|
|
130
|
+
} catch (Exception e) {
|
|
131
|
+
// call.reject("Failed to get native data", e);
|
|
132
|
+
}
|
|
133
|
+
return "";
|
|
134
|
+
}
|
|
99
135
|
}
|
package/dist/docs.json
CHANGED
|
@@ -35,11 +35,64 @@
|
|
|
35
35
|
"docs": "Sends a message to native code to be logged. Returns a small status\nobject on success.",
|
|
36
36
|
"complexTypes": [],
|
|
37
37
|
"slug": "logmessage"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"name": "addListener",
|
|
41
|
+
"signature": "(eventName: 'click', listenerFunc: (event: { data: string; }) => void) => PluginListenerHandle",
|
|
42
|
+
"parameters": [
|
|
43
|
+
{
|
|
44
|
+
"name": "eventName",
|
|
45
|
+
"docs": "The name of the event to listen for (should be 'click').",
|
|
46
|
+
"type": "'click'"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"name": "listenerFunc",
|
|
50
|
+
"docs": "The function to call when the event occurs, receiving an event object with data.",
|
|
51
|
+
"type": "(event: { data: string; }) => void"
|
|
52
|
+
}
|
|
53
|
+
],
|
|
54
|
+
"returns": "PluginListenerHandle",
|
|
55
|
+
"tags": [
|
|
56
|
+
{
|
|
57
|
+
"name": "param",
|
|
58
|
+
"text": "eventName The name of the event to listen for (should be 'click')."
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"name": "param",
|
|
62
|
+
"text": "listenerFunc The function to call when the event occurs, receiving an event object with data."
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"name": "returns",
|
|
66
|
+
"text": "A handle to remove the listener when no longer needed."
|
|
67
|
+
}
|
|
68
|
+
],
|
|
69
|
+
"docs": "Listens for click events from the native AR view.",
|
|
70
|
+
"complexTypes": [
|
|
71
|
+
"PluginListenerHandle"
|
|
72
|
+
],
|
|
73
|
+
"slug": "addlistenerclick-"
|
|
38
74
|
}
|
|
39
75
|
],
|
|
40
76
|
"properties": []
|
|
41
77
|
},
|
|
42
|
-
"interfaces": [
|
|
78
|
+
"interfaces": [
|
|
79
|
+
{
|
|
80
|
+
"name": "PluginListenerHandle",
|
|
81
|
+
"slug": "pluginlistenerhandle",
|
|
82
|
+
"docs": "",
|
|
83
|
+
"tags": [],
|
|
84
|
+
"methods": [],
|
|
85
|
+
"properties": [
|
|
86
|
+
{
|
|
87
|
+
"name": "remove",
|
|
88
|
+
"tags": [],
|
|
89
|
+
"docs": "",
|
|
90
|
+
"complexTypes": [],
|
|
91
|
+
"type": "() => Promise<void>"
|
|
92
|
+
}
|
|
93
|
+
]
|
|
94
|
+
}
|
|
95
|
+
],
|
|
43
96
|
"enums": [],
|
|
44
97
|
"typeAliases": [],
|
|
45
98
|
"pluginConfigs": []
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PluginListenerHandle } from '@capacitor/core';
|
|
1
2
|
export interface NativeBridgePlugin {
|
|
2
3
|
/**
|
|
3
4
|
* Launches the AR activity.
|
|
@@ -12,4 +13,13 @@ export interface NativeBridgePlugin {
|
|
|
12
13
|
message: string;
|
|
13
14
|
duration?: number;
|
|
14
15
|
}): void;
|
|
16
|
+
/**
|
|
17
|
+
* Listens for click events from the native AR view.
|
|
18
|
+
* @param eventName The name of the event to listen for (should be 'click').
|
|
19
|
+
* @param listenerFunc The function to call when the event occurs, receiving an event object with data.
|
|
20
|
+
* @returns A handle to remove the listener when no longer needed.
|
|
21
|
+
*/
|
|
22
|
+
addListener(eventName: 'click', listenerFunc: (event: {
|
|
23
|
+
data: string;
|
|
24
|
+
}) => void): PluginListenerHandle;
|
|
15
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import { PluginListenerHandle } from '@capacitor/core';\n\nexport 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 /**\n * Listens for click events from the native AR view.\n * @param eventName The name of the event to listen for (should be 'click').\n * @param listenerFunc The function to call when the event occurs, receiving an event object with data.\n * @returns A handle to remove the listener when no longer needed.\n */\n addListener(\n eventName: 'click',\n listenerFunc: (event: { data: string }) => void\n ): PluginListenerHandle;\n}\n"]}
|