plusui-native-core 0.1.84 → 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.
- package/Core/API/index.ts +87 -0
- 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
|
// ============================================================
|
|
@@ -31,6 +78,8 @@ export { fileDrop } from '../Features/FileDrop/filedrop';
|
|
|
31
78
|
export { menu } from '../Features/Menu/menu';
|
|
32
79
|
export { app } from '../Features/App/app';
|
|
33
80
|
export { gpu } from '../Features/WebGPU/webgpu';
|
|
81
|
+
export { browser } from '../Features/Browser/browser';
|
|
82
|
+
export { router } from '../Features/Router/router';
|
|
34
83
|
|
|
35
84
|
// ============================================================
|
|
36
85
|
// CUSTOM CHANNELS - For user-defined events (uses .on/.emit)
|
|
@@ -128,3 +177,41 @@ export {
|
|
|
128
177
|
isTextFile,
|
|
129
178
|
formatFileSize
|
|
130
179
|
} from '../Features/FileDrop/filedrop';
|
|
180
|
+
|
|
181
|
+
// ============================================================
|
|
182
|
+
// DEFAULT EXPORT - For `import plusui from 'plusui'` convenience
|
|
183
|
+
// ============================================================
|
|
184
|
+
|
|
185
|
+
import { window } from '../Features/Window/window';
|
|
186
|
+
import { clipboard } from '../Features/Clipboard/clipboard';
|
|
187
|
+
import { keyboard } from '../Features/Keyboard/keyboard';
|
|
188
|
+
import { tray } from '../Features/Tray/tray';
|
|
189
|
+
import { display } from '../Features/Display/display';
|
|
190
|
+
import { fileDrop, formatFileSize } from '../Features/FileDrop/filedrop';
|
|
191
|
+
import { menu } from '../Features/Menu/menu';
|
|
192
|
+
import { app } from '../Features/App/app';
|
|
193
|
+
import { gpu } from '../Features/WebGPU/webgpu';
|
|
194
|
+
import { browser } from '../Features/Browser/browser';
|
|
195
|
+
import { router } from '../Features/Router/router';
|
|
196
|
+
import { connect, createChannel, createFeatureConnect } from './Connect_API';
|
|
197
|
+
|
|
198
|
+
const plusui = {
|
|
199
|
+
window,
|
|
200
|
+
win: window, // Alias for backward compatibility
|
|
201
|
+
clipboard,
|
|
202
|
+
keyboard,
|
|
203
|
+
tray,
|
|
204
|
+
display,
|
|
205
|
+
fileDrop,
|
|
206
|
+
menu,
|
|
207
|
+
app,
|
|
208
|
+
gpu,
|
|
209
|
+
browser,
|
|
210
|
+
router,
|
|
211
|
+
connect,
|
|
212
|
+
createChannel,
|
|
213
|
+
createFeatureConnect,
|
|
214
|
+
formatFileSize
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
export default plusui;
|