github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/printingmetrics/bindings/ffi_bindings.ts (about) 1 import { importModule, Application, heap, Pointer } from "@ffi"; 2 3 importModule("plat/js/webext/printingmetrics", (A: Application) => { 4 const WEBEXT = typeof globalThis.browser === "undefined" ? globalThis.chrome : globalThis.browser; 5 6 return { 7 "constof_ColorMode": (ref: heap.Ref<string>): number => { 8 const idx = ["BLACK_AND_WHITE", "COLOR"].indexOf(A.H.get(ref)); 9 return idx < 0 ? 0 : idx + 1; 10 }, 11 "constof_DuplexMode": (ref: heap.Ref<string>): number => { 12 const idx = ["ONE_SIDED", "TWO_SIDED_LONG_EDGE", "TWO_SIDED_SHORT_EDGE"].indexOf(A.H.get(ref)); 13 return idx < 0 ? 0 : idx + 1; 14 }, 15 "constof_PrintJobSource": (ref: heap.Ref<string>): number => { 16 const idx = ["PRINT_PREVIEW", "ANDROID_APP", "EXTENSION"].indexOf(A.H.get(ref)); 17 return idx < 0 ? 0 : idx + 1; 18 }, 19 "constof_PrintJobStatus": (ref: heap.Ref<string>): number => { 20 const idx = ["FAILED", "CANCELED", "PRINTED"].indexOf(A.H.get(ref)); 21 return idx < 0 ? 0 : idx + 1; 22 }, 23 "constof_PrinterSource": (ref: heap.Ref<string>): number => { 24 const idx = ["USER", "POLICY"].indexOf(A.H.get(ref)); 25 return idx < 0 ? 0 : idx + 1; 26 }, 27 28 "store_Printer": (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 + 12, false); 33 A.store.Ref(ptr + 0, undefined); 34 A.store.Ref(ptr + 4, undefined); 35 A.store.Enum(ptr + 8, -1); 36 } else { 37 A.store.Bool(ptr + 12, true); 38 A.store.Ref(ptr + 0, x["name"]); 39 A.store.Ref(ptr + 4, x["uri"]); 40 A.store.Enum(ptr + 8, ["USER", "POLICY"].indexOf(x["source"] as string)); 41 } 42 }, 43 "load_Printer": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => { 44 const x = create === A.H.TRUE ? {} : A.H.get<any>(ref); 45 46 x["name"] = A.load.Ref(ptr + 0, undefined); 47 x["uri"] = A.load.Ref(ptr + 4, undefined); 48 x["source"] = A.load.Enum(ptr + 8, ["USER", "POLICY"]); 49 return create === A.H.TRUE ? A.H.push(x) : ref; 50 }, 51 52 "store_MediaSize": (ptr: Pointer, ref: heap.Ref<any>) => { 53 const x = A.H.get<any>(ref); 54 55 if (typeof x === "undefined") { 56 A.store.Bool(ptr + 14, false); 57 A.store.Bool(ptr + 12, false); 58 A.store.Int32(ptr + 0, 0); 59 A.store.Bool(ptr + 13, false); 60 A.store.Int32(ptr + 4, 0); 61 A.store.Ref(ptr + 8, undefined); 62 } else { 63 A.store.Bool(ptr + 14, true); 64 A.store.Bool(ptr + 12, "width" in x ? true : false); 65 A.store.Int32(ptr + 0, x["width"] === undefined ? 0 : (x["width"] as number)); 66 A.store.Bool(ptr + 13, "height" in x ? true : false); 67 A.store.Int32(ptr + 4, x["height"] === undefined ? 0 : (x["height"] as number)); 68 A.store.Ref(ptr + 8, x["vendorId"]); 69 } 70 }, 71 "load_MediaSize": (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 if (A.load.Bool(ptr + 12)) { 75 x["width"] = A.load.Int32(ptr + 0); 76 } else { 77 delete x["width"]; 78 } 79 if (A.load.Bool(ptr + 13)) { 80 x["height"] = A.load.Int32(ptr + 4); 81 } else { 82 delete x["height"]; 83 } 84 x["vendorId"] = A.load.Ref(ptr + 8, undefined); 85 return create === A.H.TRUE ? A.H.push(x) : ref; 86 }, 87 88 "store_PrintSettings": (ptr: Pointer, ref: heap.Ref<any>) => { 89 const x = A.H.get<any>(ref); 90 91 if (typeof x === "undefined") { 92 A.store.Bool(ptr + 29, false); 93 A.store.Enum(ptr + 0, -1); 94 A.store.Enum(ptr + 4, -1); 95 96 A.store.Bool(ptr + 8 + 14, false); 97 A.store.Bool(ptr + 8 + 12, false); 98 A.store.Int32(ptr + 8 + 0, 0); 99 A.store.Bool(ptr + 8 + 13, false); 100 A.store.Int32(ptr + 8 + 4, 0); 101 A.store.Ref(ptr + 8 + 8, undefined); 102 A.store.Bool(ptr + 28, false); 103 A.store.Int32(ptr + 24, 0); 104 } else { 105 A.store.Bool(ptr + 29, true); 106 A.store.Enum(ptr + 0, ["BLACK_AND_WHITE", "COLOR"].indexOf(x["color"] as string)); 107 A.store.Enum( 108 ptr + 4, 109 ["ONE_SIDED", "TWO_SIDED_LONG_EDGE", "TWO_SIDED_SHORT_EDGE"].indexOf(x["duplex"] as string) 110 ); 111 112 if (typeof x["mediaSize"] === "undefined") { 113 A.store.Bool(ptr + 8 + 14, false); 114 A.store.Bool(ptr + 8 + 12, false); 115 A.store.Int32(ptr + 8 + 0, 0); 116 A.store.Bool(ptr + 8 + 13, false); 117 A.store.Int32(ptr + 8 + 4, 0); 118 A.store.Ref(ptr + 8 + 8, undefined); 119 } else { 120 A.store.Bool(ptr + 8 + 14, true); 121 A.store.Bool(ptr + 8 + 12, "width" in x["mediaSize"] ? true : false); 122 A.store.Int32(ptr + 8 + 0, x["mediaSize"]["width"] === undefined ? 0 : (x["mediaSize"]["width"] as number)); 123 A.store.Bool(ptr + 8 + 13, "height" in x["mediaSize"] ? true : false); 124 A.store.Int32(ptr + 8 + 4, x["mediaSize"]["height"] === undefined ? 0 : (x["mediaSize"]["height"] as number)); 125 A.store.Ref(ptr + 8 + 8, x["mediaSize"]["vendorId"]); 126 } 127 A.store.Bool(ptr + 28, "copies" in x ? true : false); 128 A.store.Int32(ptr + 24, x["copies"] === undefined ? 0 : (x["copies"] as number)); 129 } 130 }, 131 "load_PrintSettings": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => { 132 const x = create === A.H.TRUE ? {} : A.H.get<any>(ref); 133 134 x["color"] = A.load.Enum(ptr + 0, ["BLACK_AND_WHITE", "COLOR"]); 135 x["duplex"] = A.load.Enum(ptr + 4, ["ONE_SIDED", "TWO_SIDED_LONG_EDGE", "TWO_SIDED_SHORT_EDGE"]); 136 if (A.load.Bool(ptr + 8 + 14)) { 137 x["mediaSize"] = {}; 138 if (A.load.Bool(ptr + 8 + 12)) { 139 x["mediaSize"]["width"] = A.load.Int32(ptr + 8 + 0); 140 } else { 141 delete x["mediaSize"]["width"]; 142 } 143 if (A.load.Bool(ptr + 8 + 13)) { 144 x["mediaSize"]["height"] = A.load.Int32(ptr + 8 + 4); 145 } else { 146 delete x["mediaSize"]["height"]; 147 } 148 x["mediaSize"]["vendorId"] = A.load.Ref(ptr + 8 + 8, undefined); 149 } else { 150 delete x["mediaSize"]; 151 } 152 if (A.load.Bool(ptr + 28)) { 153 x["copies"] = A.load.Int32(ptr + 24); 154 } else { 155 delete x["copies"]; 156 } 157 return create === A.H.TRUE ? A.H.push(x) : ref; 158 }, 159 160 "store_PrintJobInfo": (ptr: Pointer, ref: heap.Ref<any>) => { 161 const x = A.H.get<any>(ref); 162 163 if (typeof x === "undefined") { 164 A.store.Bool(ptr + 99, false); 165 A.store.Ref(ptr + 0, undefined); 166 A.store.Ref(ptr + 4, undefined); 167 A.store.Enum(ptr + 8, -1); 168 A.store.Ref(ptr + 12, undefined); 169 A.store.Enum(ptr + 16, -1); 170 A.store.Bool(ptr + 96, false); 171 A.store.Float64(ptr + 24, 0); 172 A.store.Bool(ptr + 97, false); 173 A.store.Float64(ptr + 32, 0); 174 175 A.store.Bool(ptr + 40 + 12, false); 176 A.store.Ref(ptr + 40 + 0, undefined); 177 A.store.Ref(ptr + 40 + 4, undefined); 178 A.store.Enum(ptr + 40 + 8, -1); 179 180 A.store.Bool(ptr + 56 + 29, false); 181 A.store.Enum(ptr + 56 + 0, -1); 182 A.store.Enum(ptr + 56 + 4, -1); 183 184 A.store.Bool(ptr + 56 + 8 + 14, false); 185 A.store.Bool(ptr + 56 + 8 + 12, false); 186 A.store.Int32(ptr + 56 + 8 + 0, 0); 187 A.store.Bool(ptr + 56 + 8 + 13, false); 188 A.store.Int32(ptr + 56 + 8 + 4, 0); 189 A.store.Ref(ptr + 56 + 8 + 8, undefined); 190 A.store.Bool(ptr + 56 + 28, false); 191 A.store.Int32(ptr + 56 + 24, 0); 192 A.store.Bool(ptr + 98, false); 193 A.store.Int32(ptr + 88, 0); 194 A.store.Enum(ptr + 92, -1); 195 } else { 196 A.store.Bool(ptr + 99, true); 197 A.store.Ref(ptr + 0, x["id"]); 198 A.store.Ref(ptr + 4, x["title"]); 199 A.store.Enum(ptr + 8, ["PRINT_PREVIEW", "ANDROID_APP", "EXTENSION"].indexOf(x["source"] as string)); 200 A.store.Ref(ptr + 12, x["sourceId"]); 201 A.store.Enum(ptr + 16, ["FAILED", "CANCELED", "PRINTED"].indexOf(x["status"] as string)); 202 A.store.Bool(ptr + 96, "creationTime" in x ? true : false); 203 A.store.Float64(ptr + 24, x["creationTime"] === undefined ? 0 : (x["creationTime"] as number)); 204 A.store.Bool(ptr + 97, "completionTime" in x ? true : false); 205 A.store.Float64(ptr + 32, x["completionTime"] === undefined ? 0 : (x["completionTime"] as number)); 206 207 if (typeof x["printer"] === "undefined") { 208 A.store.Bool(ptr + 40 + 12, false); 209 A.store.Ref(ptr + 40 + 0, undefined); 210 A.store.Ref(ptr + 40 + 4, undefined); 211 A.store.Enum(ptr + 40 + 8, -1); 212 } else { 213 A.store.Bool(ptr + 40 + 12, true); 214 A.store.Ref(ptr + 40 + 0, x["printer"]["name"]); 215 A.store.Ref(ptr + 40 + 4, x["printer"]["uri"]); 216 A.store.Enum(ptr + 40 + 8, ["USER", "POLICY"].indexOf(x["printer"]["source"] as string)); 217 } 218 219 if (typeof x["settings"] === "undefined") { 220 A.store.Bool(ptr + 56 + 29, false); 221 A.store.Enum(ptr + 56 + 0, -1); 222 A.store.Enum(ptr + 56 + 4, -1); 223 224 A.store.Bool(ptr + 56 + 8 + 14, false); 225 A.store.Bool(ptr + 56 + 8 + 12, false); 226 A.store.Int32(ptr + 56 + 8 + 0, 0); 227 A.store.Bool(ptr + 56 + 8 + 13, false); 228 A.store.Int32(ptr + 56 + 8 + 4, 0); 229 A.store.Ref(ptr + 56 + 8 + 8, undefined); 230 A.store.Bool(ptr + 56 + 28, false); 231 A.store.Int32(ptr + 56 + 24, 0); 232 } else { 233 A.store.Bool(ptr + 56 + 29, true); 234 A.store.Enum(ptr + 56 + 0, ["BLACK_AND_WHITE", "COLOR"].indexOf(x["settings"]["color"] as string)); 235 A.store.Enum( 236 ptr + 56 + 4, 237 ["ONE_SIDED", "TWO_SIDED_LONG_EDGE", "TWO_SIDED_SHORT_EDGE"].indexOf(x["settings"]["duplex"] as string) 238 ); 239 240 if (typeof x["settings"]["mediaSize"] === "undefined") { 241 A.store.Bool(ptr + 56 + 8 + 14, false); 242 A.store.Bool(ptr + 56 + 8 + 12, false); 243 A.store.Int32(ptr + 56 + 8 + 0, 0); 244 A.store.Bool(ptr + 56 + 8 + 13, false); 245 A.store.Int32(ptr + 56 + 8 + 4, 0); 246 A.store.Ref(ptr + 56 + 8 + 8, undefined); 247 } else { 248 A.store.Bool(ptr + 56 + 8 + 14, true); 249 A.store.Bool(ptr + 56 + 8 + 12, "width" in x["settings"]["mediaSize"] ? true : false); 250 A.store.Int32( 251 ptr + 56 + 8 + 0, 252 x["settings"]["mediaSize"]["width"] === undefined ? 0 : (x["settings"]["mediaSize"]["width"] as number) 253 ); 254 A.store.Bool(ptr + 56 + 8 + 13, "height" in x["settings"]["mediaSize"] ? true : false); 255 A.store.Int32( 256 ptr + 56 + 8 + 4, 257 x["settings"]["mediaSize"]["height"] === undefined ? 0 : (x["settings"]["mediaSize"]["height"] as number) 258 ); 259 A.store.Ref(ptr + 56 + 8 + 8, x["settings"]["mediaSize"]["vendorId"]); 260 } 261 A.store.Bool(ptr + 56 + 28, "copies" in x["settings"] ? true : false); 262 A.store.Int32(ptr + 56 + 24, x["settings"]["copies"] === undefined ? 0 : (x["settings"]["copies"] as number)); 263 } 264 A.store.Bool(ptr + 98, "numberOfPages" in x ? true : false); 265 A.store.Int32(ptr + 88, x["numberOfPages"] === undefined ? 0 : (x["numberOfPages"] as number)); 266 A.store.Enum( 267 ptr + 92, 268 [ 269 "DOOR_OPEN", 270 "TRAY_MISSING", 271 "OUT_OF_INK", 272 "OUT_OF_PAPER", 273 "OUTPUT_FULL", 274 "PAPER_JAM", 275 "GENERIC_ISSUE", 276 "STOPPED", 277 "UNREACHABLE", 278 "EXPIRED_CERTIFICATE", 279 "AVAILABLE", 280 ].indexOf(x["printer_status"] as string) 281 ); 282 } 283 }, 284 "load_PrintJobInfo": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => { 285 const x = create === A.H.TRUE ? {} : A.H.get<any>(ref); 286 287 x["id"] = A.load.Ref(ptr + 0, undefined); 288 x["title"] = A.load.Ref(ptr + 4, undefined); 289 x["source"] = A.load.Enum(ptr + 8, ["PRINT_PREVIEW", "ANDROID_APP", "EXTENSION"]); 290 x["sourceId"] = A.load.Ref(ptr + 12, undefined); 291 x["status"] = A.load.Enum(ptr + 16, ["FAILED", "CANCELED", "PRINTED"]); 292 if (A.load.Bool(ptr + 96)) { 293 x["creationTime"] = A.load.Float64(ptr + 24); 294 } else { 295 delete x["creationTime"]; 296 } 297 if (A.load.Bool(ptr + 97)) { 298 x["completionTime"] = A.load.Float64(ptr + 32); 299 } else { 300 delete x["completionTime"]; 301 } 302 if (A.load.Bool(ptr + 40 + 12)) { 303 x["printer"] = {}; 304 x["printer"]["name"] = A.load.Ref(ptr + 40 + 0, undefined); 305 x["printer"]["uri"] = A.load.Ref(ptr + 40 + 4, undefined); 306 x["printer"]["source"] = A.load.Enum(ptr + 40 + 8, ["USER", "POLICY"]); 307 } else { 308 delete x["printer"]; 309 } 310 if (A.load.Bool(ptr + 56 + 29)) { 311 x["settings"] = {}; 312 x["settings"]["color"] = A.load.Enum(ptr + 56 + 0, ["BLACK_AND_WHITE", "COLOR"]); 313 x["settings"]["duplex"] = A.load.Enum(ptr + 56 + 4, [ 314 "ONE_SIDED", 315 "TWO_SIDED_LONG_EDGE", 316 "TWO_SIDED_SHORT_EDGE", 317 ]); 318 if (A.load.Bool(ptr + 56 + 8 + 14)) { 319 x["settings"]["mediaSize"] = {}; 320 if (A.load.Bool(ptr + 56 + 8 + 12)) { 321 x["settings"]["mediaSize"]["width"] = A.load.Int32(ptr + 56 + 8 + 0); 322 } else { 323 delete x["settings"]["mediaSize"]["width"]; 324 } 325 if (A.load.Bool(ptr + 56 + 8 + 13)) { 326 x["settings"]["mediaSize"]["height"] = A.load.Int32(ptr + 56 + 8 + 4); 327 } else { 328 delete x["settings"]["mediaSize"]["height"]; 329 } 330 x["settings"]["mediaSize"]["vendorId"] = A.load.Ref(ptr + 56 + 8 + 8, undefined); 331 } else { 332 delete x["settings"]["mediaSize"]; 333 } 334 if (A.load.Bool(ptr + 56 + 28)) { 335 x["settings"]["copies"] = A.load.Int32(ptr + 56 + 24); 336 } else { 337 delete x["settings"]["copies"]; 338 } 339 } else { 340 delete x["settings"]; 341 } 342 if (A.load.Bool(ptr + 98)) { 343 x["numberOfPages"] = A.load.Int32(ptr + 88); 344 } else { 345 delete x["numberOfPages"]; 346 } 347 x["printer_status"] = A.load.Enum(ptr + 92, [ 348 "DOOR_OPEN", 349 "TRAY_MISSING", 350 "OUT_OF_INK", 351 "OUT_OF_PAPER", 352 "OUTPUT_FULL", 353 "PAPER_JAM", 354 "GENERIC_ISSUE", 355 "STOPPED", 356 "UNREACHABLE", 357 "EXPIRED_CERTIFICATE", 358 "AVAILABLE", 359 ]); 360 return create === A.H.TRUE ? A.H.push(x) : ref; 361 }, 362 "has_GetPrintJobs": (): heap.Ref<boolean> => { 363 if (WEBEXT?.printingMetrics && "getPrintJobs" in WEBEXT?.printingMetrics) { 364 return A.H.TRUE; 365 } 366 return A.H.FALSE; 367 }, 368 "func_GetPrintJobs": (fn: Pointer): void => { 369 A.store.Ref(fn, WEBEXT.printingMetrics.getPrintJobs); 370 }, 371 "call_GetPrintJobs": (retPtr: Pointer): void => { 372 const _ret = WEBEXT.printingMetrics.getPrintJobs(); 373 A.store.Ref(retPtr, _ret); 374 }, 375 "try_GetPrintJobs": (retPtr: Pointer, errPtr: Pointer): heap.Ref<boolean> => { 376 try { 377 const _ret = WEBEXT.printingMetrics.getPrintJobs(); 378 A.store.Ref(retPtr, _ret); 379 return A.H.TRUE; 380 } catch (err: any) { 381 A.store.Ref(errPtr, err); 382 return A.H.FALSE; 383 } 384 }, 385 "has_OnPrintJobFinished": (): heap.Ref<boolean> => { 386 if (WEBEXT?.printingMetrics?.onPrintJobFinished && "addListener" in WEBEXT?.printingMetrics?.onPrintJobFinished) { 387 return A.H.TRUE; 388 } 389 return A.H.FALSE; 390 }, 391 "func_OnPrintJobFinished": (fn: Pointer): void => { 392 A.store.Ref(fn, WEBEXT.printingMetrics.onPrintJobFinished.addListener); 393 }, 394 "call_OnPrintJobFinished": (retPtr: Pointer, callback: heap.Ref<object>): void => { 395 const _ret = WEBEXT.printingMetrics.onPrintJobFinished.addListener(A.H.get<object>(callback)); 396 }, 397 "try_OnPrintJobFinished": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => { 398 try { 399 const _ret = WEBEXT.printingMetrics.onPrintJobFinished.addListener(A.H.get<object>(callback)); 400 return A.H.TRUE; 401 } catch (err: any) { 402 A.store.Ref(errPtr, err); 403 return A.H.FALSE; 404 } 405 }, 406 "has_OffPrintJobFinished": (): heap.Ref<boolean> => { 407 if ( 408 WEBEXT?.printingMetrics?.onPrintJobFinished && 409 "removeListener" in WEBEXT?.printingMetrics?.onPrintJobFinished 410 ) { 411 return A.H.TRUE; 412 } 413 return A.H.FALSE; 414 }, 415 "func_OffPrintJobFinished": (fn: Pointer): void => { 416 A.store.Ref(fn, WEBEXT.printingMetrics.onPrintJobFinished.removeListener); 417 }, 418 "call_OffPrintJobFinished": (retPtr: Pointer, callback: heap.Ref<object>): void => { 419 const _ret = WEBEXT.printingMetrics.onPrintJobFinished.removeListener(A.H.get<object>(callback)); 420 }, 421 "try_OffPrintJobFinished": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => { 422 try { 423 const _ret = WEBEXT.printingMetrics.onPrintJobFinished.removeListener(A.H.get<object>(callback)); 424 return A.H.TRUE; 425 } catch (err: any) { 426 A.store.Ref(errPtr, err); 427 return A.H.FALSE; 428 } 429 }, 430 "has_HasOnPrintJobFinished": (): heap.Ref<boolean> => { 431 if (WEBEXT?.printingMetrics?.onPrintJobFinished && "hasListener" in WEBEXT?.printingMetrics?.onPrintJobFinished) { 432 return A.H.TRUE; 433 } 434 return A.H.FALSE; 435 }, 436 "func_HasOnPrintJobFinished": (fn: Pointer): void => { 437 A.store.Ref(fn, WEBEXT.printingMetrics.onPrintJobFinished.hasListener); 438 }, 439 "call_HasOnPrintJobFinished": (retPtr: Pointer, callback: heap.Ref<object>): void => { 440 const _ret = WEBEXT.printingMetrics.onPrintJobFinished.hasListener(A.H.get<object>(callback)); 441 A.store.Bool(retPtr, _ret); 442 }, 443 "try_HasOnPrintJobFinished": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => { 444 try { 445 const _ret = WEBEXT.printingMetrics.onPrintJobFinished.hasListener(A.H.get<object>(callback)); 446 A.store.Bool(retPtr, _ret); 447 return A.H.TRUE; 448 } catch (err: any) { 449 A.store.Ref(errPtr, err); 450 return A.H.FALSE; 451 } 452 }, 453 }; 454 });