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

     1  import { importModule, Application, heap, Pointer } from "@ffi";
     2  
     3  importModule("plat/js/webext/idle", (A: Application) => {
     4    const WEBEXT = typeof globalThis.browser === "undefined" ? globalThis.chrome : globalThis.browser;
     5  
     6    return {
     7      "constof_IdleState": (ref: heap.Ref<string>): number => {
     8        const idx = ["active", "idle", "locked"].indexOf(A.H.get(ref));
     9        return idx < 0 ? 0 : idx + 1;
    10      },
    11      "has_GetAutoLockDelay": (): heap.Ref<boolean> => {
    12        if (WEBEXT?.idle && "getAutoLockDelay" in WEBEXT?.idle) {
    13          return A.H.TRUE;
    14        }
    15        return A.H.FALSE;
    16      },
    17      "func_GetAutoLockDelay": (fn: Pointer): void => {
    18        A.store.Ref(fn, WEBEXT.idle.getAutoLockDelay);
    19      },
    20      "call_GetAutoLockDelay": (retPtr: Pointer): void => {
    21        const _ret = WEBEXT.idle.getAutoLockDelay();
    22        A.store.Ref(retPtr, _ret);
    23      },
    24      "try_GetAutoLockDelay": (retPtr: Pointer, errPtr: Pointer): heap.Ref<boolean> => {
    25        try {
    26          const _ret = WEBEXT.idle.getAutoLockDelay();
    27          A.store.Ref(retPtr, _ret);
    28          return A.H.TRUE;
    29        } catch (err: any) {
    30          A.store.Ref(errPtr, err);
    31          return A.H.FALSE;
    32        }
    33      },
    34      "has_OnStateChanged": (): heap.Ref<boolean> => {
    35        if (WEBEXT?.idle?.onStateChanged && "addListener" in WEBEXT?.idle?.onStateChanged) {
    36          return A.H.TRUE;
    37        }
    38        return A.H.FALSE;
    39      },
    40      "func_OnStateChanged": (fn: Pointer): void => {
    41        A.store.Ref(fn, WEBEXT.idle.onStateChanged.addListener);
    42      },
    43      "call_OnStateChanged": (retPtr: Pointer, callback: heap.Ref<object>): void => {
    44        const _ret = WEBEXT.idle.onStateChanged.addListener(A.H.get<object>(callback));
    45      },
    46      "try_OnStateChanged": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => {
    47        try {
    48          const _ret = WEBEXT.idle.onStateChanged.addListener(A.H.get<object>(callback));
    49          return A.H.TRUE;
    50        } catch (err: any) {
    51          A.store.Ref(errPtr, err);
    52          return A.H.FALSE;
    53        }
    54      },
    55      "has_OffStateChanged": (): heap.Ref<boolean> => {
    56        if (WEBEXT?.idle?.onStateChanged && "removeListener" in WEBEXT?.idle?.onStateChanged) {
    57          return A.H.TRUE;
    58        }
    59        return A.H.FALSE;
    60      },
    61      "func_OffStateChanged": (fn: Pointer): void => {
    62        A.store.Ref(fn, WEBEXT.idle.onStateChanged.removeListener);
    63      },
    64      "call_OffStateChanged": (retPtr: Pointer, callback: heap.Ref<object>): void => {
    65        const _ret = WEBEXT.idle.onStateChanged.removeListener(A.H.get<object>(callback));
    66      },
    67      "try_OffStateChanged": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => {
    68        try {
    69          const _ret = WEBEXT.idle.onStateChanged.removeListener(A.H.get<object>(callback));
    70          return A.H.TRUE;
    71        } catch (err: any) {
    72          A.store.Ref(errPtr, err);
    73          return A.H.FALSE;
    74        }
    75      },
    76      "has_HasOnStateChanged": (): heap.Ref<boolean> => {
    77        if (WEBEXT?.idle?.onStateChanged && "hasListener" in WEBEXT?.idle?.onStateChanged) {
    78          return A.H.TRUE;
    79        }
    80        return A.H.FALSE;
    81      },
    82      "func_HasOnStateChanged": (fn: Pointer): void => {
    83        A.store.Ref(fn, WEBEXT.idle.onStateChanged.hasListener);
    84      },
    85      "call_HasOnStateChanged": (retPtr: Pointer, callback: heap.Ref<object>): void => {
    86        const _ret = WEBEXT.idle.onStateChanged.hasListener(A.H.get<object>(callback));
    87        A.store.Bool(retPtr, _ret);
    88      },
    89      "try_HasOnStateChanged": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => {
    90        try {
    91          const _ret = WEBEXT.idle.onStateChanged.hasListener(A.H.get<object>(callback));
    92          A.store.Bool(retPtr, _ret);
    93          return A.H.TRUE;
    94        } catch (err: any) {
    95          A.store.Ref(errPtr, err);
    96          return A.H.FALSE;
    97        }
    98      },
    99      "has_QueryState": (): heap.Ref<boolean> => {
   100        if (WEBEXT?.idle && "queryState" in WEBEXT?.idle) {
   101          return A.H.TRUE;
   102        }
   103        return A.H.FALSE;
   104      },
   105      "func_QueryState": (fn: Pointer): void => {
   106        A.store.Ref(fn, WEBEXT.idle.queryState);
   107      },
   108      "call_QueryState": (retPtr: Pointer, detectionIntervalInSeconds: number): void => {
   109        const _ret = WEBEXT.idle.queryState(detectionIntervalInSeconds);
   110        A.store.Ref(retPtr, _ret);
   111      },
   112      "try_QueryState": (retPtr: Pointer, errPtr: Pointer, detectionIntervalInSeconds: number): heap.Ref<boolean> => {
   113        try {
   114          const _ret = WEBEXT.idle.queryState(detectionIntervalInSeconds);
   115          A.store.Ref(retPtr, _ret);
   116          return A.H.TRUE;
   117        } catch (err: any) {
   118          A.store.Ref(errPtr, err);
   119          return A.H.FALSE;
   120        }
   121      },
   122      "has_SetDetectionInterval": (): heap.Ref<boolean> => {
   123        if (WEBEXT?.idle && "setDetectionInterval" in WEBEXT?.idle) {
   124          return A.H.TRUE;
   125        }
   126        return A.H.FALSE;
   127      },
   128      "func_SetDetectionInterval": (fn: Pointer): void => {
   129        A.store.Ref(fn, WEBEXT.idle.setDetectionInterval);
   130      },
   131      "call_SetDetectionInterval": (retPtr: Pointer, intervalInSeconds: number): void => {
   132        const _ret = WEBEXT.idle.setDetectionInterval(intervalInSeconds);
   133      },
   134      "try_SetDetectionInterval": (retPtr: Pointer, errPtr: Pointer, intervalInSeconds: number): heap.Ref<boolean> => {
   135        try {
   136          const _ret = WEBEXT.idle.setDetectionInterval(intervalInSeconds);
   137          return A.H.TRUE;
   138        } catch (err: any) {
   139          A.store.Ref(errPtr, err);
   140          return A.H.FALSE;
   141        }
   142      },
   143    };
   144  });