github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/loginstate/apis_js_wasm.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright 2023 The Prime Citizens 3 4 package loginstate 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/loginstate/bindings" 10 ) 11 12 type ProfileType uint32 13 14 const ( 15 _ ProfileType = iota 16 17 ProfileType_SIGNIN_PROFILE 18 ProfileType_USER_PROFILE 19 ) 20 21 func (ProfileType) FromRef(str js.Ref) ProfileType { 22 return ProfileType(bindings.ConstOfProfileType(str)) 23 } 24 25 func (x ProfileType) String() (string, bool) { 26 switch x { 27 case ProfileType_SIGNIN_PROFILE: 28 return "SIGNIN_PROFILE", true 29 case ProfileType_USER_PROFILE: 30 return "USER_PROFILE", true 31 default: 32 return "", false 33 } 34 } 35 36 type ProfileTypeCallbackFunc func(this js.Ref, result ProfileType) js.Ref 37 38 func (fn ProfileTypeCallbackFunc) Register() js.Func[func(result ProfileType)] { 39 return js.RegisterCallback[func(result ProfileType)]( 40 fn, abi.FuncPCABIInternal(fn), 41 ) 42 } 43 44 func (fn ProfileTypeCallbackFunc) DispatchCallback( 45 targetPC uintptr, ctx *js.CallbackContext, 46 ) { 47 args := ctx.Args() 48 if len(args) != 1+1 /* js this */ || 49 targetPC != uintptr(abi.FuncPCABIInternal(fn)) { 50 js.ThrowInvalidCallbackInvocation() 51 } 52 53 if ctx.Return(fn( 54 args[0], 55 56 ProfileType(0).FromRef(args[0+1]), 57 )) { 58 return 59 } 60 61 js.ThrowCallbackValueNotReturned() 62 } 63 64 type ProfileTypeCallback[T any] struct { 65 Fn func(arg T, this js.Ref, result ProfileType) js.Ref 66 Arg T 67 } 68 69 func (cb *ProfileTypeCallback[T]) Register() js.Func[func(result ProfileType)] { 70 return js.RegisterCallback[func(result ProfileType)]( 71 cb, abi.FuncPCABIInternal(cb.Fn), 72 ) 73 } 74 75 func (cb *ProfileTypeCallback[T]) DispatchCallback( 76 targetPC uintptr, ctx *js.CallbackContext, 77 ) { 78 args := ctx.Args() 79 if len(args) != 1+1 /* js this */ || 80 targetPC != uintptr(abi.FuncPCABIInternal(cb.Fn)) { 81 js.ThrowInvalidCallbackInvocation() 82 } 83 84 if ctx.Return(cb.Fn( 85 cb.Arg, 86 args[0], 87 88 ProfileType(0).FromRef(args[0+1]), 89 )) { 90 return 91 } 92 93 js.ThrowCallbackValueNotReturned() 94 } 95 96 type SessionState uint32 97 98 const ( 99 _ SessionState = iota 100 101 SessionState_UNKNOWN 102 SessionState_IN_OOBE_SCREEN 103 SessionState_IN_LOGIN_SCREEN 104 SessionState_IN_SESSION 105 SessionState_IN_LOCK_SCREEN 106 SessionState_IN_RMA_SCREEN 107 ) 108 109 func (SessionState) FromRef(str js.Ref) SessionState { 110 return SessionState(bindings.ConstOfSessionState(str)) 111 } 112 113 func (x SessionState) String() (string, bool) { 114 switch x { 115 case SessionState_UNKNOWN: 116 return "UNKNOWN", true 117 case SessionState_IN_OOBE_SCREEN: 118 return "IN_OOBE_SCREEN", true 119 case SessionState_IN_LOGIN_SCREEN: 120 return "IN_LOGIN_SCREEN", true 121 case SessionState_IN_SESSION: 122 return "IN_SESSION", true 123 case SessionState_IN_LOCK_SCREEN: 124 return "IN_LOCK_SCREEN", true 125 case SessionState_IN_RMA_SCREEN: 126 return "IN_RMA_SCREEN", true 127 default: 128 return "", false 129 } 130 } 131 132 type SessionStateCallbackFunc func(this js.Ref, result SessionState) js.Ref 133 134 func (fn SessionStateCallbackFunc) Register() js.Func[func(result SessionState)] { 135 return js.RegisterCallback[func(result SessionState)]( 136 fn, abi.FuncPCABIInternal(fn), 137 ) 138 } 139 140 func (fn SessionStateCallbackFunc) DispatchCallback( 141 targetPC uintptr, ctx *js.CallbackContext, 142 ) { 143 args := ctx.Args() 144 if len(args) != 1+1 /* js this */ || 145 targetPC != uintptr(abi.FuncPCABIInternal(fn)) { 146 js.ThrowInvalidCallbackInvocation() 147 } 148 149 if ctx.Return(fn( 150 args[0], 151 152 SessionState(0).FromRef(args[0+1]), 153 )) { 154 return 155 } 156 157 js.ThrowCallbackValueNotReturned() 158 } 159 160 type SessionStateCallback[T any] struct { 161 Fn func(arg T, this js.Ref, result SessionState) js.Ref 162 Arg T 163 } 164 165 func (cb *SessionStateCallback[T]) Register() js.Func[func(result SessionState)] { 166 return js.RegisterCallback[func(result SessionState)]( 167 cb, abi.FuncPCABIInternal(cb.Fn), 168 ) 169 } 170 171 func (cb *SessionStateCallback[T]) DispatchCallback( 172 targetPC uintptr, ctx *js.CallbackContext, 173 ) { 174 args := ctx.Args() 175 if len(args) != 1+1 /* js this */ || 176 targetPC != uintptr(abi.FuncPCABIInternal(cb.Fn)) { 177 js.ThrowInvalidCallbackInvocation() 178 } 179 180 if ctx.Return(cb.Fn( 181 cb.Arg, 182 args[0], 183 184 SessionState(0).FromRef(args[0+1]), 185 )) { 186 return 187 } 188 189 js.ThrowCallbackValueNotReturned() 190 } 191 192 // HasFuncGetProfileType returns true if the function "WEBEXT.loginState.getProfileType" exists. 193 func HasFuncGetProfileType() bool { 194 return js.True == bindings.HasFuncGetProfileType() 195 } 196 197 // FuncGetProfileType returns the function "WEBEXT.loginState.getProfileType". 198 func FuncGetProfileType() (fn js.Func[func() js.Promise[ProfileType]]) { 199 bindings.FuncGetProfileType( 200 js.Pointer(&fn), 201 ) 202 return 203 } 204 205 // GetProfileType calls the function "WEBEXT.loginState.getProfileType" directly. 206 func GetProfileType() (ret js.Promise[ProfileType]) { 207 bindings.CallGetProfileType( 208 js.Pointer(&ret), 209 ) 210 211 return 212 } 213 214 // TryGetProfileType calls the function "WEBEXT.loginState.getProfileType" 215 // in a try/catch block and returns (_, err, ok = false) when it went through 216 // the catch clause. 217 func TryGetProfileType() (ret js.Promise[ProfileType], exception js.Any, ok bool) { 218 ok = js.True == bindings.TryGetProfileType( 219 js.Pointer(&ret), js.Pointer(&exception), 220 ) 221 222 return 223 } 224 225 // HasFuncGetSessionState returns true if the function "WEBEXT.loginState.getSessionState" exists. 226 func HasFuncGetSessionState() bool { 227 return js.True == bindings.HasFuncGetSessionState() 228 } 229 230 // FuncGetSessionState returns the function "WEBEXT.loginState.getSessionState". 231 func FuncGetSessionState() (fn js.Func[func() js.Promise[SessionState]]) { 232 bindings.FuncGetSessionState( 233 js.Pointer(&fn), 234 ) 235 return 236 } 237 238 // GetSessionState calls the function "WEBEXT.loginState.getSessionState" directly. 239 func GetSessionState() (ret js.Promise[SessionState]) { 240 bindings.CallGetSessionState( 241 js.Pointer(&ret), 242 ) 243 244 return 245 } 246 247 // TryGetSessionState calls the function "WEBEXT.loginState.getSessionState" 248 // in a try/catch block and returns (_, err, ok = false) when it went through 249 // the catch clause. 250 func TryGetSessionState() (ret js.Promise[SessionState], exception js.Any, ok bool) { 251 ok = js.True == bindings.TryGetSessionState( 252 js.Pointer(&ret), js.Pointer(&exception), 253 ) 254 255 return 256 } 257 258 type OnSessionStateChangedEventCallbackFunc func(this js.Ref, sessionState SessionState) js.Ref 259 260 func (fn OnSessionStateChangedEventCallbackFunc) Register() js.Func[func(sessionState SessionState)] { 261 return js.RegisterCallback[func(sessionState SessionState)]( 262 fn, abi.FuncPCABIInternal(fn), 263 ) 264 } 265 266 func (fn OnSessionStateChangedEventCallbackFunc) DispatchCallback( 267 targetPC uintptr, ctx *js.CallbackContext, 268 ) { 269 args := ctx.Args() 270 if len(args) != 1+1 /* js this */ || 271 targetPC != uintptr(abi.FuncPCABIInternal(fn)) { 272 js.ThrowInvalidCallbackInvocation() 273 } 274 275 if ctx.Return(fn( 276 args[0], 277 278 SessionState(0).FromRef(args[0+1]), 279 )) { 280 return 281 } 282 283 js.ThrowCallbackValueNotReturned() 284 } 285 286 type OnSessionStateChangedEventCallback[T any] struct { 287 Fn func(arg T, this js.Ref, sessionState SessionState) js.Ref 288 Arg T 289 } 290 291 func (cb *OnSessionStateChangedEventCallback[T]) Register() js.Func[func(sessionState SessionState)] { 292 return js.RegisterCallback[func(sessionState SessionState)]( 293 cb, abi.FuncPCABIInternal(cb.Fn), 294 ) 295 } 296 297 func (cb *OnSessionStateChangedEventCallback[T]) DispatchCallback( 298 targetPC uintptr, ctx *js.CallbackContext, 299 ) { 300 args := ctx.Args() 301 if len(args) != 1+1 /* js this */ || 302 targetPC != uintptr(abi.FuncPCABIInternal(cb.Fn)) { 303 js.ThrowInvalidCallbackInvocation() 304 } 305 306 if ctx.Return(cb.Fn( 307 cb.Arg, 308 args[0], 309 310 SessionState(0).FromRef(args[0+1]), 311 )) { 312 return 313 } 314 315 js.ThrowCallbackValueNotReturned() 316 } 317 318 // HasFuncOnSessionStateChanged returns true if the function "WEBEXT.loginState.onSessionStateChanged.addListener" exists. 319 func HasFuncOnSessionStateChanged() bool { 320 return js.True == bindings.HasFuncOnSessionStateChanged() 321 } 322 323 // FuncOnSessionStateChanged returns the function "WEBEXT.loginState.onSessionStateChanged.addListener". 324 func FuncOnSessionStateChanged() (fn js.Func[func(callback js.Func[func(sessionState SessionState)])]) { 325 bindings.FuncOnSessionStateChanged( 326 js.Pointer(&fn), 327 ) 328 return 329 } 330 331 // OnSessionStateChanged calls the function "WEBEXT.loginState.onSessionStateChanged.addListener" directly. 332 func OnSessionStateChanged(callback js.Func[func(sessionState SessionState)]) (ret js.Void) { 333 bindings.CallOnSessionStateChanged( 334 js.Pointer(&ret), 335 callback.Ref(), 336 ) 337 338 return 339 } 340 341 // TryOnSessionStateChanged calls the function "WEBEXT.loginState.onSessionStateChanged.addListener" 342 // in a try/catch block and returns (_, err, ok = false) when it went through 343 // the catch clause. 344 func TryOnSessionStateChanged(callback js.Func[func(sessionState SessionState)]) (ret js.Void, exception js.Any, ok bool) { 345 ok = js.True == bindings.TryOnSessionStateChanged( 346 js.Pointer(&ret), js.Pointer(&exception), 347 callback.Ref(), 348 ) 349 350 return 351 } 352 353 // HasFuncOffSessionStateChanged returns true if the function "WEBEXT.loginState.onSessionStateChanged.removeListener" exists. 354 func HasFuncOffSessionStateChanged() bool { 355 return js.True == bindings.HasFuncOffSessionStateChanged() 356 } 357 358 // FuncOffSessionStateChanged returns the function "WEBEXT.loginState.onSessionStateChanged.removeListener". 359 func FuncOffSessionStateChanged() (fn js.Func[func(callback js.Func[func(sessionState SessionState)])]) { 360 bindings.FuncOffSessionStateChanged( 361 js.Pointer(&fn), 362 ) 363 return 364 } 365 366 // OffSessionStateChanged calls the function "WEBEXT.loginState.onSessionStateChanged.removeListener" directly. 367 func OffSessionStateChanged(callback js.Func[func(sessionState SessionState)]) (ret js.Void) { 368 bindings.CallOffSessionStateChanged( 369 js.Pointer(&ret), 370 callback.Ref(), 371 ) 372 373 return 374 } 375 376 // TryOffSessionStateChanged calls the function "WEBEXT.loginState.onSessionStateChanged.removeListener" 377 // in a try/catch block and returns (_, err, ok = false) when it went through 378 // the catch clause. 379 func TryOffSessionStateChanged(callback js.Func[func(sessionState SessionState)]) (ret js.Void, exception js.Any, ok bool) { 380 ok = js.True == bindings.TryOffSessionStateChanged( 381 js.Pointer(&ret), js.Pointer(&exception), 382 callback.Ref(), 383 ) 384 385 return 386 } 387 388 // HasFuncHasOnSessionStateChanged returns true if the function "WEBEXT.loginState.onSessionStateChanged.hasListener" exists. 389 func HasFuncHasOnSessionStateChanged() bool { 390 return js.True == bindings.HasFuncHasOnSessionStateChanged() 391 } 392 393 // FuncHasOnSessionStateChanged returns the function "WEBEXT.loginState.onSessionStateChanged.hasListener". 394 func FuncHasOnSessionStateChanged() (fn js.Func[func(callback js.Func[func(sessionState SessionState)]) bool]) { 395 bindings.FuncHasOnSessionStateChanged( 396 js.Pointer(&fn), 397 ) 398 return 399 } 400 401 // HasOnSessionStateChanged calls the function "WEBEXT.loginState.onSessionStateChanged.hasListener" directly. 402 func HasOnSessionStateChanged(callback js.Func[func(sessionState SessionState)]) (ret bool) { 403 bindings.CallHasOnSessionStateChanged( 404 js.Pointer(&ret), 405 callback.Ref(), 406 ) 407 408 return 409 } 410 411 // TryHasOnSessionStateChanged calls the function "WEBEXT.loginState.onSessionStateChanged.hasListener" 412 // in a try/catch block and returns (_, err, ok = false) when it went through 413 // the catch clause. 414 func TryHasOnSessionStateChanged(callback js.Func[func(sessionState SessionState)]) (ret bool, exception js.Any, ok bool) { 415 ok = js.True == bindings.TryHasOnSessionStateChanged( 416 js.Pointer(&ret), js.Pointer(&exception), 417 callback.Ref(), 418 ) 419 420 return 421 }