fix: linting fixes

This commit is contained in:
Lea Anthony
2019-06-30 17:16:38 +10:00
parent 44386490c8
commit 345c8bc094
6 changed files with 236 additions and 205 deletions

29
.eslintrc.js Normal file
View File

@@ -0,0 +1,29 @@
module.exports = {
"env": {
"browser": true,
"es6": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 2016,
"sourceType": "module",
},
"rules": {
"indent": [
"error",
"tab"
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
]
}
};

View File

@@ -1,3 +1,4 @@
{
"go.formatTool": "goimports"
"go.formatTool": "goimports",
"eslint.alwaysShowStatus": true
}

View File

@@ -18,199 +18,199 @@
// Bridge object
window.wailsbridge = {
reconnectOverlay: null,
reconnectTimer: 300,
wsURL: "ws://localhost:34115/bridge",
connectionState: null,
config: {},
websocket: null,
callback: null,
overlayHTML:
reconnectOverlay: null,
reconnectTimer: 300,
wsURL: 'ws://localhost:34115/bridge',
connectionState: null,
config: {},
websocket: null,
callback: null,
overlayHTML:
'<div class="wails-reconnect-overlay"><div class="wails-reconnect-overlay-content"><div class="wails-reconnect-overlay-title">Wails Bridge</div><br><div class="wails-reconnect-overlay-loadingspinner"></div><br><div id="wails-reconnect-overlay-message">Waiting for backend</div></div></div>',
overlayCSS:
".wails-reconnect-overlay{position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,.6);font-family:sans-serif;display:none;z-index:999999}.wails-reconnect-overlay-content{padding:20px 30px;text-align:center;width:20em;position:relative;height:14em;border-radius:1em;margin:5% auto 0;background-color:#fff;box-shadow:1px 1px 20px 3px;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC8AAAAuCAMAAACPpbA7AAAAqFBMVEUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEBAQAAAAAAAAEBAQAAAAAAAAAAAAEBAQEBAQDAwMBAQEAAAABAQEAAAAAAAAAAAABAQEAAAAAAAACAgICAgIBAQEAAAAAAAAAAAAAAAAAAAAAAAABAQEAAAACAgIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFBQWKCj6oAAAAN3RSTlMALiIqDhkGBAswJjP0GxP6NR4W9/ztjRDMhWU50G9g5eHXvbZ9XEI9xZTcqZl2aldKo55QwoCvZUgzhAAAAs9JREFUSMeNleeWqjAUhU0BCaH3Itiw9zKT93+zG02QK1hm/5HF+jzZJ6fQe6cyXE+jg9X7o9wxuylIIf4Tv2V3+bOrEXnf8dwQ/KQIGDN2/S+4OmVCVXL/ScBnfibxURqIByP/hONE8r8T+bDMlQ98KSl7Y8hzjpS8v1qtDh8u5f8KQpGpfnPPhqG8JeogN37Hq9eaN2xRhIwAaGnvws8F1ShxqK5ob2twYi1FAMD4rXsYtnC/JEiRbl4cUrCWhnMCLRFemXezXbb59QK4WASOsm6n2W1+4CBT2JmtzQ6fsrbGubR/NFbd2g5Y179+5w/GEHaKsHjYCet7CgrXU3txarNC7YxOVJtIj4/ERzMdZfzc31hp+8cD6eGILgarZY9uZ12hAs03vfBD9C171gS5Omz7OcvxALQIn4u8RRBBBcsi9WW2woO9ipLgfzpYlggg3ZRdROUC8KT7QLqq3W9KB5BbdFVg4929kdwp6+qaZnMCCNBdj+NyN1W885Ry/AL3D4AQbsVV4noCiM/C83kyYq80XlDAYQtralOiDzoRAHlotWl8q2tjvYlOgcg1A8jEApZa+C06TBdAz2Qv0wu11I/zZOyJQ6EwGez2P2b8PIQr1hwwnAZsAxwA4UAYOyXUxM/xp6tHAn4GUmPGM9R28oVxgC0e/zQJJI6DyhyZ1r7uzRQhpcW7x7vTaWSzKSG6aep77kroTEl3U81uSVaUTtgEINfC8epx+Q4F9SpplHG84Ek6m4RAq9/TLkOBrxyeuddZhHvGIp1XXfFy3Z3vtwNblKGiDn+J+92vwwABHghj7HnzlS1H5kB49AZvdGCFgiBPq69qfXPr3y++yilF0ON4R8eR7spAsLpZ95NqAW5tab1c4vkZm6aleajchMwYTdILQQTwE2OV411ZM9WztDjPql12caBi6gDpUKmDd4U1XNdQxZ4LIXQ5/Tr4P7I9tYcFrDK3AAAAAElFTkSuQmCC);background-repeat:no-repeat;background-position:center}.wails-reconnect-overlay-title{font-size:2em}.wails-reconnect-overlay-message{font-size:1.3em}.wails-reconnect-overlay-loadingspinner{pointer-events:none;width:2.5em;height:2.5em;border:.4em solid transparent;border-color:#3E67EC #eee #eee;border-radius:50%;animation:loadingspin 1s linear infinite;margin:auto;padding:2.5em}@keyframes loadingspin{100%{transform:rotate(360deg)}}",
log: function (message) {
// eslint-disable-next-line
overlayCSS:
'.wails-reconnect-overlay{position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,.6);font-family:sans-serif;display:none;z-index:999999}.wails-reconnect-overlay-content{padding:20px 30px;text-align:center;width:20em;position:relative;height:14em;border-radius:1em;margin:5% auto 0;background-color:#fff;box-shadow:1px 1px 20px 3px;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC8AAAAuCAMAAACPpbA7AAAAqFBMVEUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEBAQAAAAAAAAEBAQAAAAAAAAAAAAEBAQEBAQDAwMBAQEAAAABAQEAAAAAAAAAAAABAQEAAAAAAAACAgICAgIBAQEAAAAAAAAAAAAAAAAAAAAAAAABAQEAAAACAgIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFBQWKCj6oAAAAN3RSTlMALiIqDhkGBAswJjP0GxP6NR4W9/ztjRDMhWU50G9g5eHXvbZ9XEI9xZTcqZl2aldKo55QwoCvZUgzhAAAAs9JREFUSMeNleeWqjAUhU0BCaH3Itiw9zKT93+zG02QK1hm/5HF+jzZJ6fQe6cyXE+jg9X7o9wxuylIIf4Tv2V3+bOrEXnf8dwQ/KQIGDN2/S+4OmVCVXL/ScBnfibxURqIByP/hONE8r8T+bDMlQ98KSl7Y8hzjpS8v1qtDh8u5f8KQpGpfnPPhqG8JeogN37Hq9eaN2xRhIwAaGnvws8F1ShxqK5ob2twYi1FAMD4rXsYtnC/JEiRbl4cUrCWhnMCLRFemXezXbb59QK4WASOsm6n2W1+4CBT2JmtzQ6fsrbGubR/NFbd2g5Y179+5w/GEHaKsHjYCet7CgrXU3txarNC7YxOVJtIj4/ERzMdZfzc31hp+8cD6eGILgarZY9uZ12hAs03vfBD9C171gS5Omz7OcvxALQIn4u8RRBBBcsi9WW2woO9ipLgfzpYlggg3ZRdROUC8KT7QLqq3W9KB5BbdFVg4929kdwp6+qaZnMCCNBdj+NyN1W885Ry/AL3D4AQbsVV4noCiM/C83kyYq80XlDAYQtralOiDzoRAHlotWl8q2tjvYlOgcg1A8jEApZa+C06TBdAz2Qv0wu11I/zZOyJQ6EwGez2P2b8PIQr1hwwnAZsAxwA4UAYOyXUxM/xp6tHAn4GUmPGM9R28oVxgC0e/zQJJI6DyhyZ1r7uzRQhpcW7x7vTaWSzKSG6aep77kroTEl3U81uSVaUTtgEINfC8epx+Q4F9SpplHG84Ek6m4RAq9/TLkOBrxyeuddZhHvGIp1XXfFy3Z3vtwNblKGiDn+J+92vwwABHghj7HnzlS1H5kB49AZvdGCFgiBPq69qfXPr3y++yilF0ON4R8eR7spAsLpZ95NqAW5tab1c4vkZm6aleajchMwYTdILQQTwE2OV411ZM9WztDjPql12caBi6gDpUKmDd4U1XNdQxZ4LIXQ5/Tr4P7I9tYcFrDK3AAAAAElFTkSuQmCC);background-repeat:no-repeat;background-position:center}.wails-reconnect-overlay-title{font-size:2em}.wails-reconnect-overlay-message{font-size:1.3em}.wails-reconnect-overlay-loadingspinner{pointer-events:none;width:2.5em;height:2.5em;border:.4em solid transparent;border-color:#3E67EC #eee #eee;border-radius:50%;animation:loadingspin 1s linear infinite;margin:auto;padding:2.5em}@keyframes loadingspin{100%{transform:rotate(360deg)}}',
log: function (message) {
// eslint-disable-next-line
console.log(
"%c wails bridge %c " + message + " ",
"background: #aa0000; color: #fff; border-radius: 3px 0px 0px 3px; padding: 1px; font-size: 0.7rem",
"background: #009900; color: #fff; border-radius: 0px 3px 3px 0px; padding: 1px; font-size: 0.7rem"
);
}
'%c wails bridge %c ' + message + ' ',
'background: #aa0000; color: #fff; border-radius: 3px 0px 0px 3px; padding: 1px; font-size: 0.7rem',
'background: #009900; color: #fff; border-radius: 0px 3px 3px 0px; padding: 1px; font-size: 0.7rem'
);
}
};
// Adapted from webview - thanks zserge!
function injectCSS(css) {
var elem = document.createElement("style");
elem.setAttribute("type", "text/css");
if (elem.styleSheet) {
elem.styleSheet.cssText = css;
} else {
elem.appendChild(document.createTextNode(css));
}
var head = document.head || document.getElementsByTagName("head")[0];
head.appendChild(elem);
var elem = document.createElement('style');
elem.setAttribute('type', 'text/css');
if (elem.styleSheet) {
elem.styleSheet.cssText = css;
} else {
elem.appendChild(document.createTextNode(css));
}
var head = document.head || document.getElementsByTagName('head')[0];
head.appendChild(elem);
}
// Creates a node in the Dom
function createNode(parent, elementType, id, className, content) {
var d = document.createElement(elementType);
if (id) {
d.id = id;
}
if (className) {
d.className = className;
}
if (content) {
d.innerHTML = content;
}
parent.appendChild(d);
return d;
var d = document.createElement(elementType);
if (id) {
d.id = id;
}
if (className) {
d.className = className;
}
if (content) {
d.innerHTML = content;
}
parent.appendChild(d);
return d;
}
// Sets up the overlay
function setupOverlay() {
var body = document.body;
var wailsBridgeNode = createNode(body, "div", "wails-bridge");
wailsBridgeNode.innerHTML = window.wailsbridge.overlayHTML;
var body = document.body;
var wailsBridgeNode = createNode(body, 'div', 'wails-bridge');
wailsBridgeNode.innerHTML = window.wailsbridge.overlayHTML;
// Inject the overlay CSS
injectCSS(window.wailsbridge.overlayCSS);
// Inject the overlay CSS
injectCSS(window.wailsbridge.overlayCSS);
}
// Start the Wails Bridge
function startBridge() {
// Setup the overlay
setupOverlay();
// Setup the overlay
setupOverlay();
window.wailsbridge.websocket = null;
window.wailsbridge.connectTimer = null;
window.wailsbridge.reconnectOverlay = document.querySelector(
".wails-reconnect-overlay"
);
window.wailsbridge.connectionState = "disconnected";
window.wailsbridge.websocket = null;
window.wailsbridge.connectTimer = null;
window.wailsbridge.reconnectOverlay = document.querySelector(
'.wails-reconnect-overlay'
);
window.wailsbridge.connectionState = 'disconnected';
// Shows the overlay
function showReconnectOverlay() {
window.wailsbridge.reconnectOverlay.style.display = "block";
}
// Shows the overlay
function showReconnectOverlay() {
window.wailsbridge.reconnectOverlay.style.display = 'block';
}
// Hides the overlay
function hideReconnectOverlay() {
window.wailsbridge.reconnectOverlay.style.display = "none";
}
// Hides the overlay
function hideReconnectOverlay() {
window.wailsbridge.reconnectOverlay.style.display = 'none';
}
// Bridge external.invoke
window.external = {
invoke: function (msg) {
window.wailsbridge.websocket.send(msg);
}
};
// Bridge external.invoke
window.external = {
invoke: function (msg) {
window.wailsbridge.websocket.send(msg);
}
};
// Adds a script to the Dom.
// Removes it if second parameter is true.
function addScript(script, remove) {
var s = document.createElement("script");
s.setAttribute('type', 'text/javascript');
s.textContent = script;
document.head.appendChild(s);
// Adds a script to the Dom.
// Removes it if second parameter is true.
function addScript(script, remove) {
var s = document.createElement('script');
s.setAttribute('type', 'text/javascript');
s.textContent = script;
document.head.appendChild(s);
// Remove internal messages from the DOM
if (remove) {
s.parentNode.removeChild(s);
}
}
// Remove internal messages from the DOM
if (remove) {
s.parentNode.removeChild(s);
}
}
// Handles incoming websocket connections
function handleConnect() {
window.wailsbridge.log("Connected to backend");
hideReconnectOverlay();
clearInterval(window.wailsbridge.connectTimer);
window.wailsbridge.websocket.onclose = handleDisconnect;
window.wailsbridge.websocket.onmessage = handleMessage;
window.wailsbridge.connectionState = "connected";
}
// Handles incoming websocket connections
function handleConnect() {
window.wailsbridge.log('Connected to backend');
hideReconnectOverlay();
clearInterval(window.wailsbridge.connectTimer);
window.wailsbridge.websocket.onclose = handleDisconnect;
window.wailsbridge.websocket.onmessage = handleMessage;
window.wailsbridge.connectionState = 'connected';
}
// Handles websocket disconnects
function handleDisconnect() {
window.wailsbridge.log("Disconnected from backend");
window.wailsbridge.websocket = null;
window.wailsbridge.connectionState = "disconnected";
showReconnectOverlay();
connect();
}
// Handles websocket disconnects
function handleDisconnect() {
window.wailsbridge.log('Disconnected from backend');
window.wailsbridge.websocket = null;
window.wailsbridge.connectionState = 'disconnected';
showReconnectOverlay();
connect();
}
// Try to connect to the backend every 300ms (default value).
// Change this value in the main wailsbridge object.
function connect() {
window.wailsbridge.connectTimer = setInterval(function () {
if (window.wailsbridge.websocket == null) {
window.wailsbridge.websocket = new WebSocket(window.wailsbridge.wsURL);
window.wailsbridge.websocket.onopen = handleConnect;
window.wailsbridge.websocket.onerror = function (e) {
e.stopImmediatePropagation();
e.stopPropagation();
e.preventDefault();
window.wailsbridge.websocket = null;
return false;
};
}
}, window.wailsbridge.reconnectTimer);
}
// Try to connect to the backend every 300ms (default value).
// Change this value in the main wailsbridge object.
function connect() {
window.wailsbridge.connectTimer = setInterval(function () {
if (window.wailsbridge.websocket == null) {
window.wailsbridge.websocket = new WebSocket(window.wailsbridge.wsURL);
window.wailsbridge.websocket.onopen = handleConnect;
window.wailsbridge.websocket.onerror = function (e) {
e.stopImmediatePropagation();
e.stopPropagation();
e.preventDefault();
window.wailsbridge.websocket = null;
return false;
};
}
}, window.wailsbridge.reconnectTimer);
}
function handleMessage(message) {
// As a bridge we ignore js and css injections
switch (message.data[0]) {
// Wails library - inject!
case "w":
addScript(message.data.slice(1));
function handleMessage(message) {
// As a bridge we ignore js and css injections
switch (message.data[0]) {
// Wails library - inject!
case 'w':
addScript(message.data.slice(1));
// Now wails runtime is loaded, wails for the ready event
// and callback to the main app
window.wails.Events.On("wails:loaded", function () {
window.wailsbridge.log("Wails Ready");
if (window.wailsbridge.callback) {
window.wailsbridge.log("Notifying application");
window.wailsbridge.callback(window.wails);
}
});
window.wailsbridge.log("Loaded Wails Runtime");
break;
// Notifications
case "n":
addScript(message.data.slice(1), true);
break;
// Binding
case "b":
var binding = message.data.slice(1);
//log("Binding: " + binding)
window.wails._.newBinding(binding);
break;
// Call back
case "c":
var callbackData = message.data.slice(1);
window.wails._.callback(callbackData);
break;
default:
window.wails.Log.Error("Unknown message type received: " + message.data[0])
}
}
// Now wails runtime is loaded, wails for the ready event
// and callback to the main app
window.wails.Events.On('wails:loaded', function () {
window.wailsbridge.log('Wails Ready');
if (window.wailsbridge.callback) {
window.wailsbridge.log('Notifying application');
window.wailsbridge.callback(window.wails);
}
});
window.wailsbridge.log('Loaded Wails Runtime');
break;
// Notifications
case 'n':
addScript(message.data.slice(1), true);
break;
// Binding
case 'b':
var binding = message.data.slice(1);
//log("Binding: " + binding)
window.wails._.newBinding(binding);
break;
// Call back
case 'c':
var callbackData = message.data.slice(1);
window.wails._.callback(callbackData);
break;
default:
window.wails.Log.Error('Unknown message type received: ' + message.data[0]);
}
}
// Start by showing the overlay...
showReconnectOverlay();
// Start by showing the overlay...
showReconnectOverlay();
// ...and attempt to connect
connect();
// ...and attempt to connect
connect();
}
export default {
// The main function
// Passes the main Wails object to the callback if given.
Start: function (callback) {
// Save the callback
window.wailsbridge.callback = callback;
// The main function
// Passes the main Wails object to the callback if given.
Start: function (callback) {
// Save the callback
window.wailsbridge.callback = callback;
// Start Bridge
startBridge();
}
// Start Bridge
startBridge();
}
};

