github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/power/bindings/ffi_bindings.ts (about) 1 import { importModule, Application, heap, Pointer } from "@ffi"; 2 3 importModule("plat/js/webext/power", (A: Application) => { 4 const WEBEXT = typeof globalThis.browser === "undefined" ? globalThis.chrome : globalThis.browser; 5 6 return { 7 "constof_Level": (ref: heap.Ref<string>): number => { 8 const idx = ["system", "display"].indexOf(A.H.get(ref)); 9 return idx < 0 ? 0 : idx + 1; 10 }, 11 "has_ReleaseKeepAwake": (): heap.Ref<boolean> => { 12 if (WEBEXT?.power && "releaseKeepAwake" in WEBEXT?.power) { 13 return A.H.TRUE; 14 } 15 return A.H.FALSE; 16 }, 17 "func_ReleaseKeepAwake": (fn: Pointer): void => { 18 A.store.Ref(fn, WEBEXT.power.releaseKeepAwake); 19 }, 20 "call_ReleaseKeepAwake": (retPtr: Pointer): void => { 21 const _ret = WEBEXT.power.releaseKeepAwake(); 22 }, 23 "try_ReleaseKeepAwake": (retPtr: Pointer, errPtr: Pointer): heap.Ref<boolean> => { 24 try { 25 const _ret = WEBEXT.power.releaseKeepAwake(); 26 return A.H.TRUE; 27 } catch (err: any) { 28 A.store.Ref(errPtr, err); 29 return A.H.FALSE; 30 } 31 }, 32 "has_ReportActivity": (): heap.Ref<boolean> => { 33 if (WEBEXT?.power && "reportActivity" in WEBEXT?.power) { 34 return A.H.TRUE; 35 } 36 return A.H.FALSE; 37 }, 38 "func_ReportActivity": (fn: Pointer): void => { 39 A.store.Ref(fn, WEBEXT.power.reportActivity); 40 }, 41 "call_ReportActivity": (retPtr: Pointer): void => { 42 const _ret = WEBEXT.power.reportActivity(); 43 A.store.Ref(retPtr, _ret); 44 }, 45 "try_ReportActivity": (retPtr: Pointer, errPtr: Pointer): heap.Ref<boolean> => { 46 try { 47 const _ret = WEBEXT.power.reportActivity(); 48 A.store.Ref(retPtr, _ret); 49 return A.H.TRUE; 50 } catch (err: any) { 51 A.store.Ref(errPtr, err); 52 return A.H.FALSE; 53 } 54 }, 55 "has_RequestKeepAwake": (): heap.Ref<boolean> => { 56 if (WEBEXT?.power && "requestKeepAwake" in WEBEXT?.power) { 57 return A.H.TRUE; 58 } 59 return A.H.FALSE; 60 }, 61 "func_RequestKeepAwake": (fn: Pointer): void => { 62 A.store.Ref(fn, WEBEXT.power.requestKeepAwake); 63 }, 64 "call_RequestKeepAwake": (retPtr: Pointer, level: number): void => { 65 const _ret = WEBEXT.power.requestKeepAwake( 66 level > 0 && level <= 2 ? ["system", "display"][level - 1] : undefined 67 ); 68 }, 69 "try_RequestKeepAwake": (retPtr: Pointer, errPtr: Pointer, level: number): heap.Ref<boolean> => { 70 try { 71 const _ret = WEBEXT.power.requestKeepAwake( 72 level > 0 && level <= 2 ? ["system", "display"][level - 1] : undefined 73 ); 74 return A.H.TRUE; 75 } catch (err: any) { 76 A.store.Ref(errPtr, err); 77 return A.H.FALSE; 78 } 79 }, 80 }; 81 });