github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/app/apis_js_wasm.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright 2023 The Prime Citizens
     3  
     4  package app
     5  
     6  import (
     7  	"github.com/primecitizens/pcz/std/ffi/js"
     8  	"github.com/primecitizens/pcz/std/plat/js/webext/app/bindings"
     9  )
    10  
    11  type DOMWindow struct {
    12  	FFI_USE bool
    13  }
    14  
    15  // FromRef calls UpdateFrom and returns a DOMWindow with all fields set.
    16  func (p DOMWindow) FromRef(ref js.Ref) DOMWindow {
    17  	p.UpdateFrom(ref)
    18  	return p
    19  }
    20  
    21  // New creates a new DOMWindow in the application heap.
    22  func (p DOMWindow) New() js.Ref {
    23  	return bindings.DOMWindowJSLoad(
    24  		js.Pointer(&p), js.True, 0,
    25  	)
    26  }
    27  
    28  // UpdateFrom copies value of all fields of the heap object to p.
    29  func (p *DOMWindow) UpdateFrom(ref js.Ref) {
    30  	bindings.DOMWindowJSStore(
    31  		js.Pointer(p), ref,
    32  	)
    33  }
    34  
    35  // Update writes all fields of the p to the heap object referenced by ref.
    36  func (p *DOMWindow) Update(ref js.Ref) {
    37  	bindings.DOMWindowJSLoad(
    38  		js.Pointer(p), js.False, ref,
    39  	)
    40  }
    41  
    42  // FreeMembers frees fields with heap reference, if recursive is true
    43  // free all heap references reachable from p.
    44  func (p *DOMWindow) FreeMembers(recursive bool) {
    45  }
    46  
    47  type Details struct {
    48  	FFI_USE bool
    49  }
    50  
    51  // FromRef calls UpdateFrom and returns a Details with all fields set.
    52  func (p Details) FromRef(ref js.Ref) Details {
    53  	p.UpdateFrom(ref)
    54  	return p
    55  }
    56  
    57  // New creates a new Details in the application heap.
    58  func (p Details) New() js.Ref {
    59  	return bindings.DetailsJSLoad(
    60  		js.Pointer(&p), js.True, 0,
    61  	)
    62  }
    63  
    64  // UpdateFrom copies value of all fields of the heap object to p.
    65  func (p *Details) UpdateFrom(ref js.Ref) {
    66  	bindings.DetailsJSStore(
    67  		js.Pointer(p), ref,
    68  	)
    69  }
    70  
    71  // Update writes all fields of the p to the heap object referenced by ref.
    72  func (p *Details) Update(ref js.Ref) {
    73  	bindings.DetailsJSLoad(
    74  		js.Pointer(p), js.False, ref,
    75  	)
    76  }
    77  
    78  // FreeMembers frees fields with heap reference, if recursive is true
    79  // free all heap references reachable from p.
    80  func (p *Details) FreeMembers(recursive bool) {
    81  }
    82  
    83  type InstallStateType uint32
    84  
    85  const (
    86  	_ InstallStateType = iota
    87  
    88  	InstallStateType_NOT_INSTALLED
    89  	InstallStateType_INSTALLED
    90  	InstallStateType_DISABLED
    91  )
    92  
    93  func (InstallStateType) FromRef(str js.Ref) InstallStateType {
    94  	return InstallStateType(bindings.ConstOfInstallStateType(str))
    95  }
    96  
    97  func (x InstallStateType) String() (string, bool) {
    98  	switch x {
    99  	case InstallStateType_NOT_INSTALLED:
   100  		return "not_installed", true
   101  	case InstallStateType_INSTALLED:
   102  		return "installed", true
   103  	case InstallStateType_DISABLED:
   104  		return "disabled", true
   105  	default:
   106  		return "", false
   107  	}
   108  }
   109  
   110  type RunningStateType uint32
   111  
   112  const (
   113  	_ RunningStateType = iota
   114  
   115  	RunningStateType_RUNNING
   116  	RunningStateType_CANNOT_RUN
   117  	RunningStateType_READY_TO_RUN
   118  )
   119  
   120  func (RunningStateType) FromRef(str js.Ref) RunningStateType {
   121  	return RunningStateType(bindings.ConstOfRunningStateType(str))
   122  }
   123  
   124  func (x RunningStateType) String() (string, bool) {
   125  	switch x {
   126  	case RunningStateType_RUNNING:
   127  		return "running", true
   128  	case RunningStateType_CANNOT_RUN:
   129  		return "cannot_run", true
   130  	case RunningStateType_READY_TO_RUN:
   131  		return "ready_to_run", true
   132  	default:
   133  		return "", false
   134  	}
   135  }
   136  
   137  // HasFuncGetDetails returns true if the function "WEBEXT.app.getDetails" exists.
   138  func HasFuncGetDetails() bool {
   139  	return js.True == bindings.HasFuncGetDetails()
   140  }
   141  
   142  // FuncGetDetails returns the function "WEBEXT.app.getDetails".
   143  func FuncGetDetails() (fn js.Func[func() Details]) {
   144  	bindings.FuncGetDetails(
   145  		js.Pointer(&fn),
   146  	)
   147  	return
   148  }
   149  
   150  // GetDetails calls the function "WEBEXT.app.getDetails" directly.
   151  func GetDetails() (ret Details) {
   152  	bindings.CallGetDetails(
   153  		js.Pointer(&ret),
   154  	)
   155  
   156  	return
   157  }
   158  
   159  // TryGetDetails calls the function "WEBEXT.app.getDetails"
   160  // in a try/catch block and returns (_, err, ok = false) when it went through
   161  // the catch clause.
   162  func TryGetDetails() (ret Details, exception js.Any, ok bool) {
   163  	ok = js.True == bindings.TryGetDetails(
   164  		js.Pointer(&ret), js.Pointer(&exception),
   165  	)
   166  
   167  	return
   168  }
   169  
   170  // HasFuncGetIsInstalled returns true if the function "WEBEXT.app.getIsInstalled" exists.
   171  func HasFuncGetIsInstalled() bool {
   172  	return js.True == bindings.HasFuncGetIsInstalled()
   173  }
   174  
   175  // FuncGetIsInstalled returns the function "WEBEXT.app.getIsInstalled".
   176  func FuncGetIsInstalled() (fn js.Func[func() bool]) {
   177  	bindings.FuncGetIsInstalled(
   178  		js.Pointer(&fn),
   179  	)
   180  	return
   181  }
   182  
   183  // GetIsInstalled calls the function "WEBEXT.app.getIsInstalled" directly.
   184  func GetIsInstalled() (ret bool) {
   185  	bindings.CallGetIsInstalled(
   186  		js.Pointer(&ret),
   187  	)
   188  
   189  	return
   190  }
   191  
   192  // TryGetIsInstalled calls the function "WEBEXT.app.getIsInstalled"
   193  // in a try/catch block and returns (_, err, ok = false) when it went through
   194  // the catch clause.
   195  func TryGetIsInstalled() (ret bool, exception js.Any, ok bool) {
   196  	ok = js.True == bindings.TryGetIsInstalled(
   197  		js.Pointer(&ret), js.Pointer(&exception),
   198  	)
   199  
   200  	return
   201  }
   202  
   203  // HasFuncInstallState returns true if the function "WEBEXT.app.installState" exists.
   204  func HasFuncInstallState() bool {
   205  	return js.True == bindings.HasFuncInstallState()
   206  }
   207  
   208  // FuncInstallState returns the function "WEBEXT.app.installState".
   209  func FuncInstallState() (fn js.Func[func() js.Promise[InstallStateType]]) {
   210  	bindings.FuncInstallState(
   211  		js.Pointer(&fn),
   212  	)
   213  	return
   214  }
   215  
   216  // InstallState calls the function "WEBEXT.app.installState" directly.
   217  func InstallState() (ret js.Promise[InstallStateType]) {
   218  	bindings.CallInstallState(
   219  		js.Pointer(&ret),
   220  	)
   221  
   222  	return
   223  }
   224  
   225  // TryInstallState calls the function "WEBEXT.app.installState"
   226  // in a try/catch block and returns (_, err, ok = false) when it went through
   227  // the catch clause.
   228  func TryInstallState() (ret js.Promise[InstallStateType], exception js.Any, ok bool) {
   229  	ok = js.True == bindings.TryInstallState(
   230  		js.Pointer(&ret), js.Pointer(&exception),
   231  	)
   232  
   233  	return
   234  }
   235  
   236  // HasFuncRunningState returns true if the function "WEBEXT.app.runningState" exists.
   237  func HasFuncRunningState() bool {
   238  	return js.True == bindings.HasFuncRunningState()
   239  }
   240  
   241  // FuncRunningState returns the function "WEBEXT.app.runningState".
   242  func FuncRunningState() (fn js.Func[func() RunningStateType]) {
   243  	bindings.FuncRunningState(
   244  		js.Pointer(&fn),
   245  	)
   246  	return
   247  }
   248  
   249  // RunningState calls the function "WEBEXT.app.runningState" directly.
   250  func RunningState() (ret RunningStateType) {
   251  	bindings.CallRunningState(
   252  		js.Pointer(&ret),
   253  	)
   254  
   255  	return
   256  }
   257  
   258  // TryRunningState calls the function "WEBEXT.app.runningState"
   259  // in a try/catch block and returns (_, err, ok = false) when it went through
   260  // the catch clause.
   261  func TryRunningState() (ret RunningStateType, exception js.Any, ok bool) {
   262  	ok = js.True == bindings.TryRunningState(
   263  		js.Pointer(&ret), js.Pointer(&exception),
   264  	)
   265  
   266  	return
   267  }