mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-03 18:13:20 +08:00
Merge pull request #129 from wailsapp/123-Unify-Runtime-APIs
feat: unify runtime API signatures
This commit is contained in:
commit
a84e2ae9b3
File diff suppressed because one or more lines are too long
@ -9,9 +9,9 @@
|
||||
export default {
|
||||
// The main function
|
||||
// Passes the main Wails object to the callback if given.
|
||||
Start: function(callback) {
|
||||
Start: function (callback) {
|
||||
if (callback) {
|
||||
window.wails.events.on("wails:ready", callback);
|
||||
window.wails.Events.On("wails:ready", callback);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -9,9 +9,9 @@
|
||||
export default {
|
||||
// The main function
|
||||
// Passes the main Wails object to the callback if given.
|
||||
Start: function(callback) {
|
||||
Start: function (callback) {
|
||||
if (callback) {
|
||||
window.wails.events.on("wails:ready", callback);
|
||||
window.wails.Events.On("wails:ready", callback);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
File diff suppressed because one or more lines are too long
@ -167,7 +167,7 @@ function startBridge() {
|
||||
|
||||
// Now wails runtime is loaded, wails for the ready event
|
||||
// and callback to the main app
|
||||
window.wails.events.on("wails:loaded", function () {
|
||||
window.wails.Events.On("wails:loaded", function () {
|
||||
window.wailsbridge.log("Wails Ready");
|
||||
if (window.wailsbridge.callback) {
|
||||
window.wailsbridge.log("Notifying application");
|
||||
|
@ -9,9 +9,9 @@
|
||||
export default {
|
||||
// The main function
|
||||
// Passes the main Wails object to the callback if given.
|
||||
Start: function(callback) {
|
||||
Start: function (callback) {
|
||||
if (callback) {
|
||||
window.wails.events.on("wails:ready", callback);
|
||||
window.wails.Events.On("wails:ready", callback);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
2
wailsruntimeassets/default/wails.min.js
vendored
2
wailsruntimeassets/default/wails.min.js
vendored
@ -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 a=window.backend;var t={};function r(n,a,r){return null!=r&&null!=r||(r=0),new Promise(function(i,o){var l;do{l=n+"-"+e()}while(t[l]);if(r>0)var c=setTimeout(function(){o(Error("Call to "+n+" timed out. Request ID: "+l))},r);t[l]={timeoutHandle:c,reject:o,resolve:i};try{var s=JSON.stringify(a);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){n={type:"log",payload:{level:e,message:n}},external.invoke(JSON.stringify(n))}window.wails.events={emit:function(e){var n=JSON.stringify([].slice.apply(arguments).slice(1));message={type:"event",payload:{name:e,data:n}},external.invoke(JSON.stringify(message))},on:function(e,n){o[e]=o[e]||[],o[e].push(n)}},window.wails.Browser={OpenURL:function(e){return i("Browser.OpenURL",e)},OpenFile:function(e){return i("Browser.OpenFile",e)}},window.wails.log={debug:function(e){l("debug",e)},info:function(e){l("info",e)},warning:function(e){l("warning",e)},error:function(e){l("error",e)},fatal:function(e){l("fatal",e)}},window.wails._={newBinding:function(e){var t,i=e.split(".").splice(1),o=i.pop(),l=function(e){var t=a;for(var r in e){var i=e[r];if(!n(i))return[null,new Error(i+" is not a valid javascript identifier.")];t[i]||(t[i]={}),t=t[i]}return[t,null]}(i),c=l[0];if(null!=(t=l[1]))return t;c[o]=function(){var n=0;function a(){var a=[].slice.call(arguments);return r(e,a,n)}return a.setTimeout=function(e){n=e},a.getTimeout=function(){return n},a}()},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=t[callbackID],callbackData)return clearTimeout(callbackData.timeoutHandle),delete t[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(a){var t=[];if(n)try{t=JSON.parse(n)}catch(n){wails.log.error("Invalid JSON data sent to notify. Event name = "+e)}a.apply(null,t)})},sendLogMessage:l,callbacks:t,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 a=document.createElement("script");a.text=e,document.body.appendChild(a),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 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")}();
|
@ -43,7 +43,7 @@
|
||||
var script = document.createElement("script");
|
||||
script.text = js;
|
||||
document.body.appendChild(script);
|
||||
window.wails.events.emit(callbackID);
|
||||
window.wails.Events.Emit(callbackID);
|
||||
}
|
||||
|
||||
// -------------- CSS ---------------
|
||||
@ -217,8 +217,8 @@
|
||||
try {
|
||||
message = JSON.parse(incomingMessage);
|
||||
} catch (e) {
|
||||
wails.log.debug("Invalid JSON passed to callback: " + e.message);
|
||||
wails.log.debug("Message: " + incomingMessage);
|
||||
wails.Log.Debug("Invalid JSON passed to callback: " + e.message);
|
||||
wails.Log.Debug("Message: " + incomingMessage);
|
||||
return;
|
||||
}
|
||||
callbackID = message.callbackid;
|
||||
@ -259,7 +259,7 @@
|
||||
try {
|
||||
parsedData = JSON.parse(data);
|
||||
} catch (e) {
|
||||
wails.log.error("Invalid JSON data sent to notify. Event name = " + eventName)
|
||||
wails.Log.Error("Invalid JSON data sent to notify. Event name = " + eventName)
|
||||
}
|
||||
}
|
||||
element.apply(null, parsedData);
|
||||
@ -284,8 +284,26 @@
|
||||
external.invoke(JSON.stringify(message));
|
||||
}
|
||||
|
||||
function deprecatedEventsFunction(fn, oldName) {
|
||||
var newName = oldName[0].toUpperCase() + oldName.substring(1);
|
||||
return function (eventName, eventData) {
|
||||
console.warn('Method events.' + oldName + ' has been deprecated. Please use Events.' + newName);
|
||||
return fn(eventName, eventData);
|
||||
}
|
||||
}
|
||||
|
||||
// Deprecated Events calls
|
||||
window.wails.events = {
|
||||
emit: deprecatedEventsFunction(emit, 'emit'),
|
||||
on: deprecatedEventsFunction(on, 'on'),
|
||||
};
|
||||
|
||||
// Events calls
|
||||
window.wails.events = { emit: emit, on: on };
|
||||
window.wails.Events = {
|
||||
Emit: emit,
|
||||
On: on
|
||||
};
|
||||
|
||||
|
||||
|
||||
/************************************************************/
|
||||
@ -323,6 +341,14 @@
|
||||
external.invoke(JSON.stringify(message));
|
||||
}
|
||||
|
||||
function deprecatedLogFunction(fn, oldName) {
|
||||
var newName = oldName[0].toUpperCase() + oldName.substring(1);
|
||||
return function (message) {
|
||||
console.warn('Method Log.' + oldName + ' has been deprecated. Please use Log.' + newName);
|
||||
return fn(message);
|
||||
}
|
||||
}
|
||||
|
||||
function logDebug(message) {
|
||||
sendLogMessage("debug", message);
|
||||
}
|
||||
@ -340,13 +366,22 @@
|
||||
}
|
||||
|
||||
window.wails.log = {
|
||||
debug: logDebug,
|
||||
info: logInfo,
|
||||
warning: logWarning,
|
||||
error: logError,
|
||||
fatal: logFatal,
|
||||
debug: deprecatedLogFunction(logDebug, 'debug'),
|
||||
info: deprecatedLogFunction(logInfo, 'info'),
|
||||
warning: deprecatedLogFunction(logWarning, 'warning'),
|
||||
error: deprecatedLogFunction(logError, 'error'),
|
||||
fatal: deprecatedLogFunction(logFatal, 'fatal'),
|
||||
};
|
||||
|
||||
window.wails.Log = {
|
||||
Debug: logDebug,
|
||||
Info: logInfo,
|
||||
Warning: logWarning,
|
||||
Error: logError,
|
||||
Fatal: logFatal,
|
||||
};
|
||||
|
||||
|
||||
/************************** Exports *************************/
|
||||
|
||||
window.wails._ = {
|
||||
@ -357,12 +392,12 @@
|
||||
callbacks: callbacks,
|
||||
injectCSS: injectCSS,
|
||||
addScript: addScript,
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/************************************************************/
|
||||
|
||||
// Notify backend that the runtime has finished loading
|
||||
window.wails.events.emit("wails:loaded");
|
||||
window.wails.Events.Emit("wails:loaded");
|
||||
|
||||
})()
|
Loading…
Reference in New Issue
Block a user