github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/systemprivate/bindings/ffi_bindings.ts (about) 1 import { importModule, Application, heap, Pointer } from "@ffi"; 2 3 importModule("plat/js/webext/systemprivate", (A: Application) => { 4 const WEBEXT = typeof globalThis.browser === "undefined" ? globalThis.chrome : globalThis.browser; 5 6 return { 7 "constof_GetIncognitoModeAvailabilityValue": (ref: heap.Ref<string>): number => { 8 const idx = ["enabled", "disabled", "forced"].indexOf(A.H.get(ref)); 9 return idx < 0 ? 0 : idx + 1; 10 }, 11 "constof_UpdateStatusState": (ref: heap.Ref<string>): number => { 12 const idx = ["NotAvailable", "Updating", "NeedRestart"].indexOf(A.H.get(ref)); 13 return idx < 0 ? 0 : idx + 1; 14 }, 15 16 "store_UpdateStatus": (ptr: Pointer, ref: heap.Ref<any>) => { 17 const x = A.H.get<any>(ref); 18 19 if (typeof x === "undefined") { 20 A.store.Bool(ptr + 12, false); 21 A.store.Float64(ptr + 0, 0); 22 A.store.Enum(ptr + 8, -1); 23 } else { 24 A.store.Bool(ptr + 12, true); 25 A.store.Float64(ptr + 0, x["downloadProgress"] === undefined ? 0 : (x["downloadProgress"] as number)); 26 A.store.Enum(ptr + 8, ["NotAvailable", "Updating", "NeedRestart"].indexOf(x["state"] as string)); 27 } 28 }, 29 "load_UpdateStatus": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => { 30 const x = create === A.H.TRUE ? {} : A.H.get<any>(ref); 31 32 x["downloadProgress"] = A.load.Float64(ptr + 0); 33 x["state"] = A.load.Enum(ptr + 8, ["NotAvailable", "Updating", "NeedRestart"]); 34 return create === A.H.TRUE ? A.H.push(x) : ref; 35 }, 36 "has_GetApiKey": (): heap.Ref<boolean> => { 37 if (WEBEXT?.systemPrivate && "getApiKey" in WEBEXT?.systemPrivate) { 38 return A.H.TRUE; 39 } 40 return A.H.FALSE; 41 }, 42 "func_GetApiKey": (fn: Pointer): void => { 43 A.store.Ref(fn, WEBEXT.systemPrivate.getApiKey); 44 }, 45 "call_GetApiKey": (retPtr: Pointer): void => { 46 const _ret = WEBEXT.systemPrivate.getApiKey(); 47 A.store.Ref(retPtr, _ret); 48 }, 49 "try_GetApiKey": (retPtr: Pointer, errPtr: Pointer): heap.Ref<boolean> => { 50 try { 51 const _ret = WEBEXT.systemPrivate.getApiKey(); 52 A.store.Ref(retPtr, _ret); 53 return A.H.TRUE; 54 } catch (err: any) { 55 A.store.Ref(errPtr, err); 56 return A.H.FALSE; 57 } 58 }, 59 "has_GetIncognitoModeAvailability": (): heap.Ref<boolean> => { 60 if (WEBEXT?.systemPrivate && "getIncognitoModeAvailability" in WEBEXT?.systemPrivate) { 61 return A.H.TRUE; 62 } 63 return A.H.FALSE; 64 }, 65 "func_GetIncognitoModeAvailability": (fn: Pointer): void => { 66 A.store.Ref(fn, WEBEXT.systemPrivate.getIncognitoModeAvailability); 67 }, 68 "call_GetIncognitoModeAvailability": (retPtr: Pointer): void => { 69 const _ret = WEBEXT.systemPrivate.getIncognitoModeAvailability(); 70 A.store.Ref(retPtr, _ret); 71 }, 72 "try_GetIncognitoModeAvailability": (retPtr: Pointer, errPtr: Pointer): heap.Ref<boolean> => { 73 try { 74 const _ret = WEBEXT.systemPrivate.getIncognitoModeAvailability(); 75 A.store.Ref(retPtr, _ret); 76 return A.H.TRUE; 77 } catch (err: any) { 78 A.store.Ref(errPtr, err); 79 return A.H.FALSE; 80 } 81 }, 82 "has_GetUpdateStatus": (): heap.Ref<boolean> => { 83 if (WEBEXT?.systemPrivate && "getUpdateStatus" in WEBEXT?.systemPrivate) { 84 return A.H.TRUE; 85 } 86 return A.H.FALSE; 87 }, 88 "func_GetUpdateStatus": (fn: Pointer): void => { 89 A.store.Ref(fn, WEBEXT.systemPrivate.getUpdateStatus); 90 }, 91 "call_GetUpdateStatus": (retPtr: Pointer): void => { 92 const _ret = WEBEXT.systemPrivate.getUpdateStatus(); 93 A.store.Ref(retPtr, _ret); 94 }, 95 "try_GetUpdateStatus": (retPtr: Pointer, errPtr: Pointer): heap.Ref<boolean> => { 96 try { 97 const _ret = WEBEXT.systemPrivate.getUpdateStatus(); 98 A.store.Ref(retPtr, _ret); 99 return A.H.TRUE; 100 } catch (err: any) { 101 A.store.Ref(errPtr, err); 102 return A.H.FALSE; 103 } 104 }, 105 }; 106 });