@cuby-ui/ar 0.0.7 → 0.0.9

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(...)`](#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(options?: { message?: string | undefined; } | undefined) => Promise<void>
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; }) => Promise<void>
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,6 +1,7 @@
1
1
  package com.cuby.plugins.cubyar;
2
2
 
3
- import static com.cuby.cubyar.NativeLogger.LogMessage;
3
+ import static com.cuby.cubyar.NativeLogger.logMessage;
4
+ import static com.cuby.cubyar.GEngineHelper.isGEngineReady;
4
5
 
5
6
  import android.Manifest;
6
7
  import android.annotation.SuppressLint;
@@ -15,69 +16,70 @@ import android.widget.Toast;
15
16
  import androidx.core.app.ActivityCompat;
16
17
  import androidx.core.content.ContextCompat;
17
18
 
19
+ import com.cuby.cubyar.NativeLogger;
18
20
  import com.getcapacitor.Plugin;
19
21
  import com.getcapacitor.PluginCall;
20
22
  import com.getcapacitor.PluginMethod;
21
23
  import com.getcapacitor.annotation.CapacitorPlugin;
22
24
  import com.getcapacitor.JSObject;
23
25
 
24
- @CapacitorPlugin(name = "NativeBridge")
26
+ @CapacitorPlugin(name = "NativeBridge", permissions = {
27
+ @Permission(strings = { Manifest.permission.CAMERA }, alias = "camera")
28
+ })
25
29
  public class NativeBridge extends Plugin {
26
-
27
- private static final int CAMERA_REQUEST_CODE = 1234;
28
- private PluginCall savedCall;
30
+ private static final String LOG_TAG = "CubyARPlugin";
29
31
 
30
32
  @PluginMethod
31
33
  public void startAR(PluginCall call) {
32
- Activity activity = getActivity();
33
-
34
- if (ContextCompat.checkSelfPermission(activity,
35
- Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
36
- savedCall = call;
37
- ActivityCompat.requestPermissions(activity,
38
- new String[] { Manifest.permission.CAMERA },
39
- CAMERA_REQUEST_CODE);
40
- return;
34
+ if (getPermissionState("camera") != PermissionState.GRANTED) {
35
+ requestPermissionForAlias("camera", call, "cameraPermissionCallback");
36
+ } else {
37
+ launchUnrealAR();
38
+ call.resolve();
41
39
  }
40
+ }
42
41
 
43
- launchUnrealAR(call);
42
+ @PermissionCallback
43
+ private void cameraPermissionCallback(PluginCall call) {
44
+ if (getPermissionState("camera") == PermissionState.GRANTED) {
45
+ launchUnrealAR();
46
+ call.resolve();
47
+ } else {
48
+ call.reject("Camera permission denied");
49
+ }
44
50
  }
45
51
 
46
52
  @SuppressLint("QueryPermissionsNeeded")
47
- private void launchUnrealAR(PluginCall call) {
48
- Activity activity = getActivity();
49
-
50
- String message = call.getString("message");
53
+ private void launchUnrealAR() {
51
54
  try {
55
+ Activity activity = getActivity();
52
56
  Intent intent = new Intent();
53
57
  intent.setClassName(activity.getPackageName(), "com.epicgames.unreal.GameActivity");
54
58
 
55
59
  if (intent.resolveActivity(activity.getPackageManager()) != null) {
56
60
  activity.startActivity(intent);
57
- Log.i("ArLauncherPlugin", "Unreal AR activity launched successfully");
58
-
59
- // Delay calling LogMessage by 10 seconds so we don't block the UI thread
60
- // and allow the launched activity to settle first.
61
- new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
62
- @Override
63
- public void run() {
64
- LogMessage(message);
65
- Log.i("ArLauncherPlugin", message);
66
- }
67
- }, 10_000);
68
61
 
62
+ 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
69
  } else {
70
- Log.e("ArLauncherPlugin", "GameActivity not found in package");
70
+ Log.e(LOG_TAG, "GameActivity not found in package");
71
71
  }
72
72
 
73
73
  } catch (Exception e) {
74
- Log.e("ArLauncherPlugin", "Failed to launch AR", e);
74
+ Log.e(LOG_TAG, "Failed to launch AR", e);
75
75
  }
76
76
  }
77
77
 
78
78
  @PluginMethod
79
79
  public void logMessage(PluginCall call) {
80
80
  String message = call.getString("message");
81
+ float duration = call.getString("duration", "5.0") != null ? Float.parseFloat(call.getString("duration", "5.0"))
82
+ : 5.0f;
81
83
 
82
84
  if (message == null) {
83
85
  call.reject("Missing 'message' parameter");
@@ -85,7 +87,7 @@ public class NativeBridge extends Plugin {
85
87
  }
86
88
 
87
89
  try {
88
- LogMessage(message);
90
+ NativeLogger.logMessage(message, duration);
89
91
 
90
92
  JSObject ret = new JSObject();
91
93
  ret.put("status", "logged");
package/dist/docs.json CHANGED
@@ -7,15 +7,9 @@
7
7
  "methods": [
8
8
  {
9
9
  "name": "startAR",
10
- "signature": "(options?: { message?: string | undefined; } | undefined) => Promise<void>",
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; }) => Promise<void>",
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(options?: {
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
- }): Promise<void>;
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(options?: { message?: string }): Promise<void>;\n\n /**\n * Sends a message to native code to be logged. Returns a small status\n * object on success.\n */\n logMessage(options: { message: string }): Promise<void>;\n}\n"]}
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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cuby-ui/ar",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "Ar/Vr plugin",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",