View File

@@ -7,11 +7,11 @@
*/
export default {
// The main function
// Passes the main Wails object to the callback if given.
Start: function (callback) {
if (callback) {
window.wails.Events.On("wails:ready", callback);
}
}
// The main function
// Passes the main Wails object to the callback if given.
Start: function (callback) {
if (callback) {
window.wails.Events.On('wails:ready', callback);
}
}
};

View File

@@ -1 +1 @@
!function(){var e;function n(e){try{return new Function("var "+e),!0}catch(e){return!1}}window.wails=window.wails||{},window.backend={},e=window.crypto?function(){var e=new Uint32Array(1);return window.crypto.getRandomValues(e)[0]}:function(){return 9007199254740991*Math.random()};var t=window.backend;var a={};function r(n,t,r){return null!=r&&null!=r||(r=0),new Promise(function(i,o){var l;do{l=n+"-"+e()}while(a[l]);if(r>0)var c=setTimeout(function(){o(Error("Call to "+n+" timed out. Request ID: "+l))},r);a[l]={timeoutHandle:c,reject:o,resolve:i};try{var s=JSON.stringify(t);message={type:"call",callbackid:l,payload:{bindingName:n,data:s}};var u=JSON.stringify(message);external.invoke(u)}catch(e){console.error(e)}})}function i(e,n){return r(".wails."+e,n)}var o={};function l(e,n){o[e]=o[e]||[],o[e].push(n)}function c(e){var n=JSON.stringify([].slice.apply(arguments).slice(1));message={type:"event",payload:{name:e,data:n}},external.invoke(JSON.stringify(message))}function s(e,n){var t=n[0].toUpperCase()+n.substring(1);return function(a,r){return console.warn("Method events."+n+" has been deprecated. Please use Events."+t),e(a,r)}}function u(e,n){n={type:"log",payload:{level:e,message:n}},external.invoke(JSON.stringify(n))}function d(e,n){var t=n[0].toUpperCase()+n.substring(1);return function(a){return console.warn("Method Log."+n+" has been deprecated. Please use Log."+t),e(a)}}function w(e){u("debug",e)}function f(e){u("info",e)}function g(e){u("warning",e)}function p(e){u("error",e)}function v(e){u("fatal",e)}window.wails.events={emit:s(c,"emit"),on:s(l,"on")},window.wails.Events={Emit:c,On:l},window.wails.Browser={OpenURL:function(e){return i("Browser.OpenURL",e)},OpenFile:function(e){return i("Browser.OpenFile",e)}},window.wails.log={debug:d(w,"debug"),info:d(f,"info"),warning:d(g,"warning"),error:d(p,"error"),fatal:d(v,"fatal")},window.wails.Log={Debug:w,Info:f,Warning:g,Error:p,Fatal:v},window.wails._={newBinding:function(e){var a,i=e.split(".").splice(1),o=i.pop(),l=function(e){var a=t;for(var r in e){var i=e[r];if(!n(i))return[null,new Error(i+" is not a valid javascript identifier.")];a[i]||(a[i]={}),a=a[i]}return[a,null]}(i),c=l[0];if(null!=(a=l[1]))return a;c[o]=function(){var n=0;function t(){var t=[].slice.call(arguments);return r(e,t,n)}return t.setTimeout=function(e){n=e},t.getTimeout=function(){return n},t}()},callback:function(e){var n;e=decodeURIComponent(e.replace(/\s+/g,"").replace(/[0-9a-f]{2}/g,"%$&"));try{n=JSON.parse(e)}catch(n){return wails.Log.Debug("Invalid JSON passed to callback: "+n.message),void wails.Log.Debug("Message: "+e)}if(callbackID=n.callbackid,callbackData=a[callbackID],callbackData)return clearTimeout(callbackData.timeoutHandle),delete a[callbackID],n.error?callbackData.reject(n.error):callbackData.resolve(n.data);console.error("Callback '"+callbackID+"' not registed!!!")},notify:function(e,n){o[e]&&o[e].forEach(function(t){var a=[];if(n)try{a=JSON.parse(n)}catch(n){wails.Log.Error("Invalid JSON data sent to notify. Event name = "+e)}t.apply(null,a)})},sendLogMessage:u,callbacks:a,injectCSS:function(e){var n=document.createElement("style");n.setAttribute("type","text/css"),n.styleSheet?n.styleSheet.cssText=e:n.appendChild(document.createTextNode(e)),(document.head||document.getElementsByTagName("head")[0]).appendChild(n)},addScript:function(e,n){var t=document.createElement("script");t.text=e,document.body.appendChild(t),window.wails.Events.Emit(n)}},window.wails.Events.Emit("wails:loaded")}();
!function(){var e;function n(e){try{return new Function("var "+e),!0}catch(e){return!1}}window.wails=window.wails||{},window.backend={},e=window.crypto?function(){var e=new Uint32Array(1);return window.crypto.getRandomValues(e)[0]}:function(){return 9007199254740991*Math.random()};var t=window.backend;var r={};function i(n,t,i){return null!=i&&null!=i||(i=0),new Promise(function(a,o){var l;do{l=n+"-"+e()}while(r[l]);if(i>0)var c=setTimeout(function(){o(Error("Call to "+n+" timed out. Request ID: "+l))},i);r[l]={timeoutHandle:c,reject:o,resolve:a};try{var s=JSON.stringify(t),u={type:"call",callbackid:l,payload:{bindingName:n,data:s}},d=JSON.stringify(u);external.invoke(d)}catch(e){console.error(e)}})}function a(e,n){return i(".wails."+e,n)}var o={};function l(e,n){o[e]=o[e]||[],o[e].push(n)}function c(e){var n={type:"event",payload:{name:e,data:JSON.stringify([].slice.apply(arguments).slice(1))}};external.invoke(JSON.stringify(n))}function s(e,n){var t=n[0].toUpperCase()+n.substring(1);return function(r,i){return console.warn("Method events."+n+" has been deprecated. Please use Events."+t),e(r,i)}}function u(e,n){n={type:"log",payload:{level:e,message:n}},external.invoke(JSON.stringify(n))}function d(e,n){var t=n[0].toUpperCase()+n.substring(1);return function(r){return console.warn("Method Log."+n+" has been deprecated. Please use Log."+t),e(r)}}function w(e){u("debug",e)}function f(e){u("info",e)}function p(e){u("warning",e)}function v(e){u("error",e)}function g(e){u("fatal",e)}window.wails.events={emit:s(c,"emit"),on:s(l,"on")},window.wails.Events={Emit:c,On:l},window.wails.Browser={OpenURL:function(e){return a("Browser.OpenURL",e)},OpenFile:function(e){return a("Browser.OpenFile",e)}},window.wails.log={debug:d(w,"debug"),info:d(f,"info"),warning:d(p,"warning"),error:d(v,"error"),fatal:d(g,"fatal")},window.wails.Log={Debug:w,Info:f,Warning:p,Error:v,Fatal:g},window.wails._={newBinding:function(e){var r=e.split(".").splice(1),a=r.pop(),o=function(e){var r=t;for(var i in e){var a=e[i];if(!n(a))return[null,new Error(a+" is not a valid javascript identifier.")];r[a]||(r[a]={}),r=r[a]}return[r,null]}(r),l=o[0],c=o[1];if(null!=c)return c;l[a]=function(){var n=0;function t(){var t=[].slice.call(arguments);return i(e,t,n)}return t.setTimeout=function(e){n=e},t.getTimeout=function(){return n},t}()},callback:function(e){var n;e=decodeURIComponent(e.replace(/\s+/g,"").replace(/[0-9a-f]{2}/g,"%$&"));try{n=JSON.parse(e)}catch(n){return window.wails.Log.Debug("Invalid JSON passed to callback: "+n.message),void window.wails.Log.Debug("Message: "+e)}var t=n.callbackid,i=r[t];if(i)return clearTimeout(i.timeoutHandle),delete r[t],n.error?i.reject(n.error):i.resolve(n.data);console.error("Callback '"+t+"' not registed!!!")},notify:function(e,n){o[e]&&o[e].forEach(function(t){var r=[];if(n)try{r=JSON.parse(n)}catch(n){window.wails.Log.Error("Invalid JSON data sent to notify. Event name = "+e)}t.apply(null,r)})},sendLogMessage:u,callbacks:r,injectCSS:function(e){var n=document.createElement("style");n.setAttribute("type","text/css"),n.styleSheet?n.styleSheet.cssText=e:n.appendChild(document.createTextNode(e)),(document.head||document.getElementsByTagName("head")[0]).appendChild(n)},addScript:function(e,n){var t=document.createElement("script");t.text=e,document.body.appendChild(t),window.wails.Events.Emit(n)}},window.wails.Events.Emit("wails:loaded")}();

