github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/printingmetrics/apis_js_wasm.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright 2023 The Prime Citizens 3 4 package printingmetrics 5 6 import ( 7 "github.com/primecitizens/pcz/std/core/abi" 8 "github.com/primecitizens/pcz/std/core/mark" 9 "github.com/primecitizens/pcz/std/ffi/js" 10 "github.com/primecitizens/pcz/std/plat/js/webext/printing" 11 "github.com/primecitizens/pcz/std/plat/js/webext/printingmetrics/bindings" 12 ) 13 14 type ColorMode uint32 15 16 const ( 17 _ ColorMode = iota 18 19 ColorMode_BLACK_AND_WHITE 20 ColorMode_COLOR 21 ) 22 23 func (ColorMode) FromRef(str js.Ref) ColorMode { 24 return ColorMode(bindings.ConstOfColorMode(str)) 25 } 26 27 func (x ColorMode) String() (string, bool) { 28 switch x { 29 case ColorMode_BLACK_AND_WHITE: 30 return "BLACK_AND_WHITE", true 31 case ColorMode_COLOR: 32 return "COLOR", true 33 default: 34 return "", false 35 } 36 } 37 38 type DuplexMode uint32 39 40 const ( 41 _ DuplexMode = iota 42 43 DuplexMode_ONE_SIDED 44 DuplexMode_TWO_SIDED_LONG_EDGE 45 DuplexMode_TWO_SIDED_SHORT_EDGE 46 ) 47 48 func (DuplexMode) FromRef(str js.Ref) DuplexMode { 49 return DuplexMode(bindings.ConstOfDuplexMode(str)) 50 } 51 52 func (x DuplexMode) String() (string, bool) { 53 switch x { 54 case DuplexMode_ONE_SIDED: 55 return "ONE_SIDED", true 56 case DuplexMode_TWO_SIDED_LONG_EDGE: 57 return "TWO_SIDED_LONG_EDGE", true 58 case DuplexMode_TWO_SIDED_SHORT_EDGE: 59 return "TWO_SIDED_SHORT_EDGE", true 60 default: 61 return "", false 62 } 63 } 64 65 type GetPrintJobsCallbackFunc func(this js.Ref, jobs js.Array[PrintJobInfo]) js.Ref 66 67 func (fn GetPrintJobsCallbackFunc) Register() js.Func[func(jobs js.Array[PrintJobInfo])] { 68 return js.RegisterCallback[func(jobs js.Array[PrintJobInfo])]( 69 fn, abi.FuncPCABIInternal(fn), 70 ) 71 } 72 73 func (fn GetPrintJobsCallbackFunc) DispatchCallback( 74 targetPC uintptr, ctx *js.CallbackContext, 75 ) { 76 args := ctx.Args() 77 if len(args) != 1+1 /* js this */ || 78 targetPC != uintptr(abi.FuncPCABIInternal(fn)) { 79 js.ThrowInvalidCallbackInvocation() 80 } 81 82 if ctx.Return(fn( 83 args[0], 84 85 js.Array[PrintJobInfo]{}.FromRef(args[0+1]), 86 )) { 87 return 88 } 89 90 js.ThrowCallbackValueNotReturned() 91 } 92 93 type GetPrintJobsCallback[T any] struct { 94 Fn func(arg T, this js.Ref, jobs js.Array[PrintJobInfo]) js.Ref 95 Arg T 96 } 97 98 func (cb *GetPrintJobsCallback[T]) Register() js.Func[func(jobs js.Array[PrintJobInfo])] { 99 return js.RegisterCallback[func(jobs js.Array[PrintJobInfo])]( 100 cb, abi.FuncPCABIInternal(cb.Fn), 101 ) 102 } 103 104 func (cb *GetPrintJobsCallback[T]) DispatchCallback( 105 targetPC uintptr, ctx *js.CallbackContext, 106 ) { 107 args := ctx.Args() 108 if len(args) != 1+1 /* js this */ || 109 targetPC != uintptr(abi.FuncPCABIInternal(cb.Fn)) { 110 js.ThrowInvalidCallbackInvocation() 111 } 112 113 if ctx.Return(cb.Fn( 114 cb.Arg, 115 args[0], 116 117 js.Array[PrintJobInfo]{}.FromRef(args[0+1]), 118 )) { 119 return 120 } 121 122 js.ThrowCallbackValueNotReturned() 123 } 124 125 type PrintJobSource uint32 126 127 const ( 128 _ PrintJobSource = iota 129 130 PrintJobSource_PRINT_PREVIEW 131 PrintJobSource_ANDROID_APP 132 PrintJobSource_EXTENSION 133 ) 134 135 func (PrintJobSource) FromRef(str js.Ref) PrintJobSource { 136 return PrintJobSource(bindings.ConstOfPrintJobSource(str)) 137 } 138 139 func (x PrintJobSource) String() (string, bool) { 140 switch x { 141 case PrintJobSource_PRINT_PREVIEW: 142 return "PRINT_PREVIEW", true 143 case PrintJobSource_ANDROID_APP: 144 return "ANDROID_APP", true 145 case PrintJobSource_EXTENSION: 146 return "EXTENSION", true 147 default: 148 return "", false 149 } 150 } 151 152 type PrintJobStatus uint32 153 154 const ( 155 _ PrintJobStatus = iota 156 157 PrintJobStatus_FAILED 158 PrintJobStatus_CANCELED 159 PrintJobStatus_PRINTED 160 ) 161 162 func (PrintJobStatus) FromRef(str js.Ref) PrintJobStatus { 163 return PrintJobStatus(bindings.ConstOfPrintJobStatus(str)) 164 } 165 166 func (x PrintJobStatus) String() (string, bool) { 167 switch x { 168 case PrintJobStatus_FAILED: 169 return "FAILED", true 170 case PrintJobStatus_CANCELED: 171 return "CANCELED", true 172 case PrintJobStatus_PRINTED: 173 return "PRINTED", true 174 default: 175 return "", false 176 } 177 } 178 179 type PrinterSource uint32 180 181 const ( 182 _ PrinterSource = iota 183 184 PrinterSource_USER 185 PrinterSource_POLICY 186 ) 187 188 func (PrinterSource) FromRef(str js.Ref) PrinterSource { 189 return PrinterSource(bindings.ConstOfPrinterSource(str)) 190 } 191 192 func (x PrinterSource) String() (string, bool) { 193 switch x { 194 case PrinterSource_USER: 195 return "USER", true 196 case PrinterSource_POLICY: 197 return "POLICY", true 198 default: 199 return "", false 200 } 201 } 202 203 type Printer struct { 204 // Name is "Printer.name" 205 // 206 // Optional 207 Name js.String 208 // Uri is "Printer.uri" 209 // 210 // Optional 211 Uri js.String 212 // Source is "Printer.source" 213 // 214 // Optional 215 Source PrinterSource 216 217 FFI_USE bool 218 } 219 220 // FromRef calls UpdateFrom and returns a Printer with all fields set. 221 func (p Printer) FromRef(ref js.Ref) Printer { 222 p.UpdateFrom(ref) 223 return p 224 } 225 226 // New creates a new Printer in the application heap. 227 func (p Printer) New() js.Ref { 228 return bindings.PrinterJSLoad( 229 js.Pointer(&p), js.True, 0, 230 ) 231 } 232 233 // UpdateFrom copies value of all fields of the heap object to p. 234 func (p *Printer) UpdateFrom(ref js.Ref) { 235 bindings.PrinterJSStore( 236 js.Pointer(p), ref, 237 ) 238 } 239 240 // Update writes all fields of the p to the heap object referenced by ref. 241 func (p *Printer) Update(ref js.Ref) { 242 bindings.PrinterJSLoad( 243 js.Pointer(p), js.False, ref, 244 ) 245 } 246 247 // FreeMembers frees fields with heap reference, if recursive is true 248 // free all heap references reachable from p. 249 func (p *Printer) FreeMembers(recursive bool) { 250 js.Free( 251 p.Name.Ref(), 252 p.Uri.Ref(), 253 ) 254 p.Name = p.Name.FromRef(js.Undefined) 255 p.Uri = p.Uri.FromRef(js.Undefined) 256 } 257 258 type MediaSize struct { 259 // Width is "MediaSize.width" 260 // 261 // Optional 262 // 263 // NOTE: FFI_USE_Width MUST be set to true to make this field effective. 264 Width int32 265 // Height is "MediaSize.height" 266 // 267 // Optional 268 // 269 // NOTE: FFI_USE_Height MUST be set to true to make this field effective. 270 Height int32 271 // VendorId is "MediaSize.vendorId" 272 // 273 // Optional 274 VendorId js.String 275 276 FFI_USE_Width bool // for Width. 277 FFI_USE_Height bool // for Height. 278 279 FFI_USE bool 280 } 281 282 // FromRef calls UpdateFrom and returns a MediaSize with all fields set. 283 func (p MediaSize) FromRef(ref js.Ref) MediaSize { 284 p.UpdateFrom(ref) 285 return p 286 } 287 288 // New creates a new MediaSize in the application heap. 289 func (p MediaSize) New() js.Ref { 290 return bindings.MediaSizeJSLoad( 291 js.Pointer(&p), js.True, 0, 292 ) 293 } 294 295 // UpdateFrom copies value of all fields of the heap object to p. 296 func (p *MediaSize) UpdateFrom(ref js.Ref) { 297 bindings.MediaSizeJSStore( 298 js.Pointer(p), ref, 299 ) 300 } 301 302 // Update writes all fields of the p to the heap object referenced by ref. 303 func (p *MediaSize) Update(ref js.Ref) { 304 bindings.MediaSizeJSLoad( 305 js.Pointer(p), js.False, ref, 306 ) 307 } 308 309 // FreeMembers frees fields with heap reference, if recursive is true 310 // free all heap references reachable from p. 311 func (p *MediaSize) FreeMembers(recursive bool) { 312 js.Free( 313 p.VendorId.Ref(), 314 ) 315 p.VendorId = p.VendorId.FromRef(js.Undefined) 316 } 317 318 type PrintSettings struct { 319 // Color is "PrintSettings.color" 320 // 321 // Optional 322 Color ColorMode 323 // Duplex is "PrintSettings.duplex" 324 // 325 // Optional 326 Duplex DuplexMode 327 // MediaSize is "PrintSettings.mediaSize" 328 // 329 // Optional 330 // 331 // NOTE: MediaSize.FFI_USE MUST be set to true to get MediaSize used. 332 MediaSize MediaSize 333 // Copies is "PrintSettings.copies" 334 // 335 // Optional 336 // 337 // NOTE: FFI_USE_Copies MUST be set to true to make this field effective. 338 Copies int32 339 340 FFI_USE_Copies bool // for Copies. 341 342 FFI_USE bool 343 } 344 345 // FromRef calls UpdateFrom and returns a PrintSettings with all fields set. 346 func (p PrintSettings) FromRef(ref js.Ref) PrintSettings { 347 p.UpdateFrom(ref) 348 return p 349 } 350 351 // New creates a new PrintSettings in the application heap. 352 func (p PrintSettings) New() js.Ref { 353 return bindings.PrintSettingsJSLoad( 354 js.Pointer(&p), js.True, 0, 355 ) 356 } 357 358 // UpdateFrom copies value of all fields of the heap object to p. 359 func (p *PrintSettings) UpdateFrom(ref js.Ref) { 360 bindings.PrintSettingsJSStore( 361 js.Pointer(p), ref, 362 ) 363 } 364 365 // Update writes all fields of the p to the heap object referenced by ref. 366 func (p *PrintSettings) Update(ref js.Ref) { 367 bindings.PrintSettingsJSLoad( 368 js.Pointer(p), js.False, ref, 369 ) 370 } 371 372 // FreeMembers frees fields with heap reference, if recursive is true 373 // free all heap references reachable from p. 374 func (p *PrintSettings) FreeMembers(recursive bool) { 375 if recursive { 376 p.MediaSize.FreeMembers(true) 377 } 378 } 379 380 type PrintJobInfo struct { 381 // Id is "PrintJobInfo.id" 382 // 383 // Optional 384 Id js.String 385 // Title is "PrintJobInfo.title" 386 // 387 // Optional 388 Title js.String 389 // Source is "PrintJobInfo.source" 390 // 391 // Optional 392 Source PrintJobSource 393 // SourceId is "PrintJobInfo.sourceId" 394 // 395 // Optional 396 SourceId js.String 397 // Status is "PrintJobInfo.status" 398 // 399 // Optional 400 Status PrintJobStatus 401 // CreationTime is "PrintJobInfo.creationTime" 402 // 403 // Optional 404 // 405 // NOTE: FFI_USE_CreationTime MUST be set to true to make this field effective. 406 CreationTime float64 407 // CompletionTime is "PrintJobInfo.completionTime" 408 // 409 // Optional 410 // 411 // NOTE: FFI_USE_CompletionTime MUST be set to true to make this field effective. 412 CompletionTime float64 413 // Printer is "PrintJobInfo.printer" 414 // 415 // Optional 416 // 417 // NOTE: Printer.FFI_USE MUST be set to true to get Printer used. 418 Printer Printer 419 // Settings is "PrintJobInfo.settings" 420 // 421 // Optional 422 // 423 // NOTE: Settings.FFI_USE MUST be set to true to get Settings used. 424 Settings PrintSettings 425 // NumberOfPages is "PrintJobInfo.numberOfPages" 426 // 427 // Optional 428 // 429 // NOTE: FFI_USE_NumberOfPages MUST be set to true to make this field effective. 430 NumberOfPages int32 431 // PrinterStatus is "PrintJobInfo.printer_status" 432 // 433 // Optional 434 PrinterStatus printing.PrinterStatus 435 436 FFI_USE_CreationTime bool // for CreationTime. 437 FFI_USE_CompletionTime bool // for CompletionTime. 438 FFI_USE_NumberOfPages bool // for NumberOfPages. 439 440 FFI_USE bool 441 } 442 443 // FromRef calls UpdateFrom and returns a PrintJobInfo with all fields set. 444 func (p PrintJobInfo) FromRef(ref js.Ref) PrintJobInfo { 445 p.UpdateFrom(ref) 446 return p 447 } 448 449 // New creates a new PrintJobInfo in the application heap. 450 func (p PrintJobInfo) New() js.Ref { 451 return bindings.PrintJobInfoJSLoad( 452 js.Pointer(&p), js.True, 0, 453 ) 454 } 455 456 // UpdateFrom copies value of all fields of the heap object to p. 457 func (p *PrintJobInfo) UpdateFrom(ref js.Ref) { 458 bindings.PrintJobInfoJSStore( 459 js.Pointer(p), ref, 460 ) 461 } 462 463 // Update writes all fields of the p to the heap object referenced by ref. 464 func (p *PrintJobInfo) Update(ref js.Ref) { 465 bindings.PrintJobInfoJSLoad( 466 js.Pointer(p), js.False, ref, 467 ) 468 } 469 470 // FreeMembers frees fields with heap reference, if recursive is true 471 // free all heap references reachable from p. 472 func (p *PrintJobInfo) FreeMembers(recursive bool) { 473 js.Free( 474 p.Id.Ref(), 475 p.Title.Ref(), 476 p.SourceId.Ref(), 477 ) 478 p.Id = p.Id.FromRef(js.Undefined) 479 p.Title = p.Title.FromRef(js.Undefined) 480 p.SourceId = p.SourceId.FromRef(js.Undefined) 481 if recursive { 482 p.Printer.FreeMembers(true) 483 p.Settings.FreeMembers(true) 484 } 485 } 486 487 // HasFuncGetPrintJobs returns true if the function "WEBEXT.printingMetrics.getPrintJobs" exists. 488 func HasFuncGetPrintJobs() bool { 489 return js.True == bindings.HasFuncGetPrintJobs() 490 } 491 492 // FuncGetPrintJobs returns the function "WEBEXT.printingMetrics.getPrintJobs". 493 func FuncGetPrintJobs() (fn js.Func[func() js.Promise[js.Array[PrintJobInfo]]]) { 494 bindings.FuncGetPrintJobs( 495 js.Pointer(&fn), 496 ) 497 return 498 } 499 500 // GetPrintJobs calls the function "WEBEXT.printingMetrics.getPrintJobs" directly. 501 func GetPrintJobs() (ret js.Promise[js.Array[PrintJobInfo]]) { 502 bindings.CallGetPrintJobs( 503 js.Pointer(&ret), 504 ) 505 506 return 507 } 508 509 // TryGetPrintJobs calls the function "WEBEXT.printingMetrics.getPrintJobs" 510 // in a try/catch block and returns (_, err, ok = false) when it went through 511 // the catch clause. 512 func TryGetPrintJobs() (ret js.Promise[js.Array[PrintJobInfo]], exception js.Any, ok bool) { 513 ok = js.True == bindings.TryGetPrintJobs( 514 js.Pointer(&ret), js.Pointer(&exception), 515 ) 516 517 return 518 } 519 520 type OnPrintJobFinishedEventCallbackFunc func(this js.Ref, jobInfo *PrintJobInfo) js.Ref 521 522 func (fn OnPrintJobFinishedEventCallbackFunc) Register() js.Func[func(jobInfo *PrintJobInfo)] { 523 return js.RegisterCallback[func(jobInfo *PrintJobInfo)]( 524 fn, abi.FuncPCABIInternal(fn), 525 ) 526 } 527 528 func (fn OnPrintJobFinishedEventCallbackFunc) DispatchCallback( 529 targetPC uintptr, ctx *js.CallbackContext, 530 ) { 531 args := ctx.Args() 532 if len(args) != 1+1 /* js this */ || 533 targetPC != uintptr(abi.FuncPCABIInternal(fn)) { 534 js.ThrowInvalidCallbackInvocation() 535 } 536 var arg0 PrintJobInfo 537 arg0.UpdateFrom(args[0+1]) 538 defer arg0.FreeMembers(true) 539 540 if ctx.Return(fn( 541 args[0], 542 543 mark.NoEscape(&arg0), 544 )) { 545 return 546 } 547 548 js.ThrowCallbackValueNotReturned() 549 } 550 551 type OnPrintJobFinishedEventCallback[T any] struct { 552 Fn func(arg T, this js.Ref, jobInfo *PrintJobInfo) js.Ref 553 Arg T 554 } 555 556 func (cb *OnPrintJobFinishedEventCallback[T]) Register() js.Func[func(jobInfo *PrintJobInfo)] { 557 return js.RegisterCallback[func(jobInfo *PrintJobInfo)]( 558 cb, abi.FuncPCABIInternal(cb.Fn), 559 ) 560 } 561 562 func (cb *OnPrintJobFinishedEventCallback[T]) DispatchCallback( 563 targetPC uintptr, ctx *js.CallbackContext, 564 ) { 565 args := ctx.Args() 566 if len(args) != 1+1 /* js this */ || 567 targetPC != uintptr(abi.FuncPCABIInternal(cb.Fn)) { 568 js.ThrowInvalidCallbackInvocation() 569 } 570 var arg0 PrintJobInfo 571 arg0.UpdateFrom(args[0+1]) 572 defer arg0.FreeMembers(true) 573 574 if ctx.Return(cb.Fn( 575 cb.Arg, 576 args[0], 577 578 mark.NoEscape(&arg0), 579 )) { 580 return 581 } 582 583 js.ThrowCallbackValueNotReturned() 584 } 585 586 // HasFuncOnPrintJobFinished returns true if the function "WEBEXT.printingMetrics.onPrintJobFinished.addListener" exists. 587 func HasFuncOnPrintJobFinished() bool { 588 return js.True == bindings.HasFuncOnPrintJobFinished() 589 } 590 591 // FuncOnPrintJobFinished returns the function "WEBEXT.printingMetrics.onPrintJobFinished.addListener". 592 func FuncOnPrintJobFinished() (fn js.Func[func(callback js.Func[func(jobInfo *PrintJobInfo)])]) { 593 bindings.FuncOnPrintJobFinished( 594 js.Pointer(&fn), 595 ) 596 return 597 } 598 599 // OnPrintJobFinished calls the function "WEBEXT.printingMetrics.onPrintJobFinished.addListener" directly. 600 func OnPrintJobFinished(callback js.Func[func(jobInfo *PrintJobInfo)]) (ret js.Void) { 601 bindings.CallOnPrintJobFinished( 602 js.Pointer(&ret), 603 callback.Ref(), 604 ) 605 606 return 607 } 608 609 // TryOnPrintJobFinished calls the function "WEBEXT.printingMetrics.onPrintJobFinished.addListener" 610 // in a try/catch block and returns (_, err, ok = false) when it went through 611 // the catch clause. 612 func TryOnPrintJobFinished(callback js.Func[func(jobInfo *PrintJobInfo)]) (ret js.Void, exception js.Any, ok bool) { 613 ok = js.True == bindings.TryOnPrintJobFinished( 614 js.Pointer(&ret), js.Pointer(&exception), 615 callback.Ref(), 616 ) 617 618 return 619 } 620 621 // HasFuncOffPrintJobFinished returns true if the function "WEBEXT.printingMetrics.onPrintJobFinished.removeListener" exists. 622 func HasFuncOffPrintJobFinished() bool { 623 return js.True == bindings.HasFuncOffPrintJobFinished() 624 } 625 626 // FuncOffPrintJobFinished returns the function "WEBEXT.printingMetrics.onPrintJobFinished.removeListener". 627 func FuncOffPrintJobFinished() (fn js.Func[func(callback js.Func[func(jobInfo *PrintJobInfo)])]) { 628 bindings.FuncOffPrintJobFinished( 629 js.Pointer(&fn), 630 ) 631 return 632 } 633 634 // OffPrintJobFinished calls the function "WEBEXT.printingMetrics.onPrintJobFinished.removeListener" directly. 635 func OffPrintJobFinished(callback js.Func[func(jobInfo *PrintJobInfo)]) (ret js.Void) { 636 bindings.CallOffPrintJobFinished( 637 js.Pointer(&ret), 638 callback.Ref(), 639 ) 640 641 return 642 } 643 644 // TryOffPrintJobFinished calls the function "WEBEXT.printingMetrics.onPrintJobFinished.removeListener" 645 // in a try/catch block and returns (_, err, ok = false) when it went through 646 // the catch clause. 647 func TryOffPrintJobFinished(callback js.Func[func(jobInfo *PrintJobInfo)]) (ret js.Void, exception js.Any, ok bool) { 648 ok = js.True == bindings.TryOffPrintJobFinished( 649 js.Pointer(&ret), js.Pointer(&exception), 650 callback.Ref(), 651 ) 652 653 return 654 } 655 656 // HasFuncHasOnPrintJobFinished returns true if the function "WEBEXT.printingMetrics.onPrintJobFinished.hasListener" exists. 657 func HasFuncHasOnPrintJobFinished() bool { 658 return js.True == bindings.HasFuncHasOnPrintJobFinished() 659 } 660 661 // FuncHasOnPrintJobFinished returns the function "WEBEXT.printingMetrics.onPrintJobFinished.hasListener". 662 func FuncHasOnPrintJobFinished() (fn js.Func[func(callback js.Func[func(jobInfo *PrintJobInfo)]) bool]) { 663 bindings.FuncHasOnPrintJobFinished( 664 js.Pointer(&fn), 665 ) 666 return 667 } 668 669 // HasOnPrintJobFinished calls the function "WEBEXT.printingMetrics.onPrintJobFinished.hasListener" directly. 670 func HasOnPrintJobFinished(callback js.Func[func(jobInfo *PrintJobInfo)]) (ret bool) { 671 bindings.CallHasOnPrintJobFinished( 672 js.Pointer(&ret), 673 callback.Ref(), 674 ) 675 676 return 677 } 678 679 // TryHasOnPrintJobFinished calls the function "WEBEXT.printingMetrics.onPrintJobFinished.hasListener" 680 // in a try/catch block and returns (_, err, ok = false) when it went through 681 // the catch clause. 682 func TryHasOnPrintJobFinished(callback js.Func[func(jobInfo *PrintJobInfo)]) (ret bool, exception js.Any, ok bool) { 683 ok = js.True == bindings.TryHasOnPrintJobFinished( 684 js.Pointer(&ret), js.Pointer(&exception), 685 callback.Ref(), 686 ) 687 688 return 689 }