mirror of
https://github.com/taigrr/wails.git
synced 2026-04-13 18:38:11 -07:00
Compare commits
8 Commits
v0.17.3-pr
...
runtime-re
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
24c7362163 | ||
|
|
f6ff7d7b16 | ||
|
|
b0a075cdf2 | ||
|
|
98d4d6b33c | ||
|
|
9ba3e0512b | ||
|
|
eff63175e5 | ||
|
|
75a0b632bc | ||
|
|
a2af626477 |
1
.eslintignore
Normal file
1
.eslintignore
Normal file
@@ -0,0 +1 @@
|
|||||||
|
runtime/js/dist/wails.js
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
module.exports = {
|
{
|
||||||
"env": {
|
"env": {
|
||||||
"browser": true,
|
"browser": true,
|
||||||
"es6": true
|
"es6": true
|
||||||
@@ -26,4 +26,4 @@ module.exports = {
|
|||||||
"always"
|
"always"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
6
.hound.yml
Normal file
6
.hound.yml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
jshint:
|
||||||
|
config_file: .jshintrc
|
||||||
|
eslint:
|
||||||
|
enabled: true
|
||||||
|
config_file: .eslintrc
|
||||||
|
ignore_file: .eslintignore
|
||||||
6
app.go
6
app.go
@@ -20,7 +20,7 @@ var BuildMode = cmd.BuildModeProd
|
|||||||
|
|
||||||
// App defines the main application struct
|
// App defines the main application struct
|
||||||
type App struct {
|
type App struct {
|
||||||
config *Config // The Application configuration object
|
config *AppConfig // The Application configuration object
|
||||||
cli *cmd.Cli // In debug mode, we have a cli
|
cli *cmd.Cli // In debug mode, we have a cli
|
||||||
renderer interfaces.Renderer // The renderer is what we will render the app to
|
renderer interfaces.Renderer // The renderer is what we will render the app to
|
||||||
logLevel string // The log level of the app
|
logLevel string // The log level of the app
|
||||||
@@ -33,8 +33,8 @@ type App struct {
|
|||||||
|
|
||||||
// CreateApp creates the application window with the given configuration
|
// CreateApp creates the application window with the given configuration
|
||||||
// If none given, the defaults are used
|
// If none given, the defaults are used
|
||||||
func CreateApp(optionalConfig ...*Config) *App {
|
func CreateApp(optionalConfig ...*AppConfig) *App {
|
||||||
var userConfig *Config
|
var userConfig *AppConfig
|
||||||
if len(optionalConfig) > 0 {
|
if len(optionalConfig) > 0 {
|
||||||
userConfig = optionalConfig[0]
|
userConfig = optionalConfig[0]
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -1,4 +1,4 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
// Version - Wails version
|
// Version - Wails version
|
||||||
const Version = "v0.17.3-pre"
|
const Version = "v0.17.4-pre"
|
||||||
|
|||||||
62
config.go
62
config.go
@@ -1,14 +1,8 @@
|
|||||||
package wails
|
package wails
|
||||||
|
|
||||||
import (
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/dchest/htmlmin"
|
// AppConfig is the configuration structure used when creating a Wails App object
|
||||||
// "github.com/leaanthony/mewn"
|
type AppConfig struct {
|
||||||
)
|
|
||||||
|
|
||||||
// Config is the configuration structure used when creating a Wails App object
|
|
||||||
type Config struct {
|
|
||||||
Width, Height int
|
Width, Height int
|
||||||
Title string
|
Title string
|
||||||
defaultHTML string
|
defaultHTML string
|
||||||
@@ -18,87 +12,60 @@ type Config struct {
|
|||||||
Colour string
|
Colour string
|
||||||
Resizable bool
|
Resizable bool
|
||||||
DisableInspector bool
|
DisableInspector bool
|
||||||
// isHTMLFragment bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetWidth returns the desired width
|
// GetWidth returns the desired width
|
||||||
func (a *Config) GetWidth() int {
|
func (a *AppConfig) GetWidth() int {
|
||||||
return a.Width
|
return a.Width
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetHeight returns the desired height
|
// GetHeight returns the desired height
|
||||||
func (a *Config) GetHeight() int {
|
func (a *AppConfig) GetHeight() int {
|
||||||
return a.Height
|
return a.Height
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetTitle returns the desired window title
|
// GetTitle returns the desired window title
|
||||||
func (a *Config) GetTitle() string {
|
func (a *AppConfig) GetTitle() string {
|
||||||
return a.Title
|
return a.Title
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDefaultHTML returns the desired window title
|
// GetDefaultHTML returns the desired window title
|
||||||
func (a *Config) GetDefaultHTML() string {
|
func (a *AppConfig) GetDefaultHTML() string {
|
||||||
return a.defaultHTML
|
return a.defaultHTML
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetResizable returns true if the window should be resizable
|
// GetResizable returns true if the window should be resizable
|
||||||
func (a *Config) GetResizable() bool {
|
func (a *AppConfig) GetResizable() bool {
|
||||||
return a.Resizable
|
return a.Resizable
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDisableInspector returns true if the inspector should be disabled
|
// GetDisableInspector returns true if the inspector should be disabled
|
||||||
func (a *Config) GetDisableInspector() bool {
|
func (a *AppConfig) GetDisableInspector() bool {
|
||||||
return a.DisableInspector
|
return a.DisableInspector
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetColour returns the colour
|
// GetColour returns the colour
|
||||||
func (a *Config) GetColour() string {
|
func (a *AppConfig) GetColour() string {
|
||||||
return a.Colour
|
return a.Colour
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCSS returns the user CSS
|
// GetCSS returns the user CSS
|
||||||
func (a *Config) GetCSS() string {
|
func (a *AppConfig) GetCSS() string {
|
||||||
return a.CSS
|
return a.CSS
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetJS returns the user Javascript
|
// GetJS returns the user Javascript
|
||||||
func (a *Config) GetJS() string {
|
func (a *AppConfig) GetJS() string {
|
||||||
return a.JS
|
return a.JS
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Config) merge(in *Config) error {
|
func (a *AppConfig) merge(in *AppConfig) error {
|
||||||
if in.CSS != "" {
|
if in.CSS != "" {
|
||||||
a.CSS = in.CSS
|
a.CSS = in.CSS
|
||||||
}
|
}
|
||||||
if in.Title != "" {
|
if in.Title != "" {
|
||||||
a.Title = in.Title
|
a.Title = in.Title
|
||||||
}
|
}
|
||||||
// if in.HTML != "" {
|
|
||||||
// minified, err := htmlmin.Minify([]byte(in.HTML), &htmlmin.Options{
|
|
||||||
// MinifyScripts: true,
|
|
||||||
// })
|
|
||||||
// if err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
// inlineHTML := string(minified)
|
|
||||||
// inlineHTML = strings.Replace(inlineHTML, "'", "\\'", -1)
|
|
||||||
// inlineHTML = strings.Replace(inlineHTML, "\n", " ", -1)
|
|
||||||
// a.HTML = strings.TrimSpace(inlineHTML)
|
|
||||||
|
|
||||||
// // Deduce whether this is a full html page or a fragment
|
|
||||||
// // The document is determined to be a fragment if an HTML
|
|
||||||
// // tag exists and is located before the first div tag
|
|
||||||
// HTMLTagIndex := strings.Index(a.HTML, "<html")
|
|
||||||
// DivTagIndex := strings.Index(a.HTML, "<div")
|
|
||||||
|
|
||||||
// if HTMLTagIndex == -1 {
|
|
||||||
// a.isHTMLFragment = true
|
|
||||||
// } else {
|
|
||||||
// if DivTagIndex < HTMLTagIndex {
|
|
||||||
// a.isHTMLFragment = true
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
if in.Colour != "" {
|
if in.Colour != "" {
|
||||||
a.Colour = in.Colour
|
a.Colour = in.Colour
|
||||||
@@ -121,14 +88,13 @@ func (a *Config) merge(in *Config) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Creates the default configuration
|
// Creates the default configuration
|
||||||
func newConfig(userConfig *Config) (*Config, error) {
|
func newConfig(userConfig *AppConfig) (*AppConfig, error) {
|
||||||
result := &Config{
|
result := &AppConfig{
|
||||||
Width: 800,
|
Width: 800,
|
||||||
Height: 600,
|
Height: 600,
|
||||||
Resizable: true,
|
Resizable: true,
|
||||||
Title: "My Wails App",
|
Title: "My Wails App",
|
||||||
Colour: "#FFF", // White by default
|
Colour: "#FFF", // White by default
|
||||||
// HTML: mewn.String("./runtime/assets/default.html"),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if userConfig != nil {
|
if userConfig != nil {
|
||||||
|
|||||||
@@ -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]);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module.exports = {
|
{
|
||||||
"env": {
|
"env": {
|
||||||
"browser": true,
|
"browser": true,
|
||||||
"es6": true
|
"es6": true
|
||||||
@@ -277,4 +277,4 @@ module.exports = {
|
|||||||
"never"
|
"never"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
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")}]);
|
||||||
@@ -7,10 +7,11 @@
|
|||||||
The lightweight framework for web-like apps
|
The lightweight framework for web-like apps
|
||||||
(c) Lea Anthony 2019-present
|
(c) Lea Anthony 2019-present
|
||||||
*/
|
*/
|
||||||
|
/* jshint esversion: 6 */
|
||||||
|
|
||||||
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 +24,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;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
The lightweight framework for web-like apps
|
The lightweight framework for web-like apps
|
||||||
(c) Lea Anthony 2019-present
|
(c) Lea Anthony 2019-present
|
||||||
*/
|
*/
|
||||||
|
/* jshint esversion: 6 */
|
||||||
|
|
||||||
import { SystemCall } from './calls';
|
import { SystemCall } from './calls';
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,16 @@
|
|||||||
|
/*
|
||||||
|
_ __ _ __
|
||||||
|
| | / /___ _(_) /____
|
||||||
|
| | /| / / __ `/ / / ___/
|
||||||
|
| |/ |/ / /_/ / / (__ )
|
||||||
|
|__/|__/\__,_/_/_/____/
|
||||||
|
The lightweight framework for web-like apps
|
||||||
|
(c) Lea Anthony 2019-present
|
||||||
|
*/
|
||||||
|
/* jshint esversion: 6 */
|
||||||
|
|
||||||
import { Debug } from './log';
|
import { Debug } from './log';
|
||||||
import { SendMessage } from './ipc'
|
import { SendMessage } from './ipc';
|
||||||
|
|
||||||
var callbacks = {};
|
var callbacks = {};
|
||||||
|
|
||||||
@@ -65,10 +75,10 @@ export function Call(bindingName, data, timeout) {
|
|||||||
const payload = {
|
const payload = {
|
||||||
bindingName: bindingName,
|
bindingName: bindingName,
|
||||||
data: JSON.stringify(data),
|
data: JSON.stringify(data),
|
||||||
}
|
};
|
||||||
|
|
||||||
// Make the call
|
// Make the call
|
||||||
SendMessage('call', payload, callbackID)
|
SendMessage('call', payload, callbackID);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
console.error(e);
|
console.error(e);
|
||||||
@@ -89,16 +99,16 @@ export function Callback(incomingMessage) {
|
|||||||
try {
|
try {
|
||||||
message = JSON.parse(incomingMessage);
|
message = JSON.parse(incomingMessage);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Debug('Invalid JSON passed to callback: ' + e.message);
|
const error = `Invalid JSON passed to callback: ${e.message}. Message: ${incomingMessage}`;
|
||||||
Debug('Message: ' + incomingMessage);
|
Debug(error);
|
||||||
return;
|
throw new Error(error);
|
||||||
}
|
}
|
||||||
var callbackID = message.callbackid;
|
var callbackID = message.callbackid;
|
||||||
var callbackData = callbacks[callbackID];
|
var callbackData = callbacks[callbackID];
|
||||||
if (!callbackData) {
|
if (!callbackData) {
|
||||||
// eslint-disable-next-line
|
const error = `Callback '${callbackID}' not registed!!!`;
|
||||||
console.error(`Callback '${callbackID}' not registed!!!`);
|
console.error(error); // eslint-disable-line
|
||||||
return;
|
throw new Error(error);
|
||||||
}
|
}
|
||||||
clearTimeout(callbackData.timeoutHandle);
|
clearTimeout(callbackData.timeoutHandle);
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
The lightweight framework for web-like apps
|
The lightweight framework for web-like apps
|
||||||
(c) Lea Anthony 2019-present
|
(c) Lea Anthony 2019-present
|
||||||
*/
|
*/
|
||||||
|
/* jshint esversion: 6 */
|
||||||
|
|
||||||
import { Error } from './log';
|
import { Error } from './log';
|
||||||
import { SendMessage } from './ipc';
|
import { SendMessage } from './ipc';
|
||||||
@@ -97,8 +98,8 @@ export function Emit(eventName) {
|
|||||||
const payload = {
|
const payload = {
|
||||||
name: eventName,
|
name: eventName,
|
||||||
data: data,
|
data: data,
|
||||||
}
|
};
|
||||||
SendMessage('event', payload)
|
SendMessage('event', payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
const heartbeatCallbacks = {};
|
const heartbeatCallbacks = {};
|
||||||
|
|||||||
@@ -7,15 +7,14 @@
|
|||||||
The lightweight framework for web-like apps
|
The lightweight framework for web-like apps
|
||||||
(c) Lea Anthony 2019-present
|
(c) Lea Anthony 2019-present
|
||||||
*/
|
*/
|
||||||
|
/* jshint esversion: 6 */
|
||||||
|
|
||||||
// var Invoke = window.external.invoke;
|
function Invoke(message) {
|
||||||
|
if (window && window.external && window.external.invoke) {
|
||||||
var Invoke;
|
window.external.invoke(message);
|
||||||
|
} else {
|
||||||
if (window && window.external && window.external.invoke) {
|
console.log(`[No external.invoke] ${message}`); // eslint-disable-line
|
||||||
Invoke = window.external.invoke;
|
}
|
||||||
} else {
|
|
||||||
Invoke = console.log;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
The lightweight framework for web-like apps
|
The lightweight framework for web-like apps
|
||||||
(c) Lea Anthony 2019-present
|
(c) Lea Anthony 2019-present
|
||||||
*/
|
*/
|
||||||
|
/* jshint esversion: 6 */
|
||||||
|
|
||||||
import { SendMessage } from './ipc';
|
import { SendMessage } from './ipc';
|
||||||
|
|
||||||
@@ -18,8 +19,8 @@ function sendLogMessage(level, message) {
|
|||||||
const payload = {
|
const payload = {
|
||||||
level: level,
|
level: level,
|
||||||
message: message,
|
message: message,
|
||||||
}
|
};
|
||||||
SendMessage('log', payload)
|
SendMessage('log', payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Debug(message) {
|
export function Debug(message) {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
The lightweight framework for web-like apps
|
The lightweight framework for web-like apps
|
||||||
(c) Lea Anthony 2019-present
|
(c) Lea Anthony 2019-present
|
||||||
*/
|
*/
|
||||||
|
/* jshint esversion: 6 */
|
||||||
import * as Log from './log';
|
import * as Log from './log';
|
||||||
import { On, Emit, Notify, Heartbeat, Acknowledge } from './events';
|
import { On, Emit, Notify, Heartbeat, Acknowledge } from './events';
|
||||||
import { NewBinding } from './bindings';
|
import { NewBinding } from './bindings';
|
||||||
@@ -24,19 +25,19 @@ var internal = {
|
|||||||
Notify,
|
Notify,
|
||||||
AddScript,
|
AddScript,
|
||||||
InjectCSS
|
InjectCSS
|
||||||
}
|
};
|
||||||
|
|
||||||
// Setup runtime structure
|
// Setup runtime structure
|
||||||
var runtime = {
|
var runtime = {
|
||||||
Log,
|
Log,
|
||||||
Event: {
|
Events: {
|
||||||
On,
|
On,
|
||||||
Emit,
|
Emit,
|
||||||
Heartbeat,
|
Heartbeat,
|
||||||
Acknowledge,
|
Acknowledge,
|
||||||
},
|
},
|
||||||
_: internal,
|
_: internal,
|
||||||
}
|
};
|
||||||
|
|
||||||
// Augment global
|
// Augment global
|
||||||
Object.assign(window.wails, runtime);
|
Object.assign(window.wails, runtime);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
The lightweight framework for web-like apps
|
The lightweight framework for web-like apps
|
||||||
(c) Lea Anthony 2019-present
|
(c) Lea Anthony 2019-present
|
||||||
*/
|
*/
|
||||||
|
/* jshint esversion: 6 */
|
||||||
|
|
||||||
import { Emit } from './events';
|
import { Emit } from './events';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user