plusui-native-core 0.1.85 → 0.1.86

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.
Files changed (2) hide show
  1. package/Core/API/index.ts +47 -0
  2. package/package.json +1 -1
package/Core/API/index.ts CHANGED
@@ -18,6 +18,53 @@
18
18
  * and generates typed channel objects for both frontend and backend.
19
19
  */
20
20
 
21
+ // ============================================================
22
+ // INTERNAL: Initialize Native Bridge Polyfill
23
+ // ============================================================
24
+ if (typeof window !== 'undefined') {
25
+ const win = window as any;
26
+ if (!win.__invoke__) {
27
+ const pendingPromises = new Map<string, { resolve: (val: any) => void; reject: (err: any) => void }>();
28
+ let callId = 0;
29
+
30
+ win.__response__ = function (id: string, result: any, error?: any) {
31
+ if (pendingPromises.has(id)) {
32
+ const { resolve, reject } = pendingPromises.get(id)!;
33
+ pendingPromises.delete(id);
34
+ if (error) {
35
+ reject(new Error(error));
36
+ } else {
37
+ resolve(result);
38
+ }
39
+ }
40
+ };
41
+
42
+ win.__invoke__ = function (method: string, params: any[] = []): Promise<any> {
43
+ if (!win.__native_invoke__) {
44
+ console.warn(`[PlusUI] API not initialized: __native_invoke__ missing. Running in mock mode for '${method}'.`);
45
+ return Promise.resolve(null);
46
+ }
47
+ return new Promise((resolve, reject) => {
48
+ const id = String(++callId);
49
+ pendingPromises.set(id, { resolve, reject });
50
+
51
+ try {
52
+ const payload = JSON.stringify({
53
+ jsonrpc: '2.0',
54
+ id,
55
+ method,
56
+ params
57
+ });
58
+ win.__native_invoke__(payload);
59
+ } catch (err) {
60
+ pendingPromises.delete(id);
61
+ reject(err);
62
+ }
63
+ });
64
+ };
65
+ }
66
+ }
67
+
21
68
  // ============================================================
22
69
  // BUILT-IN FEATURES - Direct methods only (NO .on/.emit)
23
70
  // ============================================================
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plusui-native-core",
3
- "version": "0.1.85",
3
+ "version": "0.1.86",
4
4
  "description": "PlusUI Core framework (frontend + backend implementations)",
5
5
  "type": "module",
6
6
  "exports": {