github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/wallpaper/apis_js_wasm.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright 2023 The Prime Citizens 3 4 package wallpaper 5 6 import ( 7 "github.com/primecitizens/pcz/std/ffi/js" 8 "github.com/primecitizens/pcz/std/plat/js/webext/wallpaper/bindings" 9 ) 10 11 type WallpaperLayout uint32 12 13 const ( 14 _ WallpaperLayout = iota 15 16 WallpaperLayout_STRETCH 17 WallpaperLayout_CENTER 18 WallpaperLayout_CENTER_CROPPED 19 ) 20 21 func (WallpaperLayout) FromRef(str js.Ref) WallpaperLayout { 22 return WallpaperLayout(bindings.ConstOfWallpaperLayout(str)) 23 } 24 25 func (x WallpaperLayout) String() (string, bool) { 26 switch x { 27 case WallpaperLayout_STRETCH: 28 return "STRETCH", true 29 case WallpaperLayout_CENTER: 30 return "CENTER", true 31 case WallpaperLayout_CENTER_CROPPED: 32 return "CENTER_CROPPED", true 33 default: 34 return "", false 35 } 36 } 37 38 type SetWallpaperArgDetails struct { 39 // Data is "SetWallpaperArgDetails.data" 40 // 41 // Optional 42 Data js.TypedArray[uint8] 43 // Filename is "SetWallpaperArgDetails.filename" 44 // 45 // Required 46 Filename js.String 47 // Layout is "SetWallpaperArgDetails.layout" 48 // 49 // Required 50 Layout WallpaperLayout 51 // Thumbnail is "SetWallpaperArgDetails.thumbnail" 52 // 53 // Optional 54 // 55 // NOTE: FFI_USE_Thumbnail MUST be set to true to make this field effective. 56 Thumbnail bool 57 // Url is "SetWallpaperArgDetails.url" 58 // 59 // Optional 60 Url js.String 61 62 FFI_USE_Thumbnail bool // for Thumbnail. 63 64 FFI_USE bool 65 } 66 67 // FromRef calls UpdateFrom and returns a SetWallpaperArgDetails with all fields set. 68 func (p SetWallpaperArgDetails) FromRef(ref js.Ref) SetWallpaperArgDetails { 69 p.UpdateFrom(ref) 70 return p 71 } 72 73 // New creates a new SetWallpaperArgDetails in the application heap. 74 func (p SetWallpaperArgDetails) New() js.Ref { 75 return bindings.SetWallpaperArgDetailsJSLoad( 76 js.Pointer(&p), js.True, 0, 77 ) 78 } 79 80 // UpdateFrom copies value of all fields of the heap object to p. 81 func (p *SetWallpaperArgDetails) UpdateFrom(ref js.Ref) { 82 bindings.SetWallpaperArgDetailsJSStore( 83 js.Pointer(p), ref, 84 ) 85 } 86 87 // Update writes all fields of the p to the heap object referenced by ref. 88 func (p *SetWallpaperArgDetails) Update(ref js.Ref) { 89 bindings.SetWallpaperArgDetailsJSLoad( 90 js.Pointer(p), js.False, ref, 91 ) 92 } 93 94 // FreeMembers frees fields with heap reference, if recursive is true 95 // free all heap references reachable from p. 96 func (p *SetWallpaperArgDetails) FreeMembers(recursive bool) { 97 js.Free( 98 p.Data.Ref(), 99 p.Filename.Ref(), 100 p.Url.Ref(), 101 ) 102 p.Data = p.Data.FromRef(js.Undefined) 103 p.Filename = p.Filename.FromRef(js.Undefined) 104 p.Url = p.Url.FromRef(js.Undefined) 105 } 106 107 // HasFuncSetWallpaper returns true if the function "WEBEXT.wallpaper.setWallpaper" exists. 108 func HasFuncSetWallpaper() bool { 109 return js.True == bindings.HasFuncSetWallpaper() 110 } 111 112 // FuncSetWallpaper returns the function "WEBEXT.wallpaper.setWallpaper". 113 func FuncSetWallpaper() (fn js.Func[func(details SetWallpaperArgDetails) js.Promise[js.TypedArray[uint8]]]) { 114 bindings.FuncSetWallpaper( 115 js.Pointer(&fn), 116 ) 117 return 118 } 119 120 // SetWallpaper calls the function "WEBEXT.wallpaper.setWallpaper" directly. 121 func SetWallpaper(details SetWallpaperArgDetails) (ret js.Promise[js.TypedArray[uint8]]) { 122 bindings.CallSetWallpaper( 123 js.Pointer(&ret), 124 js.Pointer(&details), 125 ) 126 127 return 128 } 129 130 // TrySetWallpaper calls the function "WEBEXT.wallpaper.setWallpaper" 131 // in a try/catch block and returns (_, err, ok = false) when it went through 132 // the catch clause. 133 func TrySetWallpaper(details SetWallpaperArgDetails) (ret js.Promise[js.TypedArray[uint8]], exception js.Any, ok bool) { 134 ok = js.True == bindings.TrySetWallpaper( 135 js.Pointer(&ret), js.Pointer(&exception), 136 js.Pointer(&details), 137 ) 138 139 return 140 }