View File

@@ -31,7 +31,7 @@
function isValidIdentifier(name) {
// Don't xss yourself :-)
try {
new Function("var " + name);
new Function('var ' + name);
return true;
} catch (e) {
return false;
@@ -40,7 +40,7 @@
// -------------- JS ----------------
function addScript(js, callbackID) {
var script = document.createElement("script");
var script = document.createElement('script');
script.text = js;
document.body.appendChild(script);
window.wails.Events.Emit(callbackID);
@@ -75,7 +75,7 @@
// Is section a valid javascript identifier?
if (!isValidIdentifier(section)) {
var errMessage = section + " is not a valid javascript identifier.";
var errMessage = section + ' is not a valid javascript identifier.';
var err = new Error(errMessage);
return [null, err];
}
@@ -98,9 +98,6 @@
// Get the actual function/method call name
var callName = bindingSections.pop();
var pathToBinding;
var err;
// Add path to binding
var bs = addBindingPath(bindingSections);
var pathToBinding = bs[0];
@@ -126,12 +123,12 @@
// Allow setting timeout to function
dynamic.setTimeout = function (newTimeout) {
timeout = newTimeout;
}
};
// Allow getting timeout to function
dynamic.getTimeout = function () {
return timeout;
}
};
return dynamic;
}();
@@ -163,13 +160,13 @@
// Create a unique callbackID
var callbackID;
do {
callbackID = bindingName + "-" + randomFunc();
callbackID = bindingName + '-' + randomFunc();
} while (callbacks[callbackID]);
// Set timeout
if (timeout > 0) {
var timeoutHandle = setTimeout(function () {
reject(Error("Call to " + bindingName + " timed out. Request ID: " + callbackID));
reject(Error('Call to ' + bindingName + ' timed out. Request ID: ' + callbackID));
}, timeout);
}
@@ -178,31 +175,32 @@
timeoutHandle: timeoutHandle,
reject: reject,
resolve: resolve
}
};
try {
var payloaddata = JSON.stringify(data);
// Create the message
message = {
type: "call",
var message = {
type: 'call',
callbackid: callbackID,
payload: {
bindingName: bindingName,
data: payloaddata,
}
}
};
// Make the call
var payload = JSON.stringify(message);
external.invoke(payload);
} catch (e) {
// eslint-disable-next-line
console.error(e);
}
})
});
}
// systemCall is used to call wails methods from the frontend
function systemCall(method, data) {
return call(".wails." + method, data);
return call('.wails.' + method, data);
}
// Called by the backend to return data to a previously called
@@ -217,15 +215,16 @@
try {
message = JSON.parse(incomingMessage);
} catch (e) {
wails.Log.Debug("Invalid JSON passed to callback: " + e.message);
wails.Log.Debug("Message: " + incomingMessage);
window.wails.Log.Debug('Invalid JSON passed to callback: ' + e.message);
window.wails.Log.Debug('Message: ' + incomingMessage);
return;
}
callbackID = message.callbackid;
callbackData = callbacks[callbackID];
var callbackID = message.callbackid;
var callbackData = callbacks[callbackID];
if (!callbackData) {
console.error("Callback '" + callbackID + "' not registed!!!");
return
// eslint-disable-next-line
console.error('Callback \'' + callbackID + '\' not registed!!!');
return;
}
clearTimeout(callbackData.timeoutHandle);
delete callbacks[callbackID];
@@ -259,7 +258,7 @@
try {
parsedData = JSON.parse(data);
} catch (e) {
wails.Log.Error("Invalid JSON data sent to notify. Event name = " + eventName);
window.wails.Log.Error('Invalid JSON data sent to notify. Event name = ' + eventName);
}
}
element.apply(null, parsedData);
@@ -274,19 +273,20 @@
var data = JSON.stringify([].slice.apply(arguments).slice(1));
// Notify backend
message = {
type: "event",
var message = {
type: 'event',
payload: {
name: eventName,
data: data,
}
}
};
external.invoke(JSON.stringify(message));
}
function deprecatedEventsFunction(fn, oldName) {
var newName = oldName[0].toUpperCase() + oldName.substring(1);
return function (eventName, eventData) {
// eslint-disable-next-line
console.warn('Method events.' + oldName + ' has been deprecated. Please use Events.' + newName);
return fn(eventName, eventData);
};
@@ -312,11 +312,11 @@
function OpenURL(url) {
return systemCall("Browser.OpenURL", url);
return systemCall('Browser.OpenURL', url);
}
function OpenFile(filename) {
return systemCall("Browser.OpenFile", filename);
return systemCall('Browser.OpenFile', filename);
}
window.wails.Browser = {
@@ -332,37 +332,38 @@
// Log Message
message = {
type: "log",
type: 'log',
payload: {
level: level,
message: message,
}
}
};
external.invoke(JSON.stringify(message));
}
function deprecatedLogFunction(fn, oldName) {
var newName = oldName[0].toUpperCase() + oldName.substring(1);
return function (message) {
// eslint-disable-next-line
console.warn('Method Log.' + oldName + ' has been deprecated. Please use Log.' + newName);
return fn(message);
};
}
function logDebug(message) {
sendLogMessage("debug", message);
sendLogMessage('debug', message);
}
function logInfo(message) {
sendLogMessage("info", message);
sendLogMessage('info', message);
}
function logWarning(message) {
sendLogMessage("warning", message);
sendLogMessage('warning', message);
}
function logError(message) {
sendLogMessage("error", message);
sendLogMessage('error', message);
}
function logFatal(message) {
sendLogMessage("fatal", message);
sendLogMessage('fatal', message);
}
window.wails.log = {
@@ -398,6 +399,6 @@
/************************************************************/
// Notify backend that the runtime has finished loading
window.wails.Events.Emit("wails:loaded");
window.wails.Events.Emit('wails:loaded');
})()
})();