github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/enterprise/networkingattributes/bindings/ffi_bindings.ts (about)

     1  import { importModule, Application, heap, Pointer } from "@ffi";
     2  
     3  importModule("plat/js/webext/enterprise/networkingattributes", (A: Application) => {
     4    const WEBEXT = typeof globalThis.browser === "undefined" ? globalThis.chrome : globalThis.browser;
     5  
     6    return {
     7      "store_NetworkDetails": (ptr: Pointer, ref: heap.Ref<any>) => {
     8        const x = A.H.get<any>(ref);
     9  
    10        if (typeof x === "undefined") {
    11          A.store.Bool(ptr + 12, false);
    12          A.store.Ref(ptr + 0, undefined);
    13          A.store.Ref(ptr + 4, undefined);
    14          A.store.Ref(ptr + 8, undefined);
    15        } else {
    16          A.store.Bool(ptr + 12, true);
    17          A.store.Ref(ptr + 0, x["macAddress"]);
    18          A.store.Ref(ptr + 4, x["ipv4"]);
    19          A.store.Ref(ptr + 8, x["ipv6"]);
    20        }
    21      },
    22      "load_NetworkDetails": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => {
    23        const x = create === A.H.TRUE ? {} : A.H.get<any>(ref);
    24  
    25        x["macAddress"] = A.load.Ref(ptr + 0, undefined);
    26        x["ipv4"] = A.load.Ref(ptr + 4, undefined);
    27        x["ipv6"] = A.load.Ref(ptr + 8, undefined);
    28        return create === A.H.TRUE ? A.H.push(x) : ref;
    29      },
    30      "has_GetNetworkDetails": (): heap.Ref<boolean> => {
    31        if (WEBEXT?.enterprise?.networkingAttributes && "getNetworkDetails" in WEBEXT?.enterprise?.networkingAttributes) {
    32          return A.H.TRUE;
    33        }
    34        return A.H.FALSE;
    35      },
    36      "func_GetNetworkDetails": (fn: Pointer): void => {
    37        A.store.Ref(fn, WEBEXT.enterprise.networkingAttributes.getNetworkDetails);
    38      },
    39      "call_GetNetworkDetails": (retPtr: Pointer): void => {
    40        const _ret = WEBEXT.enterprise.networkingAttributes.getNetworkDetails();
    41        A.store.Ref(retPtr, _ret);
    42      },
    43      "try_GetNetworkDetails": (retPtr: Pointer, errPtr: Pointer): heap.Ref<boolean> => {
    44        try {
    45          const _ret = WEBEXT.enterprise.networkingAttributes.getNetworkDetails();
    46          A.store.Ref(retPtr, _ret);
    47          return A.H.TRUE;
    48        } catch (err: any) {
    49          A.store.Ref(errPtr, err);
    50          return A.H.FALSE;
    51        }
    52      },
    53    };
    54  });