github.com/secoba/wails/v2@v2.6.4/internal/frontend/runtime/desktop/bindings.js (about) 1 /* 2 _ __ _ __ 3 | | / /___ _(_) /____ 4 | | /| / / __ `/ / / ___/ 5 | |/ |/ / /_/ / / (__ ) 6 |__/|__/\__,_/_/_/____/ 7 The electron alternative for Go 8 (c) Lea Anthony 2019-present 9 */ 10 /* jshint esversion: 6 */ 11 12 import {Call} from './calls'; 13 14 // This is where we bind go method wrappers 15 window.go = {}; 16 17 export function SetBindings(bindingsMap) { 18 try { 19 bindingsMap = JSON.parse(bindingsMap); 20 } catch (e) { 21 console.error(e); 22 } 23 24 // Initialise the bindings map 25 window.go = window.go || {}; 26 27 // Iterate package names 28 Object.keys(bindingsMap).forEach((packageName) => { 29 30 // Create inner map if it doesn't exist 31 window.go[packageName] = window.go[packageName] || {}; 32 33 // Iterate struct names 34 Object.keys(bindingsMap[packageName]).forEach((structName) => { 35 36 // Create inner map if it doesn't exist 37 window.go[packageName][structName] = window.go[packageName][structName] || {}; 38 39 Object.keys(bindingsMap[packageName][structName]).forEach((methodName) => { 40 41 window.go[packageName][structName][methodName] = function () { 42 43 // No timeout by default 44 let timeout = 0; 45 46 // Actual function 47 function dynamic() { 48 const args = [].slice.call(arguments); 49 return Call([packageName, structName, methodName].join('.'), args, timeout); 50 } 51 52 // Allow setting timeout to function 53 dynamic.setTimeout = function (newTimeout) { 54 timeout = newTimeout; 55 }; 56 57 // Allow getting timeout to function 58 dynamic.getTimeout = function () { 59 return timeout; 60 }; 61 62 return dynamic; 63 }(); 64 }); 65 }); 66 }); 67 }