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

     1  import { importModule, Application, heap, Pointer } from "@ffi";
     2  
     3  importModule("plat/js/webext/chromeosinfoprivate", (A: Application) => {
     4    const WEBEXT = typeof globalThis.browser === "undefined" ? globalThis.chrome : globalThis.browser;
     5  
     6    return {
     7      "constof_AssistantStatus": (ref: heap.Ref<string>): number => {
     8        const idx = ["unsupported", "supported"].indexOf(A.H.get(ref));
     9        return idx < 0 ? 0 : idx + 1;
    10      },
    11      "constof_DeviceType": (ref: heap.Ref<string>): number => {
    12        const idx = ["chromebase", "chromebit", "chromebook", "chromebox", "chromedevice"].indexOf(A.H.get(ref));
    13        return idx < 0 ? 0 : idx + 1;
    14      },
    15      "constof_ManagedDeviceStatus": (ref: heap.Ref<string>): number => {
    16        const idx = ["managed", "not managed"].indexOf(A.H.get(ref));
    17        return idx < 0 ? 0 : idx + 1;
    18      },
    19      "constof_PlayStoreStatus": (ref: heap.Ref<string>): number => {
    20        const idx = ["not available", "available", "enabled"].indexOf(A.H.get(ref));
    21        return idx < 0 ? 0 : idx + 1;
    22      },
    23      "constof_SessionType": (ref: heap.Ref<string>): number => {
    24        const idx = ["normal", "kiosk", "public session"].indexOf(A.H.get(ref));
    25        return idx < 0 ? 0 : idx + 1;
    26      },
    27      "constof_StylusStatus": (ref: heap.Ref<string>): number => {
    28        const idx = ["unsupported", "supported", "seen"].indexOf(A.H.get(ref));
    29        return idx < 0 ? 0 : idx + 1;
    30      },
    31  
    32      "store_GetReturnType": (ptr: Pointer, ref: heap.Ref<any>) => {
    33        const x = A.H.get<any>(ref);
    34  
    35        if (typeof x === "undefined") {
    36          A.store.Bool(ptr + 97, false);
    37          A.store.Bool(ptr + 80, false);
    38          A.store.Bool(ptr + 0, false);
    39          A.store.Bool(ptr + 81, false);
    40          A.store.Bool(ptr + 1, false);
    41          A.store.Bool(ptr + 82, false);
    42          A.store.Bool(ptr + 2, false);
    43          A.store.Bool(ptr + 83, false);
    44          A.store.Bool(ptr + 3, false);
    45          A.store.Bool(ptr + 84, false);
    46          A.store.Bool(ptr + 4, false);
    47          A.store.Bool(ptr + 85, false);
    48          A.store.Bool(ptr + 5, false);
    49          A.store.Bool(ptr + 86, false);
    50          A.store.Bool(ptr + 6, false);
    51          A.store.Bool(ptr + 87, false);
    52          A.store.Bool(ptr + 7, false);
    53          A.store.Bool(ptr + 88, false);
    54          A.store.Bool(ptr + 8, false);
    55          A.store.Bool(ptr + 89, false);
    56          A.store.Bool(ptr + 9, false);
    57          A.store.Bool(ptr + 90, false);
    58          A.store.Bool(ptr + 10, false);
    59          A.store.Bool(ptr + 91, false);
    60          A.store.Bool(ptr + 11, false);
    61          A.store.Bool(ptr + 92, false);
    62          A.store.Bool(ptr + 12, false);
    63          A.store.Bool(ptr + 93, false);
    64          A.store.Bool(ptr + 13, false);
    65          A.store.Enum(ptr + 16, -1);
    66          A.store.Ref(ptr + 20, undefined);
    67          A.store.Ref(ptr + 24, undefined);
    68          A.store.Ref(ptr + 28, undefined);
    69          A.store.Enum(ptr + 32, -1);
    70          A.store.Ref(ptr + 36, undefined);
    71          A.store.Ref(ptr + 40, undefined);
    72          A.store.Ref(ptr + 44, undefined);
    73          A.store.Bool(ptr + 94, false);
    74          A.store.Bool(ptr + 48, false);
    75          A.store.Bool(ptr + 95, false);
    76          A.store.Bool(ptr + 49, false);
    77          A.store.Enum(ptr + 52, -1);
    78          A.store.Enum(ptr + 56, -1);
    79          A.store.Bool(ptr + 96, false);
    80          A.store.Bool(ptr + 60, false);
    81          A.store.Enum(ptr + 64, -1);
    82          A.store.Enum(ptr + 68, -1);
    83          A.store.Ref(ptr + 72, undefined);
    84          A.store.Ref(ptr + 76, undefined);
    85        } else {
    86          A.store.Bool(ptr + 97, true);
    87          A.store.Bool(ptr + 80, "a11yAutoClickEnabled" in x ? true : false);
    88          A.store.Bool(ptr + 0, x["a11yAutoClickEnabled"] ? true : false);
    89          A.store.Bool(ptr + 81, "a11yCaretHighlightEnabled" in x ? true : false);
    90          A.store.Bool(ptr + 1, x["a11yCaretHighlightEnabled"] ? true : false);
    91          A.store.Bool(ptr + 82, "a11yCursorColorEnabled" in x ? true : false);
    92          A.store.Bool(ptr + 2, x["a11yCursorColorEnabled"] ? true : false);
    93          A.store.Bool(ptr + 83, "a11yCursorHighlightEnabled" in x ? true : false);
    94          A.store.Bool(ptr + 3, x["a11yCursorHighlightEnabled"] ? true : false);
    95          A.store.Bool(ptr + 84, "a11yDockedMagnifierEnabled" in x ? true : false);
    96          A.store.Bool(ptr + 4, x["a11yDockedMagnifierEnabled"] ? true : false);
    97          A.store.Bool(ptr + 85, "a11yFocusHighlightEnabled" in x ? true : false);
    98          A.store.Bool(ptr + 5, x["a11yFocusHighlightEnabled"] ? true : false);
    99          A.store.Bool(ptr + 86, "a11yHighContrastEnabled" in x ? true : false);
   100          A.store.Bool(ptr + 6, x["a11yHighContrastEnabled"] ? true : false);
   101          A.store.Bool(ptr + 87, "a11yLargeCursorEnabled" in x ? true : false);
   102          A.store.Bool(ptr + 7, x["a11yLargeCursorEnabled"] ? true : false);
   103          A.store.Bool(ptr + 88, "a11yScreenMagnifierEnabled" in x ? true : false);
   104          A.store.Bool(ptr + 8, x["a11yScreenMagnifierEnabled"] ? true : false);
   105          A.store.Bool(ptr + 89, "a11ySelectToSpeakEnabled" in x ? true : false);
   106          A.store.Bool(ptr + 9, x["a11ySelectToSpeakEnabled"] ? true : false);
   107          A.store.Bool(ptr + 90, "a11ySpokenFeedbackEnabled" in x ? true : false);
   108          A.store.Bool(ptr + 10, x["a11ySpokenFeedbackEnabled"] ? true : false);
   109          A.store.Bool(ptr + 91, "a11yStickyKeysEnabled" in x ? true : false);
   110          A.store.Bool(ptr + 11, x["a11yStickyKeysEnabled"] ? true : false);
   111          A.store.Bool(ptr + 92, "a11ySwitchAccessEnabled" in x ? true : false);
   112          A.store.Bool(ptr + 12, x["a11ySwitchAccessEnabled"] ? true : false);
   113          A.store.Bool(ptr + 93, "a11yVirtualKeyboardEnabled" in x ? true : false);
   114          A.store.Bool(ptr + 13, x["a11yVirtualKeyboardEnabled"] ? true : false);
   115          A.store.Enum(ptr + 16, ["unsupported", "supported"].indexOf(x["assistantStatus"] as string));
   116          A.store.Ref(ptr + 20, x["board"]);
   117          A.store.Ref(ptr + 24, x["clientId"]);
   118          A.store.Ref(ptr + 28, x["customizationId"]);
   119          A.store.Enum(
   120            ptr + 32,
   121            ["chromebase", "chromebit", "chromebook", "chromebox", "chromedevice"].indexOf(x["deviceType"] as string)
   122          );
   123          A.store.Ref(ptr + 36, x["homeProvider"]);
   124          A.store.Ref(ptr + 40, x["hwid"]);
   125          A.store.Ref(ptr + 44, x["initialLocale"]);
   126          A.store.Bool(ptr + 94, "isMeetDevice" in x ? true : false);
   127          A.store.Bool(ptr + 48, x["isMeetDevice"] ? true : false);
   128          A.store.Bool(ptr + 95, "isOwner" in x ? true : false);
   129          A.store.Bool(ptr + 49, x["isOwner"] ? true : false);
   130          A.store.Enum(ptr + 52, ["managed", "not managed"].indexOf(x["managedDeviceStatus"] as string));
   131          A.store.Enum(ptr + 56, ["not available", "available", "enabled"].indexOf(x["playStoreStatus"] as string));
   132          A.store.Bool(ptr + 96, "sendFunctionKeys" in x ? true : false);
   133          A.store.Bool(ptr + 60, x["sendFunctionKeys"] ? true : false);
   134          A.store.Enum(ptr + 64, ["normal", "kiosk", "public session"].indexOf(x["sessionType"] as string));
   135          A.store.Enum(ptr + 68, ["unsupported", "supported", "seen"].indexOf(x["stylusStatus"] as string));
   136          A.store.Ref(ptr + 72, x["supportedTimezones"]);
   137          A.store.Ref(ptr + 76, x["timezone"]);
   138        }
   139      },
   140      "load_GetReturnType": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => {
   141        const x = create === A.H.TRUE ? {} : A.H.get<any>(ref);
   142  
   143        if (A.load.Bool(ptr + 80)) {
   144          x["a11yAutoClickEnabled"] = A.load.Bool(ptr + 0);
   145        } else {
   146          delete x["a11yAutoClickEnabled"];
   147        }
   148        if (A.load.Bool(ptr + 81)) {
   149          x["a11yCaretHighlightEnabled"] = A.load.Bool(ptr + 1);
   150        } else {
   151          delete x["a11yCaretHighlightEnabled"];
   152        }
   153        if (A.load.Bool(ptr + 82)) {
   154          x["a11yCursorColorEnabled"] = A.load.Bool(ptr + 2);
   155        } else {
   156          delete x["a11yCursorColorEnabled"];
   157        }
   158        if (A.load.Bool(ptr + 83)) {
   159          x["a11yCursorHighlightEnabled"] = A.load.Bool(ptr + 3);
   160        } else {
   161          delete x["a11yCursorHighlightEnabled"];
   162        }
   163        if (A.load.Bool(ptr + 84)) {
   164          x["a11yDockedMagnifierEnabled"] = A.load.Bool(ptr + 4);
   165        } else {
   166          delete x["a11yDockedMagnifierEnabled"];
   167        }
   168        if (A.load.Bool(ptr + 85)) {
   169          x["a11yFocusHighlightEnabled"] = A.load.Bool(ptr + 5);
   170        } else {
   171          delete x["a11yFocusHighlightEnabled"];
   172        }
   173        if (A.load.Bool(ptr + 86)) {
   174          x["a11yHighContrastEnabled"] = A.load.Bool(ptr + 6);
   175        } else {
   176          delete x["a11yHighContrastEnabled"];
   177        }
   178        if (A.load.Bool(ptr + 87)) {
   179          x["a11yLargeCursorEnabled"] = A.load.Bool(ptr + 7);
   180        } else {
   181          delete x["a11yLargeCursorEnabled"];
   182        }
   183        if (A.load.Bool(ptr + 88)) {
   184          x["a11yScreenMagnifierEnabled"] = A.load.Bool(ptr + 8);
   185        } else {
   186          delete x["a11yScreenMagnifierEnabled"];
   187        }
   188        if (A.load.Bool(ptr + 89)) {
   189          x["a11ySelectToSpeakEnabled"] = A.load.Bool(ptr + 9);
   190        } else {
   191          delete x["a11ySelectToSpeakEnabled"];
   192        }
   193        if (A.load.Bool(ptr + 90)) {
   194          x["a11ySpokenFeedbackEnabled"] = A.load.Bool(ptr + 10);
   195        } else {
   196          delete x["a11ySpokenFeedbackEnabled"];
   197        }
   198        if (A.load.Bool(ptr + 91)) {
   199          x["a11yStickyKeysEnabled"] = A.load.Bool(ptr + 11);
   200        } else {
   201          delete x["a11yStickyKeysEnabled"];
   202        }
   203        if (A.load.Bool(ptr + 92)) {
   204          x["a11ySwitchAccessEnabled"] = A.load.Bool(ptr + 12);
   205        } else {
   206          delete x["a11ySwitchAccessEnabled"];
   207        }
   208        if (A.load.Bool(ptr + 93)) {
   209          x["a11yVirtualKeyboardEnabled"] = A.load.Bool(ptr + 13);
   210        } else {
   211          delete x["a11yVirtualKeyboardEnabled"];
   212        }
   213        x["assistantStatus"] = A.load.Enum(ptr + 16, ["unsupported", "supported"]);
   214        x["board"] = A.load.Ref(ptr + 20, undefined);
   215        x["clientId"] = A.load.Ref(ptr + 24, undefined);
   216        x["customizationId"] = A.load.Ref(ptr + 28, undefined);
   217        x["deviceType"] = A.load.Enum(ptr + 32, ["chromebase", "chromebit", "chromebook", "chromebox", "chromedevice"]);
   218        x["homeProvider"] = A.load.Ref(ptr + 36, undefined);
   219        x["hwid"] = A.load.Ref(ptr + 40, undefined);
   220        x["initialLocale"] = A.load.Ref(ptr + 44, undefined);
   221        if (A.load.Bool(ptr + 94)) {
   222          x["isMeetDevice"] = A.load.Bool(ptr + 48);
   223        } else {
   224          delete x["isMeetDevice"];
   225        }
   226        if (A.load.Bool(ptr + 95)) {
   227          x["isOwner"] = A.load.Bool(ptr + 49);
   228        } else {
   229          delete x["isOwner"];
   230        }
   231        x["managedDeviceStatus"] = A.load.Enum(ptr + 52, ["managed", "not managed"]);
   232        x["playStoreStatus"] = A.load.Enum(ptr + 56, ["not available", "available", "enabled"]);
   233        if (A.load.Bool(ptr + 96)) {
   234          x["sendFunctionKeys"] = A.load.Bool(ptr + 60);
   235        } else {
   236          delete x["sendFunctionKeys"];
   237        }
   238        x["sessionType"] = A.load.Enum(ptr + 64, ["normal", "kiosk", "public session"]);
   239        x["stylusStatus"] = A.load.Enum(ptr + 68, ["unsupported", "supported", "seen"]);
   240        x["supportedTimezones"] = A.load.Ref(ptr + 72, undefined);
   241        x["timezone"] = A.load.Ref(ptr + 76, undefined);
   242        return create === A.H.TRUE ? A.H.push(x) : ref;
   243      },
   244      "constof_PropertyName": (ref: heap.Ref<string>): number => {
   245        const idx = [
   246          "timezone",
   247          "a11yLargeCursorEnabled",
   248          "a11yStickyKeysEnabled",
   249          "a11ySpokenFeedbackEnabled",
   250          "a11yHighContrastEnabled",
   251          "a11yScreenMagnifierEnabled",
   252          "a11yAutoClickEnabled",
   253          "a11yVirtualKeyboardEnabled",
   254          "a11yCaretHighlightEnabled",
   255          "a11yCursorHighlightEnabled",
   256          "a11yFocusHighlightEnabled",
   257          "a11ySelectToSpeakEnabled",
   258          "a11ySwitchAccessEnabled",
   259          "a11yCursorColorEnabled",
   260          "a11yDockedMagnifierEnabled",
   261          "sendFunctionKeys",
   262        ].indexOf(A.H.get(ref));
   263        return idx < 0 ? 0 : idx + 1;
   264      },
   265      "has_Get": (): heap.Ref<boolean> => {
   266        if (WEBEXT?.chromeosInfoPrivate && "get" in WEBEXT?.chromeosInfoPrivate) {
   267          return A.H.TRUE;
   268        }
   269        return A.H.FALSE;
   270      },
   271      "func_Get": (fn: Pointer): void => {
   272        A.store.Ref(fn, WEBEXT.chromeosInfoPrivate.get);
   273      },
   274      "call_Get": (retPtr: Pointer, propertyNames: heap.Ref<object>): void => {
   275        const _ret = WEBEXT.chromeosInfoPrivate.get(A.H.get<object>(propertyNames));
   276        A.store.Ref(retPtr, _ret);
   277      },
   278      "try_Get": (retPtr: Pointer, errPtr: Pointer, propertyNames: heap.Ref<object>): heap.Ref<boolean> => {
   279        try {
   280          const _ret = WEBEXT.chromeosInfoPrivate.get(A.H.get<object>(propertyNames));
   281          A.store.Ref(retPtr, _ret);
   282          return A.H.TRUE;
   283        } catch (err: any) {
   284          A.store.Ref(errPtr, err);
   285          return A.H.FALSE;
   286        }
   287      },
   288      "has_IsTabletModeEnabled": (): heap.Ref<boolean> => {
   289        if (WEBEXT?.chromeosInfoPrivate && "isTabletModeEnabled" in WEBEXT?.chromeosInfoPrivate) {
   290          return A.H.TRUE;
   291        }
   292        return A.H.FALSE;
   293      },
   294      "func_IsTabletModeEnabled": (fn: Pointer): void => {
   295        A.store.Ref(fn, WEBEXT.chromeosInfoPrivate.isTabletModeEnabled);
   296      },
   297      "call_IsTabletModeEnabled": (retPtr: Pointer): void => {
   298        const _ret = WEBEXT.chromeosInfoPrivate.isTabletModeEnabled();
   299        A.store.Ref(retPtr, _ret);
   300      },
   301      "try_IsTabletModeEnabled": (retPtr: Pointer, errPtr: Pointer): heap.Ref<boolean> => {
   302        try {
   303          const _ret = WEBEXT.chromeosInfoPrivate.isTabletModeEnabled();
   304          A.store.Ref(retPtr, _ret);
   305          return A.H.TRUE;
   306        } catch (err: any) {
   307          A.store.Ref(errPtr, err);
   308          return A.H.FALSE;
   309        }
   310      },
   311      "has_Set": (): heap.Ref<boolean> => {
   312        if (WEBEXT?.chromeosInfoPrivate && "set" in WEBEXT?.chromeosInfoPrivate) {
   313          return A.H.TRUE;
   314        }
   315        return A.H.FALSE;
   316      },
   317      "func_Set": (fn: Pointer): void => {
   318        A.store.Ref(fn, WEBEXT.chromeosInfoPrivate.set);
   319      },
   320      "call_Set": (retPtr: Pointer, propertyName: number, propertyValue: heap.Ref<object>): void => {
   321        const _ret = WEBEXT.chromeosInfoPrivate.set(
   322          propertyName > 0 && propertyName <= 16
   323            ? [
   324                "timezone",
   325                "a11yLargeCursorEnabled",
   326                "a11yStickyKeysEnabled",
   327                "a11ySpokenFeedbackEnabled",
   328                "a11yHighContrastEnabled",
   329                "a11yScreenMagnifierEnabled",
   330                "a11yAutoClickEnabled",
   331                "a11yVirtualKeyboardEnabled",
   332                "a11yCaretHighlightEnabled",
   333                "a11yCursorHighlightEnabled",
   334                "a11yFocusHighlightEnabled",
   335                "a11ySelectToSpeakEnabled",
   336                "a11ySwitchAccessEnabled",
   337                "a11yCursorColorEnabled",
   338                "a11yDockedMagnifierEnabled",
   339                "sendFunctionKeys",
   340              ][propertyName - 1]
   341            : undefined,
   342          A.H.get<object>(propertyValue)
   343        );
   344      },
   345      "try_Set": (
   346        retPtr: Pointer,
   347        errPtr: Pointer,
   348        propertyName: number,
   349        propertyValue: heap.Ref<object>
   350      ): heap.Ref<boolean> => {
   351        try {
   352          const _ret = WEBEXT.chromeosInfoPrivate.set(
   353            propertyName > 0 && propertyName <= 16
   354              ? [
   355                  "timezone",
   356                  "a11yLargeCursorEnabled",
   357                  "a11yStickyKeysEnabled",
   358                  "a11ySpokenFeedbackEnabled",
   359                  "a11yHighContrastEnabled",
   360                  "a11yScreenMagnifierEnabled",
   361                  "a11yAutoClickEnabled",
   362                  "a11yVirtualKeyboardEnabled",
   363                  "a11yCaretHighlightEnabled",
   364                  "a11yCursorHighlightEnabled",
   365                  "a11yFocusHighlightEnabled",
   366                  "a11ySelectToSpeakEnabled",
   367                  "a11ySwitchAccessEnabled",
   368                  "a11yCursorColorEnabled",
   369                  "a11yDockedMagnifierEnabled",
   370                  "sendFunctionKeys",
   371                ][propertyName - 1]
   372              : undefined,
   373            A.H.get<object>(propertyValue)
   374          );
   375          return A.H.TRUE;
   376        } catch (err: any) {
   377          A.store.Ref(errPtr, err);
   378          return A.H.FALSE;
   379        }
   380      },
   381    };
   382  });