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

     1  import { importModule, Application, heap, Pointer } from "@ffi";
     2  
     3  importModule("plat/js/webext/virtualkeyboard", (A: Application) => {
     4    const WEBEXT = typeof globalThis.browser === "undefined" ? globalThis.chrome : globalThis.browser;
     5  
     6    return {
     7      "store_FeatureRestrictions": (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 + 10, false);
    12          A.store.Bool(ptr + 5, false);
    13          A.store.Bool(ptr + 0, false);
    14          A.store.Bool(ptr + 6, false);
    15          A.store.Bool(ptr + 1, false);
    16          A.store.Bool(ptr + 7, false);
    17          A.store.Bool(ptr + 2, false);
    18          A.store.Bool(ptr + 8, false);
    19          A.store.Bool(ptr + 3, false);
    20          A.store.Bool(ptr + 9, false);
    21          A.store.Bool(ptr + 4, false);
    22        } else {
    23          A.store.Bool(ptr + 10, true);
    24          A.store.Bool(ptr + 5, "autoCompleteEnabled" in x ? true : false);
    25          A.store.Bool(ptr + 0, x["autoCompleteEnabled"] ? true : false);
    26          A.store.Bool(ptr + 6, "autoCorrectEnabled" in x ? true : false);
    27          A.store.Bool(ptr + 1, x["autoCorrectEnabled"] ? true : false);
    28          A.store.Bool(ptr + 7, "handwritingEnabled" in x ? true : false);
    29          A.store.Bool(ptr + 2, x["handwritingEnabled"] ? true : false);
    30          A.store.Bool(ptr + 8, "spellCheckEnabled" in x ? true : false);
    31          A.store.Bool(ptr + 3, x["spellCheckEnabled"] ? true : false);
    32          A.store.Bool(ptr + 9, "voiceInputEnabled" in x ? true : false);
    33          A.store.Bool(ptr + 4, x["voiceInputEnabled"] ? true : false);
    34        }
    35      },
    36      "load_FeatureRestrictions": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => {
    37        const x = create === A.H.TRUE ? {} : A.H.get<any>(ref);
    38  
    39        if (A.load.Bool(ptr + 5)) {
    40          x["autoCompleteEnabled"] = A.load.Bool(ptr + 0);
    41        } else {
    42          delete x["autoCompleteEnabled"];
    43        }
    44        if (A.load.Bool(ptr + 6)) {
    45          x["autoCorrectEnabled"] = A.load.Bool(ptr + 1);
    46        } else {
    47          delete x["autoCorrectEnabled"];
    48        }
    49        if (A.load.Bool(ptr + 7)) {
    50          x["handwritingEnabled"] = A.load.Bool(ptr + 2);
    51        } else {
    52          delete x["handwritingEnabled"];
    53        }
    54        if (A.load.Bool(ptr + 8)) {
    55          x["spellCheckEnabled"] = A.load.Bool(ptr + 3);
    56        } else {
    57          delete x["spellCheckEnabled"];
    58        }
    59        if (A.load.Bool(ptr + 9)) {
    60          x["voiceInputEnabled"] = A.load.Bool(ptr + 4);
    61        } else {
    62          delete x["voiceInputEnabled"];
    63        }
    64        return create === A.H.TRUE ? A.H.push(x) : ref;
    65      },
    66      "has_RestrictFeatures": (): heap.Ref<boolean> => {
    67        if (WEBEXT?.virtualKeyboard && "restrictFeatures" in WEBEXT?.virtualKeyboard) {
    68          return A.H.TRUE;
    69        }
    70        return A.H.FALSE;
    71      },
    72      "func_RestrictFeatures": (fn: Pointer): void => {
    73        A.store.Ref(fn, WEBEXT.virtualKeyboard.restrictFeatures);
    74      },
    75      "call_RestrictFeatures": (retPtr: Pointer, restrictions: Pointer): void => {
    76        const restrictions_ffi = {};
    77  
    78        if (A.load.Bool(restrictions + 5)) {
    79          restrictions_ffi["autoCompleteEnabled"] = A.load.Bool(restrictions + 0);
    80        }
    81        if (A.load.Bool(restrictions + 6)) {
    82          restrictions_ffi["autoCorrectEnabled"] = A.load.Bool(restrictions + 1);
    83        }
    84        if (A.load.Bool(restrictions + 7)) {
    85          restrictions_ffi["handwritingEnabled"] = A.load.Bool(restrictions + 2);
    86        }
    87        if (A.load.Bool(restrictions + 8)) {
    88          restrictions_ffi["spellCheckEnabled"] = A.load.Bool(restrictions + 3);
    89        }
    90        if (A.load.Bool(restrictions + 9)) {
    91          restrictions_ffi["voiceInputEnabled"] = A.load.Bool(restrictions + 4);
    92        }
    93  
    94        const _ret = WEBEXT.virtualKeyboard.restrictFeatures(restrictions_ffi);
    95        A.store.Ref(retPtr, _ret);
    96      },
    97      "try_RestrictFeatures": (retPtr: Pointer, errPtr: Pointer, restrictions: Pointer): heap.Ref<boolean> => {
    98        try {
    99          const restrictions_ffi = {};
   100  
   101          if (A.load.Bool(restrictions + 5)) {
   102            restrictions_ffi["autoCompleteEnabled"] = A.load.Bool(restrictions + 0);
   103          }
   104          if (A.load.Bool(restrictions + 6)) {
   105            restrictions_ffi["autoCorrectEnabled"] = A.load.Bool(restrictions + 1);
   106          }
   107          if (A.load.Bool(restrictions + 7)) {
   108            restrictions_ffi["handwritingEnabled"] = A.load.Bool(restrictions + 2);
   109          }
   110          if (A.load.Bool(restrictions + 8)) {
   111            restrictions_ffi["spellCheckEnabled"] = A.load.Bool(restrictions + 3);
   112          }
   113          if (A.load.Bool(restrictions + 9)) {
   114            restrictions_ffi["voiceInputEnabled"] = A.load.Bool(restrictions + 4);
   115          }
   116  
   117          const _ret = WEBEXT.virtualKeyboard.restrictFeatures(restrictions_ffi);
   118          A.store.Ref(retPtr, _ret);
   119          return A.H.TRUE;
   120        } catch (err: any) {
   121          A.store.Ref(errPtr, err);
   122          return A.H.FALSE;
   123        }
   124      },
   125    };
   126  });