fix: capitalisation and binding fix

This commit is contained in:
Lea Anthony
2019-07-13 15:30:52 +10:00
parent a2af626477
commit 75a0b632bc
9 changed files with 45 additions and 60 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
+2 -2
View File
@@ -86,7 +86,7 @@ func (h *Headless) injectCSS(css string) {
minifiedCSS = strings.Replace(minifiedCSS, "\\", "\\\\", -1)
minifiedCSS = strings.Replace(minifiedCSS, "'", "\\'", -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)
}
@@ -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)
}
File diff suppressed because one or more lines are too long
+4 -4
View File
@@ -141,7 +141,7 @@ func (w *WebView) evalJSSync(js string) error {
wg.Done()
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.Eval(command)
})
@@ -226,7 +226,7 @@ func (w *WebView) Run() error {
// NewBinding registers a new binding with the frontend
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)
return nil
}
@@ -288,7 +288,7 @@ func (w *WebView) SelectSaveFile() string {
// Callback sends a callback to the frontend
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)
}
@@ -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)
}
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+23 -38
View File
@@ -10,7 +10,7 @@ The lightweight framework for web-like apps
import { Call } from './calls';
var bindingsBasePath = window.backend;
window.backend = {};
// Determines if the given identifier is valid Javascript
function isValidIdentifier(name) {
@@ -23,52 +23,37 @@ function isValidIdentifier(name) {
}
}
// Creates the path given in the bindings path
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];
}
// eslint-disable-next-line max-lines-per-function
export function NewBinding(bindingName) {
// 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
var callName = bindingSections.pop();
const name = bindingSections.pop();
// Add path to binding
var bs = addBindingPath(bindingSections);
var pathToBinding = bs[0];
var err = bs[1];
if (err != null) {
// We need to return an error
return err;
// Is name a valid javascript identifier?
if (!isValidIdentifier(name)) {
return new Error(`${name} is not a valid javascript identifier.`);
}
// Add binding call
pathToBinding[callName] = function () {
pathToBinding[name] = function () {
// No timeout by default
var timeout = 0;
+7 -7
View File
@@ -8,14 +8,13 @@ The lightweight framework for web-like apps
(c) Lea Anthony 2019-present
*/
// var Invoke = window.external.invoke;
var Invoke;
if (window && window.external && window.external.invoke) {
Invoke = window.external.invoke;
} else {
Invoke = console.log;
function Invoke(message) {
if (window && window.external && window.external.invoke) {
window.external.invoke(message);
} else {
console.log(`[No external.invoke] ${message}`);
}
}
export function SendMessage(type, payload, callbackID) {
@@ -24,5 +23,6 @@ export function SendMessage(type, payload, callbackID) {
callbackID,
payload
};
Invoke(JSON.stringify(message));
}
+1 -1
View File
@@ -29,7 +29,7 @@ var internal = {
// Setup runtime structure
var runtime = {
Log,
Event: {
Events: {
On,
Emit,
Heartbeat,