@cuby-ui/ar 0.0.9 → 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.
@@ -1,50 +1,71 @@
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;
31
25
 
32
26
  @PluginMethod
33
27
  public void startAR(PluginCall call) {
34
- if (getPermissionState("camera") != PermissionState.GRANTED) {
35
- requestPermissionForAlias("camera", call, "cameraPermissionCallback");
36
- } else {
28
+ PermissionState state = getPermissionState("camera");
29
+
30
+ isPermissionDenied = false;
31
+
32
+ if (state == PermissionState.GRANTED) {
37
33
  launchUnrealAR();
38
34
  call.resolve();
35
+ } else {
36
+ requestPermissionForAlias("camera", call, "cameraPermsCallback");
37
+ }
38
+
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");
39
57
  }
40
58
  }
41
59
 
42
60
  @PermissionCallback
43
- private void cameraPermissionCallback(PluginCall call) {
61
+ private void cameraPermsCallback(PluginCall call) {
44
62
  if (getPermissionState("camera") == PermissionState.GRANTED) {
45
- launchUnrealAR();
46
- call.resolve();
63
+ new Thread(() -> {
64
+ launchUnrealAR();
65
+ getActivity().runOnUiThread(call::resolve);
66
+ }).start();
47
67
  } else {
68
+ isPermissionDenied = true;
48
69
  call.reject("Camera permission denied");
49
70
  }
50
71
  }
@@ -60,12 +81,6 @@ public class NativeBridge extends Plugin {
60
81
  activity.startActivity(intent);
61
82
 
62
83
  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
84
  } else {
70
85
  Log.e(LOG_TAG, "GameActivity not found in package");
71
86
  }
@@ -78,8 +93,7 @@ public class NativeBridge extends Plugin {
78
93
  @PluginMethod
79
94
  public void logMessage(PluginCall call) {
80
95
  String message = call.getString("message");
81
- float duration = call.getString("duration", "5.0") != null ? Float.parseFloat(call.getString("duration", "5.0"))
82
- : 5.0f;
96
+ double duration = call.getDouble("duration", 5.0);
83
97
 
84
98
  if (message == null) {
85
99
  call.reject("Missing 'message' parameter");
@@ -87,7 +101,7 @@ public class NativeBridge extends Plugin {
87
101
  }
88
102
 
89
103
  try {
90
- NativeLogger.logMessage(message, duration);
104
+ NativeLogger.logMessage(message, (float) duration);
91
105
 
92
106
  JSObject ret = new JSObject();
93
107
  ret.put("status", "logged");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cuby-ui/ar",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "description": "Ar/Vr plugin",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",