github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/systemindicator/bindings/ffi_bindings.ts (about) 1 import { importModule, Application, heap, Pointer } from "@ffi"; 2 3 importModule("plat/js/webext/systemindicator", (A: Application) => { 4 const WEBEXT = typeof globalThis.browser === "undefined" ? globalThis.chrome : globalThis.browser; 5 6 return { 7 "store_SetIconDetails": (ptr: Pointer, ref: heap.Ref<any>) => { 8 const x = A.H.get<any>(ref); 9 10 if (typeof x === "undefined") { 11 A.store.Bool(ptr + 8, false); 12 A.store.Ref(ptr + 0, undefined); 13 A.store.Ref(ptr + 4, undefined); 14 } else { 15 A.store.Bool(ptr + 8, true); 16 A.store.Ref(ptr + 0, x["path"]); 17 A.store.Ref(ptr + 4, x["imageData"]); 18 } 19 }, 20 "load_SetIconDetails": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => { 21 const x = create === A.H.TRUE ? {} : A.H.get<any>(ref); 22 23 x["path"] = A.load.Ref(ptr + 0, undefined); 24 x["imageData"] = A.load.Ref(ptr + 4, undefined); 25 return create === A.H.TRUE ? A.H.push(x) : ref; 26 }, 27 "has_Disable": (): heap.Ref<boolean> => { 28 if (WEBEXT?.systemIndicator && "disable" in WEBEXT?.systemIndicator) { 29 return A.H.TRUE; 30 } 31 return A.H.FALSE; 32 }, 33 "func_Disable": (fn: Pointer): void => { 34 A.store.Ref(fn, WEBEXT.systemIndicator.disable); 35 }, 36 "call_Disable": (retPtr: Pointer): void => { 37 const _ret = WEBEXT.systemIndicator.disable(); 38 }, 39 "try_Disable": (retPtr: Pointer, errPtr: Pointer): heap.Ref<boolean> => { 40 try { 41 const _ret = WEBEXT.systemIndicator.disable(); 42 return A.H.TRUE; 43 } catch (err: any) { 44 A.store.Ref(errPtr, err); 45 return A.H.FALSE; 46 } 47 }, 48 "has_Enable": (): heap.Ref<boolean> => { 49 if (WEBEXT?.systemIndicator && "enable" in WEBEXT?.systemIndicator) { 50 return A.H.TRUE; 51 } 52 return A.H.FALSE; 53 }, 54 "func_Enable": (fn: Pointer): void => { 55 A.store.Ref(fn, WEBEXT.systemIndicator.enable); 56 }, 57 "call_Enable": (retPtr: Pointer): void => { 58 const _ret = WEBEXT.systemIndicator.enable(); 59 }, 60 "try_Enable": (retPtr: Pointer, errPtr: Pointer): heap.Ref<boolean> => { 61 try { 62 const _ret = WEBEXT.systemIndicator.enable(); 63 return A.H.TRUE; 64 } catch (err: any) { 65 A.store.Ref(errPtr, err); 66 return A.H.FALSE; 67 } 68 }, 69 "has_OnClicked": (): heap.Ref<boolean> => { 70 if (WEBEXT?.systemIndicator?.onClicked && "addListener" in WEBEXT?.systemIndicator?.onClicked) { 71 return A.H.TRUE; 72 } 73 return A.H.FALSE; 74 }, 75 "func_OnClicked": (fn: Pointer): void => { 76 A.store.Ref(fn, WEBEXT.systemIndicator.onClicked.addListener); 77 }, 78 "call_OnClicked": (retPtr: Pointer, callback: heap.Ref<object>): void => { 79 const _ret = WEBEXT.systemIndicator.onClicked.addListener(A.H.get<object>(callback)); 80 }, 81 "try_OnClicked": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => { 82 try { 83 const _ret = WEBEXT.systemIndicator.onClicked.addListener(A.H.get<object>(callback)); 84 return A.H.TRUE; 85 } catch (err: any) { 86 A.store.Ref(errPtr, err); 87 return A.H.FALSE; 88 } 89 }, 90 "has_OffClicked": (): heap.Ref<boolean> => { 91 if (WEBEXT?.systemIndicator?.onClicked && "removeListener" in WEBEXT?.systemIndicator?.onClicked) { 92 return A.H.TRUE; 93 } 94 return A.H.FALSE; 95 }, 96 "func_OffClicked": (fn: Pointer): void => { 97 A.store.Ref(fn, WEBEXT.systemIndicator.onClicked.removeListener); 98 }, 99 "call_OffClicked": (retPtr: Pointer, callback: heap.Ref<object>): void => { 100 const _ret = WEBEXT.systemIndicator.onClicked.removeListener(A.H.get<object>(callback)); 101 }, 102 "try_OffClicked": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => { 103 try { 104 const _ret = WEBEXT.systemIndicator.onClicked.removeListener(A.H.get<object>(callback)); 105 return A.H.TRUE; 106 } catch (err: any) { 107 A.store.Ref(errPtr, err); 108 return A.H.FALSE; 109 } 110 }, 111 "has_HasOnClicked": (): heap.Ref<boolean> => { 112 if (WEBEXT?.systemIndicator?.onClicked && "hasListener" in WEBEXT?.systemIndicator?.onClicked) { 113 return A.H.TRUE; 114 } 115 return A.H.FALSE; 116 }, 117 "func_HasOnClicked": (fn: Pointer): void => { 118 A.store.Ref(fn, WEBEXT.systemIndicator.onClicked.hasListener); 119 }, 120 "call_HasOnClicked": (retPtr: Pointer, callback: heap.Ref<object>): void => { 121 const _ret = WEBEXT.systemIndicator.onClicked.hasListener(A.H.get<object>(callback)); 122 A.store.Bool(retPtr, _ret); 123 }, 124 "try_HasOnClicked": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => { 125 try { 126 const _ret = WEBEXT.systemIndicator.onClicked.hasListener(A.H.get<object>(callback)); 127 A.store.Bool(retPtr, _ret); 128 return A.H.TRUE; 129 } catch (err: any) { 130 A.store.Ref(errPtr, err); 131 return A.H.FALSE; 132 } 133 }, 134 "has_SetIcon": (): heap.Ref<boolean> => { 135 if (WEBEXT?.systemIndicator && "setIcon" in WEBEXT?.systemIndicator) { 136 return A.H.TRUE; 137 } 138 return A.H.FALSE; 139 }, 140 "func_SetIcon": (fn: Pointer): void => { 141 A.store.Ref(fn, WEBEXT.systemIndicator.setIcon); 142 }, 143 "call_SetIcon": (retPtr: Pointer, details: Pointer): void => { 144 const details_ffi = {}; 145 146 details_ffi["path"] = A.load.Ref(details + 0, undefined); 147 details_ffi["imageData"] = A.load.Ref(details + 4, undefined); 148 149 const _ret = WEBEXT.systemIndicator.setIcon(details_ffi); 150 A.store.Ref(retPtr, _ret); 151 }, 152 "try_SetIcon": (retPtr: Pointer, errPtr: Pointer, details: Pointer): heap.Ref<boolean> => { 153 try { 154 const details_ffi = {}; 155 156 details_ffi["path"] = A.load.Ref(details + 0, undefined); 157 details_ffi["imageData"] = A.load.Ref(details + 4, undefined); 158 159 const _ret = WEBEXT.systemIndicator.setIcon(details_ffi); 160 A.store.Ref(retPtr, _ret); 161 return A.H.TRUE; 162 } catch (err: any) { 163 A.store.Ref(errPtr, err); 164 return A.H.FALSE; 165 } 166 }, 167 }; 168 });