mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-04 04:11:56 +08:00
fix: capitalisation and binding fix
This commit is contained in:
parent
a2af626477
commit
75a0b632bc
File diff suppressed because one or more lines are too long
@ -86,7 +86,7 @@ func (h *Headless) injectCSS(css string) {
|
|||||||
minifiedCSS = strings.Replace(minifiedCSS, "\\", "\\\\", -1)
|
minifiedCSS = strings.Replace(minifiedCSS, "\\", "\\\\", -1)
|
||||||
minifiedCSS = strings.Replace(minifiedCSS, "'", "\\'", -1)
|
minifiedCSS = strings.Replace(minifiedCSS, "'", "\\'", -1)
|
||||||
minifiedCSS = strings.Replace(minifiedCSS, "\n", " ", -1)
|
minifiedCSS = strings.Replace(minifiedCSS, "\n", " ", -1)
|
||||||
inject := fmt.Sprintf("wails._.injectCSS('%s')", minifiedCSS)
|
inject := fmt.Sprintf("wails._.InjectCSS('%s')", minifiedCSS)
|
||||||
h.evalJS(inject, cssMessage)
|
h.evalJS(inject, cssMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,7 +218,7 @@ func (h *Headless) NotifyEvent(event *messages.EventData) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
message := fmt.Sprintf("window.wails._.notify('%s','%s')", event.Name, data)
|
message := fmt.Sprintf("window.wails._.Notify('%s','%s')", event.Name, data)
|
||||||
return h.evalJS(message, notifyMessage)
|
return h.evalJS(message, notifyMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File diff suppressed because one or more lines are too long
@ -141,7 +141,7 @@ func (w *WebView) evalJSSync(js string) error {
|
|||||||
wg.Done()
|
wg.Done()
|
||||||
exit = true
|
exit = true
|
||||||
})
|
})
|
||||||
command := fmt.Sprintf("wails._.addScript('%s', '%s')", minified, ID)
|
command := fmt.Sprintf("wails._.AddScript('%s', '%s')", minified, ID)
|
||||||
w.window.Dispatch(func() {
|
w.window.Dispatch(func() {
|
||||||
w.window.Eval(command)
|
w.window.Eval(command)
|
||||||
})
|
})
|
||||||
@ -226,7 +226,7 @@ func (w *WebView) Run() error {
|
|||||||
|
|
||||||
// NewBinding registers a new binding with the frontend
|
// NewBinding registers a new binding with the frontend
|
||||||
func (w *WebView) NewBinding(methodName string) error {
|
func (w *WebView) NewBinding(methodName string) error {
|
||||||
objectCode := fmt.Sprintf("window.wails._.newBinding('%s');", methodName)
|
objectCode := fmt.Sprintf("window.wails._.NewBinding('%s');", methodName)
|
||||||
w.bindingCache = append(w.bindingCache, objectCode)
|
w.bindingCache = append(w.bindingCache, objectCode)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -288,7 +288,7 @@ func (w *WebView) SelectSaveFile() string {
|
|||||||
|
|
||||||
// Callback sends a callback to the frontend
|
// Callback sends a callback to the frontend
|
||||||
func (w *WebView) Callback(data string) error {
|
func (w *WebView) Callback(data string) error {
|
||||||
callbackCMD := fmt.Sprintf("window.wails._.callback('%s');", data)
|
callbackCMD := fmt.Sprintf("window.wails._.Callback('%s');", data)
|
||||||
return w.evalJS(callbackCMD)
|
return w.evalJS(callbackCMD)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -316,7 +316,7 @@ func (w *WebView) NotifyEvent(event *messages.EventData) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
message := fmt.Sprintf("wails._.notify('%s','%s')", event.Name, data)
|
message := fmt.Sprintf("wails._.Notify('%s','%s')", event.Name, data)
|
||||||
return w.evalJS(message)
|
return w.evalJS(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,12 +184,12 @@ function startBridge() {
|
|||||||
case 'b':
|
case 'b':
|
||||||
var binding = message.data.slice(1);
|
var binding = message.data.slice(1);
|
||||||
//log("Binding: " + binding)
|
//log("Binding: " + binding)
|
||||||
window.wails._.newBinding(binding);
|
window.wails._.NewBinding(binding);
|
||||||
break;
|
break;
|
||||||
// Call back
|
// Call back
|
||||||
case 'c':
|
case 'c':
|
||||||
var callbackData = message.data.slice(1);
|
var callbackData = message.data.slice(1);
|
||||||
window.wails._.callback(callbackData);
|
window.wails._.Callback(callbackData);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
window.wails.Log.Error('Unknown message type received: ' + message.data[0]);
|
window.wails.Log.Error('Unknown message type received: ' + message.data[0]);
|
||||||
|
2
runtime/js/dist/wails.js
vendored
2
runtime/js/dist/wails.js
vendored
@ -1 +1 @@
|
|||||||
!function(n){var e={};function t(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return n[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}t.m=n,t.c=e,t.d=function(n,e,r){t.o(n,e)||Object.defineProperty(n,e,{enumerable:!0,get:r})},t.r=function(n){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})},t.t=function(n,e){if(1&e&&(n=t(n)),8&e)return n;if(4&e&&"object"==typeof n&&n&&n.__esModule)return n;var r=Object.create(null);if(t.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:n}),2&e&&"string"!=typeof n)for(var o in n)t.d(r,o,function(e){return n[e]}.bind(null,o));return r},t.n=function(n){var e=n&&n.__esModule?function(){return n.default}:function(){return n};return t.d(e,"a",e),e},t.o=function(n,e){return Object.prototype.hasOwnProperty.call(n,e)},t.p="",t(t.s=0)}([function(n,e,t){"use strict";t.r(e);var r={};t.r(r),t.d(r,"Debug",function(){return c}),t.d(r,"Info",function(){return u}),t.d(r,"Warning",function(){return l}),t.d(r,"Error",function(){return f}),t.d(r,"Fatal",function(){return d});var o=window&&window.external&&window.external.invoke?window.external.invoke:console.log;function a(n,e,t){o(JSON.stringify({type:n,callbackID:t,payload:e}))}function i(n,e){a("log",{level:n,message:e})}function c(n){i("debug",n)}function u(n){i("info",n)}function l(n){i("warning",n)}function f(n){i("error",n)}function d(n){i("fatal",n)}var s=function n(e,t){(function(n,e){if(!(n instanceof e))throw new TypeError("Cannot call a class as a function")})(this,n),t=t||-1,this.Callback=function(n){return e.apply(null,n),-1!==t&&0===(t-=1)}},v={};function p(n,e,t){v[n]=v[n]||[];var r=new s(e,t);v[n].push(r)}function w(n){a("event",{name:n,data:JSON.stringify([].slice.apply(arguments).slice(1))})}var y={};var g={};var m=window.crypto?function(){var n=new Uint32Array(1);return window.crypto.getRandomValues(n)[0]}:function(){return 9007199254740991*Math.random()};function b(n,e,t){return(null==t||null==t)&&(t=0),new Promise(function(r,o){var i;do{i=n+"-"+m()}while(g[i]);if(0<t)var c=setTimeout(function(){o(Error("Call to "+n+" timed out. Request ID: "+i))},t);g[i]={timeoutHandle:c,reject:o,resolve:r};try{a("call",{bindingName:n,data:JSON.stringify(e)},i)}catch(n){console.error(n)}})}var h=window.backend;function O(n){try{return new Function("var "+n),!0}catch(n){return!1}}function S(){return(S=Object.assign||function(n){for(var e,t=1;t<arguments.length;t++)for(var r in e=arguments[t])Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}).apply(this,arguments)}window.wails=window.wails||{},window.backend={};var k={NewBinding:function(n){var e=n.split(".").splice(1),t=e.pop(),r=function(n){var e=h;for(var t in n){var r=n[t];if(!O(r))return[null,new Error(r+" is not a valid javascript identifier.")];e[r]||(e[r]={}),e=e[r]}return[e,null]}(e),o=r[0],a=r[1];return null==a?void(o[t]=function(){function e(){var e=[].slice.call(arguments);return b(n,e,t)}var t=0;return e.setTimeout=function(n){t=n},e.getTimeout=function(){return t},e}()):a},Callback:function(n){var e;n=decodeURIComponent(n.replace(/\s+/g,"").replace(/[0-9a-f]{2}/g,"%$&"));try{e=JSON.parse(n)}catch(e){return c("Invalid JSON passed to callback: "+e.message),void c("Message: "+n)}var t=e.callbackid,r=g[t];return r?(clearTimeout(r.timeoutHandle),delete g[t],e.error?r.reject(e.error):r.resolve(e.data)):void console.error("Callback '".concat(t,"' not registed!!!"))},Notify:function(n,e){if(v[n]){for(var t=v[n].slice(),r=0;r<v[n].length;r+=1){var o=v[n][r],a=[];if(e)try{a=JSON.parse(e)}catch(e){f("Invalid JSON data sent to notify. Event name = "+n)}o.Callback(a)&&t.splice(r,1)}v[n]=t}},AddScript:function(n,e){var t=document.createElement("script");t.text=n,document.body.appendChild(t),e&&w(e)},InjectCSS:function(n){var e=document.createElement("style");e.setAttribute("type","text/css"),e.styleSheet?e.styleSheet.cssText=n:e.appendChild(document.createTextNode(n)),(document.head||document.getElementsByTagName("head")[0]).appendChild(e)}},j={Log:r,Event:{On:function(n,e){p(n,e)},Emit:w,Heartbeat:function(n,e,t){var r=null;y[n]=function(){clearInterval(r),t()},r=setInterval(function(){w(n)},e)},Acknowledge:function(n){if(!y[n])throw new f("Cannot acknowledge unknown heartbeat '".concat(n,"'"));y[n]()}},_:k};S(window.wails,j),w("wails:loaded")}]);
|
!function(n){var e={};function t(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return n[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}t.m=n,t.c=e,t.d=function(n,e,r){t.o(n,e)||Object.defineProperty(n,e,{enumerable:!0,get:r})},t.r=function(n){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})},t.t=function(n,e){if(1&e&&(n=t(n)),8&e)return n;if(4&e&&"object"==typeof n&&n&&n.__esModule)return n;var r=Object.create(null);if(t.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:n}),2&e&&"string"!=typeof n)for(var o in n)t.d(r,o,function(e){return n[e]}.bind(null,o));return r},t.n=function(n){var e=n&&n.__esModule?function(){return n.default}:function(){return n};return t.d(e,"a",e),e},t.o=function(n,e){return Object.prototype.hasOwnProperty.call(n,e)},t.p="",t(t.s=0)}([function(n,e,t){"use strict";t.r(e);var r={};function o(n,e,t){!function(n){window&&window.external&&window.external.invoke?window.external.invoke(n):console.log("[No external.invoke] ".concat(n))}(JSON.stringify({type:n,callbackID:t,payload:e}))}function a(n,e){o("log",{level:n,message:e})}function i(n){a("debug",n)}function c(n){a("info",n)}function u(n){a("warning",n)}function l(n){a("error",n)}function f(n){a("fatal",n)}t.r(r),t.d(r,"Debug",function(){return i}),t.d(r,"Info",function(){return c}),t.d(r,"Warning",function(){return u}),t.d(r,"Error",function(){return l}),t.d(r,"Fatal",function(){return f});var d=function n(e,t){(function(n,e){if(!(n instanceof e))throw new TypeError("Cannot call a class as a function")})(this,n),t=t||-1,this.Callback=function(n){return e.apply(null,n),-1!==t&&0===(t-=1)}},s={};function p(n,e,t){s[n]=s[n]||[];var r=new d(e,t);s[n].push(r)}function v(n){o("event",{name:n,data:JSON.stringify([].slice.apply(arguments).slice(1))})}var w={};var y={};var g=window.crypto?function(){var n=new Uint32Array(1);return window.crypto.getRandomValues(n)[0]}:function(){return 9007199254740991*Math.random()};function m(n,e,t){return(null==t||null==t)&&(t=0),new Promise(function(r,a){var i;do{i=n+"-"+g()}while(y[i]);if(0<t)var c=setTimeout(function(){a(Error("Call to "+n+" timed out. Request ID: "+i))},t);y[i]={timeoutHandle:c,reject:a,resolve:r};try{o("call",{bindingName:n,data:JSON.stringify(e)},i)}catch(n){console.error(n)}})}function b(n){try{return new Function("var "+n),!0}catch(n){return!1}}function h(){return(h=Object.assign||function(n){for(var e,t=1;t<arguments.length;t++)for(var r in e=arguments[t])Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}).apply(this,arguments)}window.backend={},window.wails=window.wails||{},window.backend={};var O={NewBinding:function(n){var e=[].concat(n.split(".").splice(1)),t=window.backend;if(1<e.length)for(var r,o=0;o<e.length-1;o+=1){if(!b(r=e[o]))return new Error("".concat(r," is not a valid javascript identifier."));t[r]={},t=t[r]}var a=e.pop();return b(a)?void(t[a]=function(){function e(){var e=[].slice.call(arguments);return m(n,e,t)}var t=0;return e.setTimeout=function(n){t=n},e.getTimeout=function(){return t},e}()):new Error("".concat(a," is not a valid javascript identifier."))},Callback:function(n){var e;n=decodeURIComponent(n.replace(/\s+/g,"").replace(/[0-9a-f]{2}/g,"%$&"));try{e=JSON.parse(n)}catch(e){return i("Invalid JSON passed to callback: "+e.message),void i("Message: "+n)}var t=e.callbackid,r=y[t];return r?(clearTimeout(r.timeoutHandle),delete y[t],e.error?r.reject(e.error):r.resolve(e.data)):void console.error("Callback '".concat(t,"' not registed!!!"))},Notify:function(n,e){if(s[n]){for(var t=s[n].slice(),r=0;r<s[n].length;r+=1){var o=s[n][r],a=[];if(e)try{a=JSON.parse(e)}catch(e){l("Invalid JSON data sent to notify. Event name = "+n)}o.Callback(a)&&t.splice(r,1)}s[n]=t}},AddScript:function(n,e){var t=document.createElement("script");t.text=n,document.body.appendChild(t),e&&v(e)},InjectCSS:function(n){var e=document.createElement("style");e.setAttribute("type","text/css"),e.styleSheet?e.styleSheet.cssText=n:e.appendChild(document.createTextNode(n)),(document.head||document.getElementsByTagName("head")[0]).appendChild(e)}},S={Log:r,Events:{On:function(n,e){p(n,e)},Emit:v,Heartbeat:function(n,e,t){var r=null;w[n]=function(){clearInterval(r),t()},r=setInterval(function(){v(n)},e)},Acknowledge:function(n){if(!w[n])throw new l("Cannot acknowledge unknown heartbeat '".concat(n,"'"));w[n]()}},_:O};h(window.wails,S),v("wails:loaded")}]);
|
@ -10,7 +10,7 @@ The lightweight framework for web-like apps
|
|||||||
|
|
||||||
import { Call } from './calls';
|
import { Call } from './calls';
|
||||||
|
|
||||||
var bindingsBasePath = window.backend;
|
window.backend = {};
|
||||||
|
|
||||||
// Determines if the given identifier is valid Javascript
|
// Determines if the given identifier is valid Javascript
|
||||||
function isValidIdentifier(name) {
|
function isValidIdentifier(name) {
|
||||||
@ -23,52 +23,37 @@ function isValidIdentifier(name) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates the path given in the bindings path
|
// eslint-disable-next-line max-lines-per-function
|
||||||
function addBindingPath(pathSections) {
|
|
||||||
// Start at the base path
|
|
||||||
var currentPath = bindingsBasePath;
|
|
||||||
// for each section of the given path
|
|
||||||
for (var sectionIndex in pathSections) {
|
|
||||||
|
|
||||||
var section = pathSections[sectionIndex];
|
|
||||||
|
|
||||||
// Is section a valid javascript identifier?
|
|
||||||
if (!isValidIdentifier(section)) {
|
|
||||||
var errMessage = section + ' is not a valid javascript identifier.';
|
|
||||||
var err = new Error(errMessage);
|
|
||||||
return [null, err];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add if doesn't exist
|
|
||||||
if (!currentPath[section]) {
|
|
||||||
currentPath[section] = {};
|
|
||||||
}
|
|
||||||
// update current path to new path
|
|
||||||
currentPath = currentPath[section];
|
|
||||||
}
|
|
||||||
return [currentPath, null];
|
|
||||||
}
|
|
||||||
|
|
||||||
export function NewBinding(bindingName) {
|
export function NewBinding(bindingName) {
|
||||||
|
|
||||||
// Get all the sections of the binding
|
// Get all the sections of the binding
|
||||||
var bindingSections = bindingName.split('.').splice(1);
|
var bindingSections = [].concat(bindingName.split('.').splice(1));
|
||||||
|
var pathToBinding = window.backend;
|
||||||
|
|
||||||
|
// Check if we have a path (IE Struct)
|
||||||
|
if (bindingSections.length > 1) {
|
||||||
|
// Iterate over binding sections, adding them to the window.backend object
|
||||||
|
for (let index = 0; index < bindingSections.length - 1; index += 1) {
|
||||||
|
const name = bindingSections[index];
|
||||||
|
// Is name a valid javascript identifier?
|
||||||
|
if (!isValidIdentifier(name)) {
|
||||||
|
return new Error(`${name} is not a valid javascript identifier.`);
|
||||||
|
}
|
||||||
|
pathToBinding[name] = {};
|
||||||
|
pathToBinding = pathToBinding[name];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Get the actual function/method call name
|
// Get the actual function/method call name
|
||||||
var callName = bindingSections.pop();
|
const name = bindingSections.pop();
|
||||||
|
|
||||||
// Add path to binding
|
// Is name a valid javascript identifier?
|
||||||
var bs = addBindingPath(bindingSections);
|
if (!isValidIdentifier(name)) {
|
||||||
var pathToBinding = bs[0];
|
return new Error(`${name} is not a valid javascript identifier.`);
|
||||||
var err = bs[1];
|
|
||||||
|
|
||||||
if (err != null) {
|
|
||||||
// We need to return an error
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add binding call
|
// Add binding call
|
||||||
pathToBinding[callName] = function () {
|
pathToBinding[name] = function () {
|
||||||
|
|
||||||
// No timeout by default
|
// No timeout by default
|
||||||
var timeout = 0;
|
var timeout = 0;
|
||||||
|
@ -8,14 +8,13 @@ The lightweight framework for web-like apps
|
|||||||
(c) Lea Anthony 2019-present
|
(c) Lea Anthony 2019-present
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// var Invoke = window.external.invoke;
|
|
||||||
|
|
||||||
var Invoke;
|
|
||||||
|
|
||||||
|
function Invoke(message) {
|
||||||
if (window && window.external && window.external.invoke) {
|
if (window && window.external && window.external.invoke) {
|
||||||
Invoke = window.external.invoke;
|
window.external.invoke(message);
|
||||||
} else {
|
} else {
|
||||||
Invoke = console.log;
|
console.log(`[No external.invoke] ${message}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function SendMessage(type, payload, callbackID) {
|
export function SendMessage(type, payload, callbackID) {
|
||||||
@ -24,5 +23,6 @@ export function SendMessage(type, payload, callbackID) {
|
|||||||
callbackID,
|
callbackID,
|
||||||
payload
|
payload
|
||||||
};
|
};
|
||||||
|
|
||||||
Invoke(JSON.stringify(message));
|
Invoke(JSON.stringify(message));
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ var internal = {
|
|||||||
// Setup runtime structure
|
// Setup runtime structure
|
||||||
var runtime = {
|
var runtime = {
|
||||||
Log,
|
Log,
|
||||||
Event: {
|
Events: {
|
||||||
On,
|
On,
|
||||||
Emit,
|
Emit,
|
||||||
Heartbeat,
|
Heartbeat,
|
||||||
|
Loading…
Reference in New Issue
Block a user