github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/systemindicator/apis_js_wasm.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright 2023 The Prime Citizens 3 4 package systemindicator 5 6 import ( 7 "github.com/primecitizens/pcz/std/core/abi" 8 "github.com/primecitizens/pcz/std/ffi/js" 9 "github.com/primecitizens/pcz/std/plat/js/webext/systemindicator/bindings" 10 ) 11 12 type DoneCallbackFunc func(this js.Ref) js.Ref 13 14 func (fn DoneCallbackFunc) Register() js.Func[func()] { 15 return js.RegisterCallback[func()]( 16 fn, abi.FuncPCABIInternal(fn), 17 ) 18 } 19 20 func (fn DoneCallbackFunc) DispatchCallback( 21 targetPC uintptr, ctx *js.CallbackContext, 22 ) { 23 args := ctx.Args() 24 if len(args) != 0+1 /* js this */ || 25 targetPC != uintptr(abi.FuncPCABIInternal(fn)) { 26 js.ThrowInvalidCallbackInvocation() 27 } 28 29 if ctx.Return(fn( 30 args[0], 31 )) { 32 return 33 } 34 35 js.ThrowCallbackValueNotReturned() 36 } 37 38 type DoneCallback[T any] struct { 39 Fn func(arg T, this js.Ref) js.Ref 40 Arg T 41 } 42 43 func (cb *DoneCallback[T]) Register() js.Func[func()] { 44 return js.RegisterCallback[func()]( 45 cb, abi.FuncPCABIInternal(cb.Fn), 46 ) 47 } 48 49 func (cb *DoneCallback[T]) DispatchCallback( 50 targetPC uintptr, ctx *js.CallbackContext, 51 ) { 52 args := ctx.Args() 53 if len(args) != 0+1 /* js this */ || 54 targetPC != uintptr(abi.FuncPCABIInternal(cb.Fn)) { 55 js.ThrowInvalidCallbackInvocation() 56 } 57 58 if ctx.Return(cb.Fn( 59 cb.Arg, 60 args[0], 61 )) { 62 return 63 } 64 65 js.ThrowCallbackValueNotReturned() 66 } 67 68 type SetIconDetails struct { 69 // Path is "SetIconDetails.path" 70 // 71 // Optional 72 Path js.Any 73 // ImageData is "SetIconDetails.imageData" 74 // 75 // Optional 76 ImageData js.Any 77 78 FFI_USE bool 79 } 80 81 // FromRef calls UpdateFrom and returns a SetIconDetails with all fields set. 82 func (p SetIconDetails) FromRef(ref js.Ref) SetIconDetails { 83 p.UpdateFrom(ref) 84 return p 85 } 86 87 // New creates a new SetIconDetails in the application heap. 88 func (p SetIconDetails) New() js.Ref { 89 return bindings.SetIconDetailsJSLoad( 90 js.Pointer(&p), js.True, 0, 91 ) 92 } 93 94 // UpdateFrom copies value of all fields of the heap object to p. 95 func (p *SetIconDetails) UpdateFrom(ref js.Ref) { 96 bindings.SetIconDetailsJSStore( 97 js.Pointer(p), ref, 98 ) 99 } 100 101 // Update writes all fields of the p to the heap object referenced by ref. 102 func (p *SetIconDetails) Update(ref js.Ref) { 103 bindings.SetIconDetailsJSLoad( 104 js.Pointer(p), js.False, ref, 105 ) 106 } 107 108 // FreeMembers frees fields with heap reference, if recursive is true 109 // free all heap references reachable from p. 110 func (p *SetIconDetails) FreeMembers(recursive bool) { 111 js.Free( 112 p.Path.Ref(), 113 p.ImageData.Ref(), 114 ) 115 p.Path = p.Path.FromRef(js.Undefined) 116 p.ImageData = p.ImageData.FromRef(js.Undefined) 117 } 118 119 // HasFuncDisable returns true if the function "WEBEXT.systemIndicator.disable" exists. 120 func HasFuncDisable() bool { 121 return js.True == bindings.HasFuncDisable() 122 } 123 124 // FuncDisable returns the function "WEBEXT.systemIndicator.disable". 125 func FuncDisable() (fn js.Func[func()]) { 126 bindings.FuncDisable( 127 js.Pointer(&fn), 128 ) 129 return 130 } 131 132 // Disable calls the function "WEBEXT.systemIndicator.disable" directly. 133 func Disable() (ret js.Void) { 134 bindings.CallDisable( 135 js.Pointer(&ret), 136 ) 137 138 return 139 } 140 141 // TryDisable calls the function "WEBEXT.systemIndicator.disable" 142 // in a try/catch block and returns (_, err, ok = false) when it went through 143 // the catch clause. 144 func TryDisable() (ret js.Void, exception js.Any, ok bool) { 145 ok = js.True == bindings.TryDisable( 146 js.Pointer(&ret), js.Pointer(&exception), 147 ) 148 149 return 150 } 151 152 // HasFuncEnable returns true if the function "WEBEXT.systemIndicator.enable" exists. 153 func HasFuncEnable() bool { 154 return js.True == bindings.HasFuncEnable() 155 } 156 157 // FuncEnable returns the function "WEBEXT.systemIndicator.enable". 158 func FuncEnable() (fn js.Func[func()]) { 159 bindings.FuncEnable( 160 js.Pointer(&fn), 161 ) 162 return 163 } 164 165 // Enable calls the function "WEBEXT.systemIndicator.enable" directly. 166 func Enable() (ret js.Void) { 167 bindings.CallEnable( 168 js.Pointer(&ret), 169 ) 170 171 return 172 } 173 174 // TryEnable calls the function "WEBEXT.systemIndicator.enable" 175 // in a try/catch block and returns (_, err, ok = false) when it went through 176 // the catch clause. 177 func TryEnable() (ret js.Void, exception js.Any, ok bool) { 178 ok = js.True == bindings.TryEnable( 179 js.Pointer(&ret), js.Pointer(&exception), 180 ) 181 182 return 183 } 184 185 type OnClickedEventCallbackFunc func(this js.Ref) js.Ref 186 187 func (fn OnClickedEventCallbackFunc) Register() js.Func[func()] { 188 return js.RegisterCallback[func()]( 189 fn, abi.FuncPCABIInternal(fn), 190 ) 191 } 192 193 func (fn OnClickedEventCallbackFunc) DispatchCallback( 194 targetPC uintptr, ctx *js.CallbackContext, 195 ) { 196 args := ctx.Args() 197 if len(args) != 0+1 /* js this */ || 198 targetPC != uintptr(abi.FuncPCABIInternal(fn)) { 199 js.ThrowInvalidCallbackInvocation() 200 } 201 202 if ctx.Return(fn( 203 args[0], 204 )) { 205 return 206 } 207 208 js.ThrowCallbackValueNotReturned() 209 } 210 211 type OnClickedEventCallback[T any] struct { 212 Fn func(arg T, this js.Ref) js.Ref 213 Arg T 214 } 215 216 func (cb *OnClickedEventCallback[T]) Register() js.Func[func()] { 217 return js.RegisterCallback[func()]( 218 cb, abi.FuncPCABIInternal(cb.Fn), 219 ) 220 } 221 222 func (cb *OnClickedEventCallback[T]) DispatchCallback( 223 targetPC uintptr, ctx *js.CallbackContext, 224 ) { 225 args := ctx.Args() 226 if len(args) != 0+1 /* js this */ || 227 targetPC != uintptr(abi.FuncPCABIInternal(cb.Fn)) { 228 js.ThrowInvalidCallbackInvocation() 229 } 230 231 if ctx.Return(cb.Fn( 232 cb.Arg, 233 args[0], 234 )) { 235 return 236 } 237 238 js.ThrowCallbackValueNotReturned() 239 } 240 241 // HasFuncOnClicked returns true if the function "WEBEXT.systemIndicator.onClicked.addListener" exists. 242 func HasFuncOnClicked() bool { 243 return js.True == bindings.HasFuncOnClicked() 244 } 245 246 // FuncOnClicked returns the function "WEBEXT.systemIndicator.onClicked.addListener". 247 func FuncOnClicked() (fn js.Func[func(callback js.Func[func()])]) { 248 bindings.FuncOnClicked( 249 js.Pointer(&fn), 250 ) 251 return 252 } 253 254 // OnClicked calls the function "WEBEXT.systemIndicator.onClicked.addListener" directly. 255 func OnClicked(callback js.Func[func()]) (ret js.Void) { 256 bindings.CallOnClicked( 257 js.Pointer(&ret), 258 callback.Ref(), 259 ) 260 261 return 262 } 263 264 // TryOnClicked calls the function "WEBEXT.systemIndicator.onClicked.addListener" 265 // in a try/catch block and returns (_, err, ok = false) when it went through 266 // the catch clause. 267 func TryOnClicked(callback js.Func[func()]) (ret js.Void, exception js.Any, ok bool) { 268 ok = js.True == bindings.TryOnClicked( 269 js.Pointer(&ret), js.Pointer(&exception), 270 callback.Ref(), 271 ) 272 273 return 274 } 275 276 // HasFuncOffClicked returns true if the function "WEBEXT.systemIndicator.onClicked.removeListener" exists. 277 func HasFuncOffClicked() bool { 278 return js.True == bindings.HasFuncOffClicked() 279 } 280 281 // FuncOffClicked returns the function "WEBEXT.systemIndicator.onClicked.removeListener". 282 func FuncOffClicked() (fn js.Func[func(callback js.Func[func()])]) { 283 bindings.FuncOffClicked( 284 js.Pointer(&fn), 285 ) 286 return 287 } 288 289 // OffClicked calls the function "WEBEXT.systemIndicator.onClicked.removeListener" directly. 290 func OffClicked(callback js.Func[func()]) (ret js.Void) { 291 bindings.CallOffClicked( 292 js.Pointer(&ret), 293 callback.Ref(), 294 ) 295 296 return 297 } 298 299 // TryOffClicked calls the function "WEBEXT.systemIndicator.onClicked.removeListener" 300 // in a try/catch block and returns (_, err, ok = false) when it went through 301 // the catch clause. 302 func TryOffClicked(callback js.Func[func()]) (ret js.Void, exception js.Any, ok bool) { 303 ok = js.True == bindings.TryOffClicked( 304 js.Pointer(&ret), js.Pointer(&exception), 305 callback.Ref(), 306 ) 307 308 return 309 } 310 311 // HasFuncHasOnClicked returns true if the function "WEBEXT.systemIndicator.onClicked.hasListener" exists. 312 func HasFuncHasOnClicked() bool { 313 return js.True == bindings.HasFuncHasOnClicked() 314 } 315 316 // FuncHasOnClicked returns the function "WEBEXT.systemIndicator.onClicked.hasListener". 317 func FuncHasOnClicked() (fn js.Func[func(callback js.Func[func()]) bool]) { 318 bindings.FuncHasOnClicked( 319 js.Pointer(&fn), 320 ) 321 return 322 } 323 324 // HasOnClicked calls the function "WEBEXT.systemIndicator.onClicked.hasListener" directly. 325 func HasOnClicked(callback js.Func[func()]) (ret bool) { 326 bindings.CallHasOnClicked( 327 js.Pointer(&ret), 328 callback.Ref(), 329 ) 330 331 return 332 } 333 334 // TryHasOnClicked calls the function "WEBEXT.systemIndicator.onClicked.hasListener" 335 // in a try/catch block and returns (_, err, ok = false) when it went through 336 // the catch clause. 337 func TryHasOnClicked(callback js.Func[func()]) (ret bool, exception js.Any, ok bool) { 338 ok = js.True == bindings.TryHasOnClicked( 339 js.Pointer(&ret), js.Pointer(&exception), 340 callback.Ref(), 341 ) 342 343 return 344 } 345 346 // HasFuncSetIcon returns true if the function "WEBEXT.systemIndicator.setIcon" exists. 347 func HasFuncSetIcon() bool { 348 return js.True == bindings.HasFuncSetIcon() 349 } 350 351 // FuncSetIcon returns the function "WEBEXT.systemIndicator.setIcon". 352 func FuncSetIcon() (fn js.Func[func(details SetIconDetails) js.Promise[js.Void]]) { 353 bindings.FuncSetIcon( 354 js.Pointer(&fn), 355 ) 356 return 357 } 358 359 // SetIcon calls the function "WEBEXT.systemIndicator.setIcon" directly. 360 func SetIcon(details SetIconDetails) (ret js.Promise[js.Void]) { 361 bindings.CallSetIcon( 362 js.Pointer(&ret), 363 js.Pointer(&details), 364 ) 365 366 return 367 } 368 369 // TrySetIcon calls the function "WEBEXT.systemIndicator.setIcon" 370 // in a try/catch block and returns (_, err, ok = false) when it went through 371 // the catch clause. 372 func TrySetIcon(details SetIconDetails) (ret js.Promise[js.Void], exception js.Any, ok bool) { 373 ok = js.True == bindings.TrySetIcon( 374 js.Pointer(&ret), js.Pointer(&exception), 375 js.Pointer(&details), 376 ) 377 378 return 379 }