github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/settingsprivate/bindings/ffi_bindings.ts (about) 1 import { importModule, Application, heap, Pointer } from "@ffi"; 2 3 importModule("plat/js/webext/settingsprivate", (A: Application) => { 4 const WEBEXT = typeof globalThis.browser === "undefined" ? globalThis.chrome : globalThis.browser; 5 6 return { 7 "constof_ControlledBy": (ref: heap.Ref<string>): number => { 8 const idx = [ 9 "DEVICE_POLICY", 10 "USER_POLICY", 11 "OWNER", 12 "PRIMARY_USER", 13 "EXTENSION", 14 "PARENT", 15 "CHILD_RESTRICTION", 16 ].indexOf(A.H.get(ref)); 17 return idx < 0 ? 0 : idx + 1; 18 }, 19 "constof_Enforcement": (ref: heap.Ref<string>): number => { 20 const idx = ["ENFORCED", "RECOMMENDED", "PARENT_SUPERVISED"].indexOf(A.H.get(ref)); 21 return idx < 0 ? 0 : idx + 1; 22 }, 23 "constof_PrefType": (ref: heap.Ref<string>): number => { 24 const idx = ["BOOLEAN", "NUMBER", "STRING", "URL", "LIST", "DICTIONARY"].indexOf(A.H.get(ref)); 25 return idx < 0 ? 0 : idx + 1; 26 }, 27 28 "store_PrefObject": (ptr: Pointer, ref: heap.Ref<any>) => { 29 const x = A.H.get<any>(ref); 30 31 if (typeof x === "undefined") { 32 A.store.Bool(ptr + 43, false); 33 A.store.Ref(ptr + 0, undefined); 34 A.store.Enum(ptr + 4, -1); 35 A.store.Ref(ptr + 8, undefined); 36 A.store.Enum(ptr + 12, -1); 37 A.store.Ref(ptr + 16, undefined); 38 A.store.Enum(ptr + 20, -1); 39 A.store.Ref(ptr + 24, undefined); 40 A.store.Ref(ptr + 28, undefined); 41 A.store.Bool(ptr + 41, false); 42 A.store.Bool(ptr + 32, false); 43 A.store.Ref(ptr + 36, undefined); 44 A.store.Bool(ptr + 42, false); 45 A.store.Bool(ptr + 40, false); 46 } else { 47 A.store.Bool(ptr + 43, true); 48 A.store.Ref(ptr + 0, x["key"]); 49 A.store.Enum( 50 ptr + 4, 51 ["BOOLEAN", "NUMBER", "STRING", "URL", "LIST", "DICTIONARY"].indexOf(x["type"] as string) 52 ); 53 A.store.Ref(ptr + 8, x["value"]); 54 A.store.Enum( 55 ptr + 12, 56 ["DEVICE_POLICY", "USER_POLICY", "OWNER", "PRIMARY_USER", "EXTENSION", "PARENT", "CHILD_RESTRICTION"].indexOf( 57 x["controlledBy"] as string 58 ) 59 ); 60 A.store.Ref(ptr + 16, x["controlledByName"]); 61 A.store.Enum(ptr + 20, ["ENFORCED", "RECOMMENDED", "PARENT_SUPERVISED"].indexOf(x["enforcement"] as string)); 62 A.store.Ref(ptr + 24, x["recommendedValue"]); 63 A.store.Ref(ptr + 28, x["userSelectableValues"]); 64 A.store.Bool(ptr + 41, "userControlDisabled" in x ? true : false); 65 A.store.Bool(ptr + 32, x["userControlDisabled"] ? true : false); 66 A.store.Ref(ptr + 36, x["extensionId"]); 67 A.store.Bool(ptr + 42, "extensionCanBeDisabled" in x ? true : false); 68 A.store.Bool(ptr + 40, x["extensionCanBeDisabled"] ? true : false); 69 } 70 }, 71 "load_PrefObject": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => { 72 const x = create === A.H.TRUE ? {} : A.H.get<any>(ref); 73 74 x["key"] = A.load.Ref(ptr + 0, undefined); 75 x["type"] = A.load.Enum(ptr + 4, ["BOOLEAN", "NUMBER", "STRING", "URL", "LIST", "DICTIONARY"]); 76 x["value"] = A.load.Ref(ptr + 8, undefined); 77 x["controlledBy"] = A.load.Enum(ptr + 12, [ 78 "DEVICE_POLICY", 79 "USER_POLICY", 80 "OWNER", 81 "PRIMARY_USER", 82 "EXTENSION", 83 "PARENT", 84 "CHILD_RESTRICTION", 85 ]); 86 x["controlledByName"] = A.load.Ref(ptr + 16, undefined); 87 x["enforcement"] = A.load.Enum(ptr + 20, ["ENFORCED", "RECOMMENDED", "PARENT_SUPERVISED"]); 88 x["recommendedValue"] = A.load.Ref(ptr + 24, undefined); 89 x["userSelectableValues"] = A.load.Ref(ptr + 28, undefined); 90 if (A.load.Bool(ptr + 41)) { 91 x["userControlDisabled"] = A.load.Bool(ptr + 32); 92 } else { 93 delete x["userControlDisabled"]; 94 } 95 x["extensionId"] = A.load.Ref(ptr + 36, undefined); 96 if (A.load.Bool(ptr + 42)) { 97 x["extensionCanBeDisabled"] = A.load.Bool(ptr + 40); 98 } else { 99 delete x["extensionCanBeDisabled"]; 100 } 101 return create === A.H.TRUE ? A.H.push(x) : ref; 102 }, 103 "has_GetAllPrefs": (): heap.Ref<boolean> => { 104 if (WEBEXT?.settingsPrivate && "getAllPrefs" in WEBEXT?.settingsPrivate) { 105 return A.H.TRUE; 106 } 107 return A.H.FALSE; 108 }, 109 "func_GetAllPrefs": (fn: Pointer): void => { 110 A.store.Ref(fn, WEBEXT.settingsPrivate.getAllPrefs); 111 }, 112 "call_GetAllPrefs": (retPtr: Pointer): void => { 113 const _ret = WEBEXT.settingsPrivate.getAllPrefs(); 114 A.store.Ref(retPtr, _ret); 115 }, 116 "try_GetAllPrefs": (retPtr: Pointer, errPtr: Pointer): heap.Ref<boolean> => { 117 try { 118 const _ret = WEBEXT.settingsPrivate.getAllPrefs(); 119 A.store.Ref(retPtr, _ret); 120 return A.H.TRUE; 121 } catch (err: any) { 122 A.store.Ref(errPtr, err); 123 return A.H.FALSE; 124 } 125 }, 126 "has_GetDefaultZoom": (): heap.Ref<boolean> => { 127 if (WEBEXT?.settingsPrivate && "getDefaultZoom" in WEBEXT?.settingsPrivate) { 128 return A.H.TRUE; 129 } 130 return A.H.FALSE; 131 }, 132 "func_GetDefaultZoom": (fn: Pointer): void => { 133 A.store.Ref(fn, WEBEXT.settingsPrivate.getDefaultZoom); 134 }, 135 "call_GetDefaultZoom": (retPtr: Pointer): void => { 136 const _ret = WEBEXT.settingsPrivate.getDefaultZoom(); 137 A.store.Ref(retPtr, _ret); 138 }, 139 "try_GetDefaultZoom": (retPtr: Pointer, errPtr: Pointer): heap.Ref<boolean> => { 140 try { 141 const _ret = WEBEXT.settingsPrivate.getDefaultZoom(); 142 A.store.Ref(retPtr, _ret); 143 return A.H.TRUE; 144 } catch (err: any) { 145 A.store.Ref(errPtr, err); 146 return A.H.FALSE; 147 } 148 }, 149 "has_GetPref": (): heap.Ref<boolean> => { 150 if (WEBEXT?.settingsPrivate && "getPref" in WEBEXT?.settingsPrivate) { 151 return A.H.TRUE; 152 } 153 return A.H.FALSE; 154 }, 155 "func_GetPref": (fn: Pointer): void => { 156 A.store.Ref(fn, WEBEXT.settingsPrivate.getPref); 157 }, 158 "call_GetPref": (retPtr: Pointer, name: heap.Ref<object>): void => { 159 const _ret = WEBEXT.settingsPrivate.getPref(A.H.get<object>(name)); 160 A.store.Ref(retPtr, _ret); 161 }, 162 "try_GetPref": (retPtr: Pointer, errPtr: Pointer, name: heap.Ref<object>): heap.Ref<boolean> => { 163 try { 164 const _ret = WEBEXT.settingsPrivate.getPref(A.H.get<object>(name)); 165 A.store.Ref(retPtr, _ret); 166 return A.H.TRUE; 167 } catch (err: any) { 168 A.store.Ref(errPtr, err); 169 return A.H.FALSE; 170 } 171 }, 172 "has_OnPrefsChanged": (): heap.Ref<boolean> => { 173 if (WEBEXT?.settingsPrivate?.onPrefsChanged && "addListener" in WEBEXT?.settingsPrivate?.onPrefsChanged) { 174 return A.H.TRUE; 175 } 176 return A.H.FALSE; 177 }, 178 "func_OnPrefsChanged": (fn: Pointer): void => { 179 A.store.Ref(fn, WEBEXT.settingsPrivate.onPrefsChanged.addListener); 180 }, 181 "call_OnPrefsChanged": (retPtr: Pointer, callback: heap.Ref<object>): void => { 182 const _ret = WEBEXT.settingsPrivate.onPrefsChanged.addListener(A.H.get<object>(callback)); 183 }, 184 "try_OnPrefsChanged": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => { 185 try { 186 const _ret = WEBEXT.settingsPrivate.onPrefsChanged.addListener(A.H.get<object>(callback)); 187 return A.H.TRUE; 188 } catch (err: any) { 189 A.store.Ref(errPtr, err); 190 return A.H.FALSE; 191 } 192 }, 193 "has_OffPrefsChanged": (): heap.Ref<boolean> => { 194 if (WEBEXT?.settingsPrivate?.onPrefsChanged && "removeListener" in WEBEXT?.settingsPrivate?.onPrefsChanged) { 195 return A.H.TRUE; 196 } 197 return A.H.FALSE; 198 }, 199 "func_OffPrefsChanged": (fn: Pointer): void => { 200 A.store.Ref(fn, WEBEXT.settingsPrivate.onPrefsChanged.removeListener); 201 }, 202 "call_OffPrefsChanged": (retPtr: Pointer, callback: heap.Ref<object>): void => { 203 const _ret = WEBEXT.settingsPrivate.onPrefsChanged.removeListener(A.H.get<object>(callback)); 204 }, 205 "try_OffPrefsChanged": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => { 206 try { 207 const _ret = WEBEXT.settingsPrivate.onPrefsChanged.removeListener(A.H.get<object>(callback)); 208 return A.H.TRUE; 209 } catch (err: any) { 210 A.store.Ref(errPtr, err); 211 return A.H.FALSE; 212 } 213 }, 214 "has_HasOnPrefsChanged": (): heap.Ref<boolean> => { 215 if (WEBEXT?.settingsPrivate?.onPrefsChanged && "hasListener" in WEBEXT?.settingsPrivate?.onPrefsChanged) { 216 return A.H.TRUE; 217 } 218 return A.H.FALSE; 219 }, 220 "func_HasOnPrefsChanged": (fn: Pointer): void => { 221 A.store.Ref(fn, WEBEXT.settingsPrivate.onPrefsChanged.hasListener); 222 }, 223 "call_HasOnPrefsChanged": (retPtr: Pointer, callback: heap.Ref<object>): void => { 224 const _ret = WEBEXT.settingsPrivate.onPrefsChanged.hasListener(A.H.get<object>(callback)); 225 A.store.Bool(retPtr, _ret); 226 }, 227 "try_HasOnPrefsChanged": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => { 228 try { 229 const _ret = WEBEXT.settingsPrivate.onPrefsChanged.hasListener(A.H.get<object>(callback)); 230 A.store.Bool(retPtr, _ret); 231 return A.H.TRUE; 232 } catch (err: any) { 233 A.store.Ref(errPtr, err); 234 return A.H.FALSE; 235 } 236 }, 237 "has_SetDefaultZoom": (): heap.Ref<boolean> => { 238 if (WEBEXT?.settingsPrivate && "setDefaultZoom" in WEBEXT?.settingsPrivate) { 239 return A.H.TRUE; 240 } 241 return A.H.FALSE; 242 }, 243 "func_SetDefaultZoom": (fn: Pointer): void => { 244 A.store.Ref(fn, WEBEXT.settingsPrivate.setDefaultZoom); 245 }, 246 "call_SetDefaultZoom": (retPtr: Pointer, zoom: number): void => { 247 const _ret = WEBEXT.settingsPrivate.setDefaultZoom(zoom); 248 A.store.Ref(retPtr, _ret); 249 }, 250 "try_SetDefaultZoom": (retPtr: Pointer, errPtr: Pointer, zoom: number): heap.Ref<boolean> => { 251 try { 252 const _ret = WEBEXT.settingsPrivate.setDefaultZoom(zoom); 253 A.store.Ref(retPtr, _ret); 254 return A.H.TRUE; 255 } catch (err: any) { 256 A.store.Ref(errPtr, err); 257 return A.H.FALSE; 258 } 259 }, 260 "has_SetPref": (): heap.Ref<boolean> => { 261 if (WEBEXT?.settingsPrivate && "setPref" in WEBEXT?.settingsPrivate) { 262 return A.H.TRUE; 263 } 264 return A.H.FALSE; 265 }, 266 "func_SetPref": (fn: Pointer): void => { 267 A.store.Ref(fn, WEBEXT.settingsPrivate.setPref); 268 }, 269 "call_SetPref": ( 270 retPtr: Pointer, 271 name: heap.Ref<object>, 272 value: heap.Ref<object>, 273 pageId: heap.Ref<object> 274 ): void => { 275 const _ret = WEBEXT.settingsPrivate.setPref( 276 A.H.get<object>(name), 277 A.H.get<object>(value), 278 A.H.get<object>(pageId) 279 ); 280 A.store.Ref(retPtr, _ret); 281 }, 282 "try_SetPref": ( 283 retPtr: Pointer, 284 errPtr: Pointer, 285 name: heap.Ref<object>, 286 value: heap.Ref<object>, 287 pageId: heap.Ref<object> 288 ): heap.Ref<boolean> => { 289 try { 290 const _ret = WEBEXT.settingsPrivate.setPref( 291 A.H.get<object>(name), 292 A.H.get<object>(value), 293 A.H.get<object>(pageId) 294 ); 295 A.store.Ref(retPtr, _ret); 296 return A.H.TRUE; 297 } catch (err: any) { 298 A.store.Ref(errPtr, err); 299 return A.H.FALSE; 300 } 301 }, 302 }; 303 });