Compare commits

..

2 Commits

Author SHA1 Message Date
Lea Anthony
71dc137194 fiX: unicode fixes for windows 2019-11-01 10:19:06 +11:00
Lea Anthony
13e6bd2178 fix: misc fixes 2019-11-01 10:15:21 +11:00
30 changed files with 845 additions and 16683 deletions

3
.gitignore vendored
View File

@@ -16,5 +16,4 @@ examples/**/example*
cmd/wails/wails cmd/wails/wails
.DS_Store .DS_Store
tmp tmp
node_modules/ node_modules/
/runtime/js/runtime/dist

8
app.go
View File

@@ -2,7 +2,6 @@ package wails
import ( import (
"os" "os"
"runtime"
"syscall" "syscall"
"github.com/syossan27/tebata" "github.com/syossan27/tebata"
@@ -44,7 +43,7 @@ func CreateApp(optionalConfig ...*AppConfig) *App {
} }
result := &App{ result := &App{
logLevel: "debug", logLevel: "info",
renderer: renderer.NewWebView(), renderer: renderer.NewWebView(),
ipc: ipc.NewManager(), ipc: ipc.NewManager(),
bindingManager: binding.NewManager(), bindingManager: binding.NewManager(),
@@ -103,11 +102,6 @@ func (a *App) start() error {
return err return err
} }
// Set debug mode
if runtime.GOOS == "windows" && BuildMode == cmd.BuildModeDebug {
a.renderer.EnableDebug()
}
// Start signal handler // Start signal handler
t := tebata.New(os.Interrupt, os.Kill, syscall.SIGTERM, syscall.SIGINT, syscall.SIGKILL) t := tebata.New(os.Interrupt, os.Kill, syscall.SIGTERM, syscall.SIGINT, syscall.SIGKILL)
t.Reserve(func() { t.Reserve(func() {

File diff suppressed because one or more lines are too long

View File

@@ -9,4 +9,4 @@
last 2 versions last 2 versions
Firefox ESR Firefox ESR
not dead not dead
IE 9-11 # For IE 9-11 support, remove 'not'. IE 9-11 # For IE 9-11 support, remove 'not'.

View File

@@ -0,0 +1,17 @@
/*
Wails Bridge (c) 2019-present Lea Anthony
This prod version is to get around having to rewrite your code
for production. When doing a release build, this file will be used
instead of the full version.
*/
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);
}
}
};

View File

@@ -0,0 +1,17 @@
/*
Wails Bridge (c) 2019-present Lea Anthony
This prod version is to get around having to rewrite your code
for production. When doing a release build, this file will be used
instead of the full version.
*/
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);
}
}
};

View File

