@cuby-ui/ar 0.0.18 → 0.0.20

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
@@ -1,11 +1,11 @@
1
1
  # cuby-ar
2
2
 
3
- Ar/Vr plugin
3
+ AR plugin
4
4
 
5
5
  ## Install
6
6
 
7
7
  ```bash
8
- npm install cuby-ar
8
+ npm i @cuby-ui/ar
9
9
  npx cap sync
10
10
  ```
11
11
 
@@ -17,9 +17,7 @@ npx cap sync
17
17
  * [`addOnScreenDebugMessage(...)`](#addonscreendebugmessage)
18
18
  * [`addListener(string, ...)`](#addlistenerstring-)
19
19
  * [`setFbxFolderPath(...)`](#setfbxfolderpath)
20
- * [`getFbxFolderPath()`](#getfbxfolderpath)
21
20
  * [`setJsonData(...)`](#setjsondata)
22
- * [`getJsonData()`](#getjsondata)
23
21
  * [Interfaces](#interfaces)
24
22
 
25
23
  </docgen-index>
@@ -33,7 +31,8 @@ npx cap sync
33
31
  startAR() => void
34
32
  ```
35
33
 
36
- Launches the AR activity.
34
+ Launches the AR activity and waits until Unreal Engine is ready.
35
+ Resolves when AR is initialized, or rejects on timeout/error.
37
36
 
38
37
  --------------------
39
38
 
@@ -44,8 +43,7 @@ Launches the AR activity.
44
43
  addOnScreenDebugMessage(options: { message: string; duration?: number; }) => void
45
44
  ```
46
45
 
47
- Sends a message to native code to be logged. Returns a small status
48
- object on success.
46
+ Sends a message to native code to be logged.
49
47
 
50
48
  | Param | Type | Description |
51
49
  | ------------- | ---------------------------------------------------- | ------------------------------------------------------------------- |
@@ -75,7 +73,7 @@ Listens for events from the native AR activity.
75
73
  ### setFbxFolderPath(...)
76
74
 
77
75
  ```typescript
78
- setFbxFolderPath(options: { path: string; }) => string
76
+ setFbxFolderPath(options: { path: string; }) => void
79
77
  ```
80
78
 
81
79
  Sets the path to the FBX folder in native code.
@@ -84,28 +82,13 @@ Sets the path to the FBX folder in native code.
84
82
  | ------------- | ------------------------------ | ------------------------------------- |
85
83
  | **`options`** | <code>{ path: string; }</code> | An object containing the path string. |
86
84
 
87
- **Returns:** <code>string</code>
88
-
89
- --------------------
90
-
91
-
92
- ### getFbxFolderPath()
93
-
94
- ```typescript
95
- getFbxFolderPath() => string
96
- ```
97
-
98
- Gets the current FBX folder path from native code.
99
-
100
- **Returns:** <code>string</code>
101
-
102
85
  --------------------
103
86
 
104
87
 
105
88
  ### setJsonData(...)
106
89
 
107
90
  ```typescript
108
- setJsonData(options: { data: string; }) => string
91
+ setJsonData(options: { data: string; }) => void
109
92
  ```
110
93
 
111
94
  Sets the path to the JSON data in native code.
@@ -114,21 +97,6 @@ Sets the path to the JSON data in native code.
114
97
  | ------------- | ------------------------------ | ------------------------------------- |
115
98
  | **`options`** | <code>{ data: string; }</code> | An object containing the path string. |
116
99
 
117
- **Returns:** <code>string</code>
118
-
119
- --------------------
120
-
121
-
122
- ### getJsonData()
123
-
124
- ```typescript
125
- getJsonData() => string
126
- ```
127
-
128
- Gets the current JSON data path from native code.
129
-
130
- **Returns:** <code>string</code>
131
-
132
100
  --------------------
133
101
 
134
102
 
Binary file
@@ -1,6 +1,5 @@
1
1
  package com.cuby.plugins.cubyar;
2
2
 
3
- import static com.cuby.cubyar.GEngineHelper.isGEngineReady;
4
3
  import android.Manifest;
5
4
  import android.annotation.SuppressLint;
6
5
  import android.app.Activity;
@@ -8,13 +7,13 @@ import android.content.Intent;
8
7
  import android.util.Log;
9
8
  import com.cuby.cubyar.NativeLogger;
10
9
  import com.cuby.cubyar.ModelData;
10
+ import com.getcapacitor.JSObject;
11
11
  import com.getcapacitor.PermissionState;
12
12
  import com.getcapacitor.Plugin;
13
13
  import com.getcapacitor.PluginCall;
14
14
  import com.getcapacitor.PluginMethod;
15
15
  import com.getcapacitor.annotation.CapacitorPlugin;
16
16
  import com.getcapacitor.annotation.Permission;
17
- import com.getcapacitor.JSObject;
18
17
  import com.getcapacitor.annotation.PermissionCallback;
19
18
 
20
19
  @CapacitorPlugin(name = "NativeBridge", permissions = {
@@ -22,7 +21,6 @@ import com.getcapacitor.annotation.PermissionCallback;
22
21
  })
23
22
  public class NativeBridge extends Plugin {
24
23
  private static final String LOG_TAG = "CubyARPlugin";
25
- private boolean isPermissionDenied = false;
26
24
 
27
25
  public static NativeBridge instance;
28
26
 
@@ -36,46 +34,18 @@ public class NativeBridge extends Plugin {
36
34
  @PluginMethod
37
35
  public void startAR(PluginCall call) {
38
36
  PermissionState state = getPermissionState("camera");
39
-
40
- isPermissionDenied = false;
41
-
42
37
  if (state == PermissionState.GRANTED) {
43
- launchUnrealAR();
44
- call.resolve();
38
+ new android.os.Handler().postDelayed(this::launchUnrealAR, 300);
45
39
  } else {
46
40
  requestPermissionForAlias("camera", call, "cameraPermsCallback");
47
41
  }
48
-
49
- // Wait until the Unreal Engine is fully initialized
50
- long startTime = System.currentTimeMillis();
51
- long timeoutInSeconds = 5_000;
52
-
53
- while (!isGEngineReady() &&
54
- (System.currentTimeMillis() - startTime < timeoutInSeconds) &&
55
- !isPermissionDenied) {
56
- try {
57
- Thread.sleep(100);
58
- } catch (InterruptedException e) {
59
- break;
60
- }
61
- }
62
-
63
- if (isGEngineReady()) {
64
- Log.i(LOG_TAG, "Unreal Engine initialized");
65
- } else {
66
- Log.e(LOG_TAG, "Timeout waiting for Unreal Engine initialization");
67
- }
68
42
  }
69
43
 
70
44
  @PermissionCallback
71
45
  private void cameraPermsCallback(PluginCall call) {
72
46
  if (getPermissionState("camera") == PermissionState.GRANTED) {
73
- new Thread(() -> {
74
- launchUnrealAR();
75
- getActivity().runOnUiThread(call::resolve);
76
- }).start();
47
+ launchUnrealAR();
77
48
  } else {
78
- isPermissionDenied = true;
79
49
  call.reject("Camera permission denied");
80
50
  }
81
51
  }
@@ -84,24 +54,30 @@ public class NativeBridge extends Plugin {
84
54
  private void launchUnrealAR() {
85
55
  try {
86
56
  Activity activity = getActivity();
57
+ if (activity == null || activity.isFinishing()) {
58
+ Log.e(LOG_TAG, "Activity is null or finishing");
59
+ return;
60
+ }
61
+
87
62
  Intent intent = new Intent();
88
63
  intent.setClassName(activity.getPackageName(), "com.epicgames.unreal.GameActivity");
89
64
 
65
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
66
+ intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
67
+
90
68
  if (intent.resolveActivity(activity.getPackageManager()) != null) {
91
69
  activity.startActivity(intent);
92
-
93
70
  Log.i(LOG_TAG, "Unreal AR activity launched successfully");
94
71
  } else {
95
72
  Log.e(LOG_TAG, "GameActivity not found in package");
96
73
  }
97
-
98
74
  } catch (Exception e) {
99
75
  Log.e(LOG_TAG, "Failed to launch AR", e);
100
76
  }
101
77
  }
102
78
 
103
79
  @PluginMethod
104
- public void logMessage(PluginCall call) {
80
+ public void addOnScreenDebugMessage(PluginCall call) {
105
81
  String message = call.getString("message");
106
82
  double duration = call.getDouble("duration", 5.0);
107
83
 
@@ -112,11 +88,9 @@ public class NativeBridge extends Plugin {
112
88
 
113
89
  try {
114
90
  NativeLogger.addOnScreenDebugMessage(message, (float) duration);
115
- JSObject ret = new JSObject();
116
- ret.put("status", "logged");
117
- call.resolve(ret);
91
+ call.resolve();
118
92
  } catch (Exception e) {
119
- call.reject("Failed to log message via native code", e);
93
+ call.reject("Failed to log message via addOnScreenDebugMessage", e);
120
94
  }
121
95
  }
122
96
 
@@ -130,65 +104,35 @@ public class NativeBridge extends Plugin {
130
104
 
131
105
  try {
132
106
  ModelData.setFbxFolderPath(path);
133
- JSObject ret = new JSObject();
134
- ret.put("status", "fbxPathSet");
135
- call.resolve(ret);
107
+ call.resolve();
136
108
  } catch (Exception e) {
137
109
  call.reject("Failed to set FBX folder path", e);
138
110
  }
139
111
  }
140
112
 
141
113
  @PluginMethod
142
- public void getFbxFolderPath(PluginCall call) {
143
- try {
144
- String path = ModelData.getFbxFolderPath();
145
- JSObject ret = new JSObject();
146
- ret.put("fbxPath", path);
147
- call.resolve(ret);
148
- } catch (Exception e) {
149
- call.reject("Failed to get FBX folder path", e);
150
- }
151
- }
152
-
153
- @PluginMethod
154
- public void setJsonFile(PluginCall call) {
155
- String path = call.getString("path");
156
- if (path == null) {
157
- call.reject("Missing 'path' parameter");
114
+ public void setJsonData(PluginCall call) {
115
+ String data = call.getString("data");
116
+ if (data == null) {
117
+ call.reject("Missing 'data' parameter");
158
118
  return;
159
119
  }
160
120
 
161
121
  try {
162
- ModelData.setJsonFile(path);
163
- JSObject ret = new JSObject();
164
- ret.put("status", "jsonFileSet");
165
- call.resolve(ret);
122
+ ModelData.setJsonFile(data);
123
+ call.resolve();
166
124
  } catch (Exception e) {
167
- call.reject("Failed to set JSON file path", e);
125
+ call.reject("Failed to set JSON file data", e);
168
126
  }
169
127
  }
170
128
 
171
- @PluginMethod
172
- public void getJsonFile(PluginCall call) {
129
+ public void notifyListeners(String eventName, String data) {
173
130
  try {
174
- String path = ModelData.getJsonFile();
175
131
  JSObject ret = new JSObject();
176
- ret.put("jsonPath", path);
177
- call.resolve(ret);
132
+ ret.put("data", data);
133
+ notifyListeners(eventName, ret);
178
134
  } catch (Exception e) {
179
- call.reject("Failed to get JSON file path", e);
135
+ Log.e(LOG_TAG, "Failed to notify listeners", e);
180
136
  }
181
137
  }
182
-
183
- // public String getNativeData() {
184
- // try {
185
- // String data = NativeLogger.returnData();
186
- // JSObject ret = new JSObject();
187
- // ret.put("data", data);
188
- // notifyListeners("click", ret);
189
- // } catch (Exception e) {
190
- // // call.reject("Failed to get native data", e);
191
- // }
192
- // return "";
193
- // }
194
- }
138
+ }
@@ -0,0 +1,19 @@
1
+ package com.google.vr.sdk.samples.permission;
2
+
3
+ import android.app.Activity;
4
+
5
+ public class PermissionHelper {
6
+ public static boolean hasPermissions(Activity activity) {
7
+ return true;
8
+ }
9
+
10
+ public static void requestPermissions(Activity activity) {
11
+ }
12
+
13
+ public static boolean checkPermission(String permission) {
14
+ return true;
15
+ }
16
+
17
+ public static void acquirePermissions(String[] permissions) {
18
+ }
19
+ }
package/dist/docs.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "parameters": [],
12
12
  "returns": "void",
13
13
  "tags": [],
14
- "docs": "Launches the AR activity.",
14
+ "docs": "Launches the AR activity and waits until Unreal Engine is ready.\nResolves when AR is initialized, or rejects on timeout/error.",
15
15
  "complexTypes": [],
16
16
  "slug": "startar"
17
17
  },
@@ -32,7 +32,7 @@
32
32
  "text": "options The message to log and optional duration in seconds (default is 5)."
33
33
  }
34
34
  ],
35
- "docs": "Sends a message to native code to be logged. Returns a small status\nobject on success.",
35
+ "docs": "Sends a message to native code to be logged.",
36
36
  "complexTypes": [],
37
37
  "slug": "addonscreendebugmessage"
38
38
  },
@@ -60,10 +60,6 @@
60
60
  {
61
61
  "name": "param",
62
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
63
  }
68
64
  ],
69
65
  "docs": "Listens for events from the native AR activity.",
@@ -74,7 +70,7 @@
74
70
  },
75
71
  {
76
72
  "name": "setFbxFolderPath",
77
- "signature": "(options: { path: string; }) => string",
73
+ "signature": "(options: { path: string; }) => void",
78
74
  "parameters": [
79
75
  {
80
76
  "name": "options",
@@ -82,7 +78,7 @@
82
78
  "type": "{ path: string; }"
83
79
  }
84
80
  ],
85
- "returns": "string",
81
+ "returns": "void",
86
82
  "tags": [
87
83
  {
88
84
  "name": "param",
@@ -93,24 +89,9 @@
93
89
  "complexTypes": [],
94
90
  "slug": "setfbxfolderpath"
95
91
  },
96
- {
97
- "name": "getFbxFolderPath",
98
- "signature": "() => string",
99
- "parameters": [],
100
- "returns": "string",
101
- "tags": [
102
- {
103
- "name": "returns",
104
- "text": "An object containing the path string."
105
- }
106
- ],
107
- "docs": "Gets the current FBX folder path from native code.",
108
- "complexTypes": [],
109
- "slug": "getfbxfolderpath"
110
- },
111
92
  {
112
93
  "name": "setJsonData",
113
- "signature": "(options: { data: string; }) => string",
94
+ "signature": "(options: { data: string; }) => void",
114
95
  "parameters": [
115
96
  {
116
97
  "name": "options",
@@ -118,7 +99,7 @@
118
99
  "type": "{ data: string; }"
119
100
  }
120
101
  ],
121
- "returns": "string",
102
+ "returns": "void",
122
103
  "tags": [
123
104
  {
124
105
  "name": "param",
@@ -128,21 +109,6 @@
128
109
  "docs": "Sets the path to the JSON data in native code.",
129
110
  "complexTypes": [],
130
111
  "slug": "setjsondata"
131
- },
132
- {
133
- "name": "getJsonData",
134
- "signature": "() => string",
135
- "parameters": [],
136
- "returns": "string",
137
- "tags": [
138
- {
139
- "name": "returns",
140
- "text": "An object containing the path string."
141
- }
142
- ],
143
- "docs": "Gets the current JSON data path from native code.",
144
- "complexTypes": [],
145
- "slug": "getjsondata"
146
112
  }
147
113
  ],
148
114
  "properties": []
@@ -1,12 +1,12 @@
1
- import { PluginListenerHandle } from '@capacitor/core';
1
+ import { PluginListenerHandle } from "@capacitor/core";
2
2
  export interface NativeBridgePlugin {
3
3
  /**
4
- * Launches the AR activity.
4
+ * Launches the AR activity and waits until Unreal Engine is ready.
5
+ * Resolves when AR is initialized, or rejects on timeout/error.
5
6
  */
6
7
  startAR(): void;
7
8
  /**
8
- * Sends a message to native code to be logged. Returns a small status
9
- * object on success.
9
+ * Sends a message to native code to be logged.
10
10
  * @param options The message to log and optional duration in seconds (default is 5).
11
11
  */
12
12
  addOnScreenDebugMessage(options: {
@@ -17,7 +17,6 @@ export interface NativeBridgePlugin {
17
17
  * Listens for events from the native AR activity.
18
18
  * @param eventName The name of the event to listen for.
19
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
20
  */
22
21
  addListener(eventName: string, listenerFunc: (event: {
23
22
  data: string;
@@ -28,22 +27,12 @@ export interface NativeBridgePlugin {
28
27
  */
29
28
  setFbxFolderPath(options: {
30
29
  path: string;
31
- }): string;
32
- /**
33
- * Gets the current FBX folder path from native code.
34
- * @returns An object containing the path string.
35
- */
36
- getFbxFolderPath(): string;
30
+ }): void;
37
31
  /**
38
32
  * Sets the path to the JSON data in native code.
39
33
  * @param options An object containing the path string.
40
34
  */
41
35
  setJsonData(options: {
42
36
  data: string;
43
- }): string;
44
- /**
45
- * Gets the current JSON data path from native code.
46
- * @returns An object containing the path string.
47
- */
48
- getJsonData(): string;
37
+ }): void;
49
38
  }
@@ -1 +1 @@
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 addOnScreenDebugMessage(options: { message: string; duration?: number; }): void;\n\n /**\n * Listens for events from the native AR activity.\n * @param eventName The name of the event to listen for.\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: string,\n listenerFunc: (event: { data: string }) => void\n ): PluginListenerHandle;\n\n /**\n * Sets the path to the FBX folder in native code.\n * @param options An object containing the path string.\n */\n setFbxFolderPath(options: { path: string }): string;\n\n /**\n * Gets the current FBX folder path from native code.\n * @returns An object containing the path string.\n */\n getFbxFolderPath(): string;\n\n /**\n * Sets the path to the JSON data in native code.\n * @param options An object containing the path string.\n */\n setJsonData(options: { data: string }): string;\n\n /**\n * Gets the current JSON data path from native code.\n * @returns An object containing the path string.\n */\n getJsonData(): string;\n}\n"]}
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 and waits until Unreal Engine is ready.\n * Resolves when AR is initialized, or rejects on timeout/error.\n */\n startAR(): void;\n\n /**\n * Sends a message to native code to be logged.\n * @param options The message to log and optional duration in seconds (default is 5).\n */\n addOnScreenDebugMessage(options: { message: string; duration?: number; }): void;\n\n /**\n * Listens for events from the native AR activity.\n * @param eventName The name of the event to listen for.\n * @param listenerFunc The function to call when the event occurs, receiving an event object with data.\n */\n addListener(\n eventName: string,\n listenerFunc: (event: { data: string }) => void\n ): PluginListenerHandle;\n\n /**\n * Sets the path to the FBX folder in native code.\n * @param options An object containing the path string.\n */\n setFbxFolderPath(options: { path: string }): void;\n\n /**\n * Sets the path to the JSON data in native code.\n * @param options An object containing the path string.\n */\n setJsonData(options: { data: string }): void;\n}"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cuby-ui/ar",
3
- "version": "0.0.18",
4
- "description": "Ar/Vr plugin",
3
+ "version": "0.0.20",
4
+ "description": "AR plugin",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
7
7
  "types": "dist/esm/index.d.ts",