@@ -94,12 +94,12 @@ func (a *AppConfig) merge(in *AppConfig) error {
// Creates the default configuration // Creates the default configuration
func newConfig(userConfig *AppConfig) (*AppConfig, error) { func newConfig(userConfig *AppConfig) (*AppConfig, error) {
result := &AppConfig{ 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
defaultHTML: mewn.String("./runtime/assets/default.html"), HTML: mewn.String("./runtime/assets/default.html"),
} }
if userConfig != nil { if userConfig != nil {

View File

@@ -3,12 +3,10 @@ package interfaces
import ( import (
"github.com/wailsapp/wails/lib/messages" "github.com/wailsapp/wails/lib/messages"
) )
// Renderer is an interface describing a Wails target to render the app to // Renderer is an interface describing a Wails target to render the app to
type Renderer interface { type Renderer interface {
Initialise(AppConfig, IPCManager, EventManager) error Initialise(AppConfig, IPCManager, EventManager) error
Run() error Run() error
EnableDebug()
// Binding // Binding
NewBinding(bindingName string) error NewBinding(bindingName string) error

View File

@@ -48,9 +48,6 @@ type Bridge struct {
// Mutex for writing to the socket // Mutex for writing to the socket
lock sync.Mutex lock sync.Mutex
// debug
debug bool
} }
// Initialise the Bridge Renderer // Initialise the Bridge Renderer
@@ -77,11 +74,6 @@ func (h *Bridge) evalJS(js string, mtype messageType) error {
return nil return nil
} }
// EnableDebug enables debug!
func (h *Bridge) EnableDebug() {
h.debug = true
}
func (h *Bridge) injectCSS(css string) { func (h *Bridge) injectCSS(css string) {
// Minify css to overcome issues in the browser with carriage returns // Minify css to overcome issues in the browser with carriage returns
minified, err := htmlmin.Minify([]byte(css), &htmlmin.Options{ minified, err := htmlmin.Minify([]byte(css), &htmlmin.Options{
@@ -125,6 +117,7 @@ func (h *Bridge) sendMessage(conn *websocket.Conn, msg string) {
func (h *Bridge) start(conn *websocket.Conn) { func (h *Bridge) start(conn *websocket.Conn) {
// set external.invoke
h.log.Infof("Connected to frontend.") h.log.Infof("Connected to frontend.")
wailsRuntime := mewn.String("../../runtime/assets/wails.js") wailsRuntime := mewn.String("../../runtime/assets/wails.js")

File diff suppressed because one or more lines are too long

View File

@@ -25,7 +25,6 @@ type WebView struct {
config interfaces.AppConfig config interfaces.AppConfig
eventManager interfaces.EventManager eventManager interfaces.EventManager
bindingCache []string bindingCache []string
debug bool
} }
// NewWebView returns a new WebView struct // NewWebView returns a new WebView struct
@@ -49,22 +48,13 @@ func (w *WebView) Initialise(config interfaces.AppConfig, ipc interfaces.IPCMana
// Save the config // Save the config
w.config = config w.config = config
// defaulthtml
HTML := config.GetDefaultHTML()
if len(HTML) == 0 {
HTML = mewn.String("../../runtime/assets/default.html")
}
HTML = fmt.Sprintf("data:text/html,%s", HTML)
fmt.Printf("*** %s ***", HTML)
w.log.Infof("URL: %s", HTML)
// Create the WebView instance // Create the WebView instance
w.window = wv.NewWebview(wv.Settings{ w.window = wv.NewWebview(wv.Settings{
Width: config.GetWidth(), Width: config.GetWidth(),
Height: config.GetHeight(), Height: config.GetHeight(),
Title: config.GetTitle(), Title: config.GetTitle(),
Resizable: config.GetResizable(), Resizable: config.GetResizable(),
URL: HTML, URL: config.GetDefaultHTML(),
Debug: !config.GetDisableInspector(), Debug: !config.GetDisableInspector(),
ExternalInvokeCallback: func(_ wv.WebView, message string) { ExternalInvokeCallback: func(_ wv.WebView, message string) {
w.ipc.Dispatch(message) w.ipc.Dispatch(message)
@@ -105,7 +95,6 @@ func (w *WebView) evalJS(js string) error {
if len(js) > 45 { if len(js) > 45 {
outputJS += "..." outputJS += "..."
} }
// var outputJS = js
w.log.DebugFields("Eval", logger.Fields{"js": outputJS}) w.log.DebugFields("Eval", logger.Fields{"js": outputJS})
// //
w.window.Dispatch(func() { w.window.Dispatch(func() {
@@ -114,11 +103,6 @@ func (w *WebView) evalJS(js string) error {
return nil return nil
} }
// EnableDebug enables debug!
func (w *WebView) EnableDebug() {
w.debug = true
}
// Escape the Javascripts! // Escape the Javascripts!
func escapeJS(js string) (string, error) { func escapeJS(js string) (string, error) {
result := strings.Replace(js, "\\", "\\\\", -1) result := strings.Replace(js, "\\", "\\\\", -1)
@@ -188,58 +172,51 @@ func (w *WebView) Run() error {
w.log.Info("Running...") w.log.Info("Running...")
// Inject firebug in debug mode on Windows // Runtime assets
if w.debug { wailsRuntime := mewn.String("../../runtime/assets/wails.js")
w.log.Debug("Injecting firebug") w.evalJS(wailsRuntime)
// firebugLite := mewn.String("../../runtime/assets/injectFirebug.js")
// w.evalJS(firebugLite)
}
// // Runtime assets // Ping the wait channel when the wails runtime is loaded
// wailsRuntime := mewn.String("../../runtime/assets/wails.js") w.eventManager.On("wails:loaded", func(...interface{}) {
// w.evalJS(wailsRuntime)
// // Ping the wait channel when the wails runtime is loaded // Run this in a different go routine to free up the main process
// w.eventManager.On("wails:loaded", func(...interface{}) { go func() {
// // Run this in a different go routine to free up the main process // Inject Bindings
// go func() { for _, binding := range w.bindingCache {
w.evalJSSync(binding)
}
// // Inject Bindings // Inject user CSS
// for _, binding := range w.bindingCache { if w.config.GetCSS() != "" {
// w.evalJSSync(binding) outputCSS := fmt.Sprintf("%.45s", w.config.GetCSS())
// } if len(outputCSS) > 45 {
outputCSS += "..."
}
w.log.DebugFields("Inject User CSS", logger.Fields{"css": outputCSS})
w.injectCSS(w.config.GetCSS())
} else {
// Use default wails css
w.log.Debug("Injecting Default Wails CSS")
defaultCSS := mewn.String("../../runtime/assets/wails.css")
// // Inject user CSS w.injectCSS(defaultCSS)
// if w.config.GetCSS() != "" { }
// outputCSS := fmt.Sprintf("%.45s", w.config.GetCSS())
// if len(outputCSS) > 45 {
// outputCSS += "..."
// }
// w.log.DebugFields("Inject User CSS", logger.Fields{"css": outputCSS})
// w.injectCSS(w.config.GetCSS())
// } else {
// // Use default wails css
// w.log.Debug("Injecting Default Wails CSS")
// defaultCSS := mewn.String("../../runtime/assets/wails.css")
// w.injectCSS(defaultCSS) // Inject user JS
// } if w.config.GetJS() != "" {
outputJS := fmt.Sprintf("%.45s", w.config.GetJS())
if len(outputJS) > 45 {
outputJS += "..."
}
w.log.DebugFields("Inject User JS", logger.Fields{"js": outputJS})
w.evalJSSync(w.config.GetJS())
}
// // Inject user JS // Emit that everything is loaded and ready
// if w.config.GetJS() != "" { w.eventManager.Emit("wails:ready")
// outputJS := fmt.Sprintf("%.45s", w.config.GetJS()) }()
// if len(outputJS) > 45 { })
// outputJS += "..."
// }
// w.log.DebugFields("Inject User JS", logger.Fields{"js": outputJS})
// w.evalJSSync(w.config.GetJS())
// }
// // Emit that everything is loaded and ready
// w.eventManager.Emit("wails:ready")
// }()
// })
// Kick off main window loop // Kick off main window loop
w.window.Run() w.window.Run()

View File

@@ -95,6 +95,13 @@ function startBridge() {
window.wailsbridge.reconnectOverlay.style.display = 'none'; window.wailsbridge.reconnectOverlay.style.display = 'none';
} }
// Bridge external.invoke
window.external = {
invoke: function (msg) {
window.wailsbridge.websocket.send(msg);
}
};
// Adds a script to the Dom. // Adds a script to the Dom.
// Removes it if second parameter is true. // Removes it if second parameter is true.
function addScript(script, remove) { function addScript(script, remove) {
@@ -204,11 +211,6 @@ function start(callback) {
} }
function Init(callback) { function Init(callback) {
// Bridge window.invoke
window.invoke = function (message) {
window.wailsbridge.websocket.send(message);
}
start(callback); start(callback);
} }

View File

@@ -1 +1,18 @@
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><script src="https://raw.githubusercontent.com/firebug/firebug-lite/master/build/firebug-lite-debug.js#startOpened=true"></script></head><body><div id="app"></div><script type="text/javascript">function AddScript(js, callbackID){var script = document.createElement('script');script.text=js;document.body.appendChild(script);}</script></body></html> <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
</head>
<body>
<div id="app"></div>
<script type="text/javascript">function AddScript(js, callbackID) {
var script = document.createElement('script');
script.text = js;
document.body.appendChild(script);
}</script>
</body>
</html>

File diff suppressed because one or more lines are too long

View File

@@ -1 +0,0 @@
(function(){console.log=function(message){document.body.innerHTML=document.body.innerHTML+'<p>'+message+'</p>';};var script=document.createElement('script');script.src="https://raw.githubusercontent.com/firebug/firebug-lite/master/build/firebug-lite-debug.js#startOpened=true";document.body.appendChild(script);})();

File diff suppressed because one or more lines are too long

View File

@@ -25,4 +25,4 @@
"always" "always"
] ]
} }
} }

View File

@@ -7,7 +7,7 @@ module.exports = function (api) {
[ [
"@babel/preset-env", "@babel/preset-env",
{ {
"useBuiltIns": "usage", "useBuiltIns": "entry",
"corejs": { "corejs": {
"version": 3, "version": 3,
"proposals": true "proposals": true
@@ -16,10 +16,7 @@ module.exports = function (api) {
] ]
]; ];
const plugins = ["@babel/plugin-transform-object-assign", "transform-es2015-shorthand-properties"]
return { return {
presets, presets,
plugins
}; };
} }

View File

@@ -1,37 +0,0 @@
/* eslint-disable */
const path = require('path');
module.exports = {
entry: './bridge.js',
mode: 'production',
output: {
path: path.resolve(__dirname, '..', 'assets'),
filename: 'bridge.js',
libraryTarget: 'this'
},
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
plugins: [],
presets: [
[
'@babel/preset-env',
{
'useBuiltIns': 'usage',
'corejs': 3,
'targets': { "browsers": ["last 2 versions", "ie >= 9"] }
}
]
]
}
}
}
]
}
};

View File

@@ -15,11 +15,7 @@ The lightweight framework for web-like apps
* @param {string} message * @param {string} message
*/ */
function Invoke(message) { function Invoke(message) {
if ( window.wailsbridge ) { window.external.invoke(message);
window.wailsbridge.websocket.send(message);
} else {
window.external.invoke(message);
}
} }
/** /**

File diff suppressed because it is too large Load Diff

View File

@@ -33,15 +33,11 @@
"@babel/core": "^7.5.4", "@babel/core": "^7.5.4",
"@babel/plugin-transform-object-assign": "^7.2.0", "@babel/plugin-transform-object-assign": "^7.2.0",
"@babel/preset-env": "^7.5.4", "@babel/preset-env": "^7.5.4",
"babel-core": "^6.26.3",
"babel-loader": "^8.0.6", "babel-loader": "^8.0.6",
"babel-plugin-transform-es2015-shorthand-properties": "^6.24.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-minify": "^0.5.0", "babel-preset-minify": "^0.5.0",
"core-js": "^3.1.4", "core-js": "^3.1.4",
"eslint": "^6.5.1", "eslint": "^6.5.1",
"webpack": "^4.41.2", "webpack": "^4.35.3",
"webpack-cli": "^3.3.5" "webpack-cli": "^3.3.5"
}, }
"dependencies": {}
} }

View File

@@ -34,4 +34,4 @@ function OpenFile(filename) {
module.exports = { module.exports = {
OpenURL: OpenURL, OpenURL: OpenURL,
OpenFile: OpenFile OpenFile: OpenFile
}; };

View File

@@ -86,4 +86,4 @@ module.exports = {
Emit: Emit, Emit: Emit,
Heartbeat: Heartbeat, Heartbeat: Heartbeat,
Acknowledge: Acknowledge Acknowledge: Acknowledge
}; };

View File

@@ -19,4 +19,4 @@ module.exports = {
Browser: Browser, Browser: Browser,
Events: Events, Events: Events,
Init: Init Init: Init
}; };

File diff suppressed because it is too large Load Diff

View File

@@ -5,8 +5,7 @@
"main": "main.js", "main": "main.js",
"types": "runtime.d.ts", "types": "runtime.d.ts",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1"
"build": "webpack"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@@ -22,18 +21,8 @@
"bugs": { "bugs": {
"url": "https://github.com/wailsapp/wails/issues" "url": "https://github.com/wailsapp/wails/issues"
}, },
"files": [
"*.js",
"!webpack.config.js",
"runtime.d.ts",
"README.md"
],
"homepage": "https://github.com/wailsapp/wails#readme", "homepage": "https://github.com/wailsapp/wails#readme",
"devDependencies": { "devDependencies": {
"babel-core": "^6.26.3", "dts-gen": "^0.5.8"
"babel-loader": "^8.0.6",
"babel-preset-es2015": "^6.24.1",
"dts-gen": "^0.5.8",
"webpack": "^4.41.2"
} }
} }

View File

@@ -1,37 +0,0 @@
/* eslint-disable */
const path = require('path');
module.exports = {
entry: './main.js',
mode: 'production',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'main.js',
libraryTarget: 'this'
},
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
plugins: [],
presets: [
[
'@babel/preset-env',
{
'useBuiltIns': 'usage',
'corejs': 3,
'targets': { "browsers": ["last 2 versions", "ie >= 9"] }
}
]
]
}
}
}
]
}
};

View File

@@ -17,14 +17,16 @@ module.exports = {
use: { use: {
loader: 'babel-loader', loader: 'babel-loader',
options: { options: {
plugins: [], plugins: ['@babel/plugin-transform-object-assign'],
presets: [ presets: [
[ [
'@babel/preset-env', '@babel/preset-env',
{ {
'useBuiltIns': 'usage', 'useBuiltIns': 'entry',
'corejs': 3, 'corejs': {
'targets': { "browsers": ["last 2 versions", "ie >= 9"] } 'version': 3,
'proposals': true
}
} }
] ]
] ]

View File

@@ -1,82 +0,0 @@
package main
import (
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
)
// Default target to run when none is specified
// If not set, running mage will list available targets
// var Default = Build
/*
# Build runtime
echo "**** Building Runtime ****"
cd runtime/js
npm install
npm run build
cd ../..
echo "**** Packing Assets ****"
cd cmd
mewn
cd ..
cd lib/renderer
mewn
cd ../..
echo "**** Installing Wails locally ****"
cd cmd/wails
go install
cd ../..
echo "**** Tidying the mods! ****"
go mod tidy
echo "**** WE ARE DONE! ****"
*/
func runCommand(command string, args ...string) {
cmd := exec.Command(command, args...)
output, err := cmd.CombinedOutput()
if err != nil {
log.Fatal(err)
}
cmd.Run()
fmt.Println(string(output))
}
// A build step that requires additional params, or platform specific steps for example
func main() {
dir, _ := os.Getwd()
// Build Runtime
fmt.Println("**** Building Runtime ****")
runtimeDir, _ := filepath.Abs(filepath.Join(dir, "..", "runtime", "js"))
os.Chdir(runtimeDir)
runCommand("npm", "run", "build")
// Pack assets
fmt.Println("**** Packing Assets ****")
rendererDir, _ := filepath.Abs(filepath.Join(dir, "..", "lib", "renderer"))
os.Chdir(rendererDir)
runCommand("mewn")
cmdDir, _ := filepath.Abs(filepath.Join(dir, "..", "cmd"))
os.Chdir(cmdDir)
runCommand("mewn")
// Install Wails
fmt.Println("**** Installing Wails locally ****")
execDir, _ := filepath.Abs(filepath.Join(dir, "..", "cmd", "wails"))
os.Chdir(execDir)
runCommand("go", "install")
baseDir, _ := filepath.Abs(filepath.Join(dir, ".."))
os.Chdir(baseDir)
runCommand("go", "mod", "tidy")
}