mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-03 06:51:26 +08:00
parent
806b1aa8e0
commit
2c2aee2d30
@ -2,22 +2,22 @@
|
||||
|
||||
Wails is what it is because of the time and effort given by these great people. A huge thank you to each and every one!
|
||||
|
||||
* [Dustin Krysak](https://wiki.ubuntu.com/bashfulrobot)
|
||||
* [Qais Patankar](https://github.com/qaisjp)
|
||||
* [Anthony Lee](https://github.com/alee792)
|
||||
* [Adrian Lanzafame](https://github.com/lanzafame)
|
||||
* [Mattn](https://github.com/mattn)
|
||||
* [0xflotus](https://github.com/0xflotus)
|
||||
* [Michael D Henderson](https://github.com/mdhender)
|
||||
* [fred2104](https://github.com/fishfishfish2104)
|
||||
* [intelwalk](https://github.com/intelwalk)
|
||||
* [Mark Stenglein](https://github.com/ocelotsloth)
|
||||
* [admin_3.exe](https://github.com/bh90210)
|
||||
* [iceleo-com](https://github.com/iceleo-com)
|
||||
* [fallendusk](https://github.com/fallendusk)
|
||||
* [Florian Didran](https://github.com/fdidron)
|
||||
* [Nikolai Zimmermann](https://github.com/Chronophylos)
|
||||
* [Toyam Cox](https://github.com/Vaelatern)
|
||||
* [Robin Eklind](https://github.com/mewmew)
|
||||
* [Kris Raney](https://github.com/kraney)
|
||||
* [Jack Mordaunt](https://github.com/JackMordaunt)
|
||||
* [Dustin Krysak](https://wiki.ubuntu.com/bashfulrobot)
|
||||
* [Qais Patankar](https://github.com/qaisjp)
|
||||
* [Anthony Lee](https://github.com/alee792)
|
||||
* [Adrian Lanzafame](https://github.com/lanzafame)
|
||||
* [Mattn](https://github.com/mattn)
|
||||
* [0xflotus](https://github.com/0xflotus)
|
||||
* [Michael D Henderson](https://github.com/mdhender)
|
||||
* [fred2104](https://github.com/fishfishfish2104)
|
||||
* [intelwalk](https://github.com/intelwalk)
|
||||
* [Mark Stenglein](https://github.com/ocelotsloth)
|
||||
* [admin_3.exe](https://github.com/bh90210)
|
||||
* [iceleo-com](https://github.com/iceleo-com)
|
||||
* [fallendusk](https://github.com/fallendusk)
|
||||
* [Florian Didran](https://github.com/fdidron)
|
||||
* [Nikolai Zimmermann](https://github.com/Chronophylos)
|
||||
* [Toyam Cox](https://github.com/Vaelatern)
|
||||
* [Robin Eklind](https://github.com/mewmew)
|
||||
* [Kris Raney](https://github.com/kraney)
|
||||
* [Jack Mordaunt](https://github.com/JackMordaunt)
|
||||
|
7
app.go
7
app.go
@ -45,7 +45,7 @@ func CreateApp(optionalConfig ...*AppConfig) *App {
|
||||
}
|
||||
|
||||
result := &App{
|
||||
logLevel: "info",
|
||||
logLevel: "debug",
|
||||
renderer: renderer.NewWebView(),
|
||||
ipc: ipc.NewManager(),
|
||||
bindingManager: binding.NewManager(),
|
||||
@ -123,6 +123,11 @@ func (a *App) start() error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Enable console for Windows debug builds
|
||||
if runtime.GOOS == "windows" && BuildMode == cmd.BuildModeDebug {
|
||||
a.renderer.EnableConsole()
|
||||
}
|
||||
|
||||
// Start signal handler
|
||||
t := tebata.New(os.Interrupt, os.Kill, syscall.SIGTERM, syscall.SIGINT, syscall.SIGKILL)
|
||||
t.Reserve(func() {
|
||||
|
@ -9,4 +9,4 @@
|
||||
last 2 versions
|
||||
Firefox ESR
|
||||
not dead
|
||||
IE 9-11 # For IE 9-11 support, remove 'not'.
|
||||
IE 9-11 # For IE 9-11 support, remove 'not'.
|
||||
|
@ -3,10 +3,12 @@ package interfaces
|
||||
import (
|
||||
"github.com/wailsapp/wails/lib/messages"
|
||||
)
|
||||
|
||||
// Renderer is an interface describing a Wails target to render the app to
|
||||
type Renderer interface {
|
||||
Initialise(AppConfig, IPCManager, EventManager) error
|
||||
Run() error
|
||||
EnableConsole()
|
||||
|
||||
// Binding
|
||||
NewBinding(bindingName string) error
|
||||
|
@ -74,6 +74,10 @@ func (h *Bridge) evalJS(js string, mtype messageType) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// EnableConsole not needed for bridge!
|
||||
func (h *Bridge) EnableConsole() {
|
||||
}
|
||||
|
||||
func (h *Bridge) injectCSS(css string) {
|
||||
// Minify css to overcome issues in the browser with carriage returns
|
||||
minified, err := htmlmin.Minify([]byte(css), &htmlmin.Options{
|
||||
|
File diff suppressed because one or more lines are too long
@ -19,12 +19,13 @@ import (
|
||||
// WebView defines the main webview application window
|
||||
// Default values in []
|
||||
type WebView struct {
|
||||
window wv.WebView // The webview object
|
||||
ipc interfaces.IPCManager
|
||||
log *logger.CustomLogger
|
||||
config interfaces.AppConfig
|
||||
eventManager interfaces.EventManager
|
||||
bindingCache []string
|
||||
window wv.WebView // The webview object
|
||||
ipc interfaces.IPCManager
|
||||
log *logger.CustomLogger
|
||||
config interfaces.AppConfig
|
||||
eventManager interfaces.EventManager
|
||||
bindingCache []string
|
||||
enableConsole bool
|
||||
}
|
||||
|
||||
// NewWebView returns a new WebView struct
|
||||
@ -103,6 +104,11 @@ func (w *WebView) evalJS(js string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// EnableConsole enables the console!
|
||||
func (w *WebView) EnableConsole() {
|
||||
w.enableConsole = true
|
||||
}
|
||||
|
||||
// Escape the Javascripts!
|
||||
func escapeJS(js string) (string, error) {
|
||||
result := strings.Replace(js, "\\", "\\\\", -1)
|
||||
@ -172,6 +178,13 @@ func (w *WebView) Run() error {
|
||||
|
||||
w.log.Info("Running...")
|
||||
|
||||
// Inject firebug in debug mode on Windows
|
||||
if w.enableConsole {
|
||||
w.log.Debug("Enabling Wails console")
|
||||
console := mewn.String("../../runtime/assets/console.js")
|
||||
w.evalJS(console)
|
||||
}
|
||||
|
||||
// Runtime assets
|
||||
wailsRuntime := mewn.String("../../runtime/assets/wails.js")
|
||||
w.evalJS(wailsRuntime)
|
||||
|
175
runtime/assets/console.js
Normal file
175
runtime/assets/console.js
Normal file
@ -0,0 +1,175 @@
|
||||
(function () {
|
||||
|
||||
window.wailsconsole = {};
|
||||
|
||||
var debugconsole = document.createElement("div");
|
||||
var header = document.createElement("div");
|
||||
var consoleOut = document.createElement("div");
|
||||
|
||||
|
||||
document.addEventListener('keyup', logKey);
|
||||
|
||||
debugconsole.id = "wailsdebug";
|
||||
debugconsole.style.fontSize = "18px";
|
||||
debugconsole.style.width = "100%";
|
||||
debugconsole.style.height = "35%";
|
||||
debugconsole.style.maxHeight = "35%";
|
||||
debugconsole.style.position = "fixed";
|
||||
debugconsole.style.left = "0px";
|
||||
debugconsole.style.backgroundColor = "rgba(255,255,255,0.8)";
|
||||
debugconsole.style.borderTop = '1px solid black';
|
||||
debugconsole.style.color = "black";
|
||||
debugconsole.style.display = "none";
|
||||
|
||||
header.style.width = "100%";
|
||||
header.style.height = "30px";
|
||||
header.style.display = "block";
|
||||
// header.style.paddingTop = "3px";
|
||||
header.style.verticalAlign = "middle";
|
||||
header.style.paddingLeft = "10px";
|
||||
header.style.background = "rgba(255,255,255,0.8)";
|
||||
header.innerHTML = " <span style='vertical-align: middle'> Wails Console > <input id='conin' style='border: solid 1px black; width: 50%'></input><span style='padding-left: 5px; cursor:pointer;' onclick='window.wailsconsole.clearConsole()'>Clear</span></span>";
|
||||
|
||||
consoleOut.style.position = "absolute";
|
||||
consoleOut.style.width = "100%";
|
||||
consoleOut.style.height = "auto";
|
||||
consoleOut.style.top = "30px";
|
||||
// consoleOut.style.paddingLeft = "10px";
|
||||
consoleOut.style.bottom = "0px";
|
||||
consoleOut.style.backgroundColor = "rgba(200,200,200,1)";
|
||||
consoleOut.style.overflowY = "scroll";
|
||||
consoleOut.style.msOverflowStyle = "-ms-autohiding-scrollbar";
|
||||
|
||||
debugconsole.appendChild(header);
|
||||
debugconsole.appendChild(consoleOut);
|
||||
document.body.appendChild(debugconsole);
|
||||
console.log(debugconsole.style.display)
|
||||
|
||||
function logKey(e) {
|
||||
var conin = document.getElementById('conin');
|
||||
if (e.which == 27 && e.shiftKey) {
|
||||
toggleConsole(conin);
|
||||
}
|
||||
if (e.which == 13 && consoleVisible()) {
|
||||
var command = conin.value.trim();
|
||||
if (command.length > 0) {
|
||||
console.log("> " + command)
|
||||
try {
|
||||
evaluateInput(command);
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
}
|
||||
conin.value = "";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
function consoleVisible() {
|
||||
return debugconsole.style.display == "block";
|
||||
}
|
||||
|
||||
function toggleConsole(conin) {
|
||||
var display = "none"
|
||||
if (debugconsole.style.display == "none") display = "block";
|
||||
debugconsole.style.display = display;
|
||||
if (display == "block") {
|
||||
conin.focus();
|
||||
}
|
||||
}
|
||||
|
||||
function evaluateExpression(expression) {
|
||||
|
||||
var pathSegments = [].concat(expression.split('.'));
|
||||
if (pathSegments[0] == 'window') {
|
||||
pathSegments.shift()
|
||||
}
|
||||
var currentObject = window;
|
||||
for (var i = 0; i < pathSegments.length; i++) {
|
||||
var pathSegment = pathSegments[i];
|
||||
if (currentObject[pathSegment] == undefined) {
|
||||
return false;
|
||||
}
|
||||
currentObject = currentObject[pathSegment];
|
||||
}
|
||||
console.log(JSON.stringify(currentObject));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function evaluateInput(command) {
|
||||
try {
|
||||
if (evaluateExpression(command)) {
|
||||
return
|
||||
} else {
|
||||
eval(command);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e.message)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Set us up as a listener
|
||||
function hookIntoIPC() {
|
||||
if (window.wails && window.wails._ && window.wails._.AddIPCListener) {
|
||||
window.wails._.AddIPCListener(processIPCMessage);
|
||||
} else {
|
||||
setTimeout(hookIntoIPC, 100);
|
||||
}
|
||||
}
|
||||
hookIntoIPC();
|
||||
|
||||
function processIPCMessage(message) {
|
||||
console.log(message);
|
||||
var parsedMessage;
|
||||
try {
|
||||
parsedMessage = JSON.parse(message);
|
||||
} catch (e) {
|
||||
console.error("Error in parsing IPC message: " + e.message);
|
||||
return false;
|
||||
}
|
||||
var logmessage = "[IPC] "
|
||||
switch (parsedMessage.type) {
|
||||
case 'call':
|
||||
logmessage += " Call: " + parsedMessage.payload.bindingName;
|
||||
var params = "";
|
||||
var parsedParams = JSON.parse(parsedMessage.payload.data);
|
||||
if (parsedParams.length > 0) {
|
||||
params = parsedParams;
|
||||
}
|
||||
logmessage += "(" + params + ")";
|
||||
break;
|
||||
case 'log':
|
||||
logmessage += "Log (" + parsedMessage.payload.level + "): " + parsedMessage.payload.message;
|
||||
break;
|
||||
default:
|
||||
logmessage = message;
|
||||
}
|
||||
console.log(logmessage);
|
||||
}
|
||||
|
||||
window.wailsconsole.clearConsole = function () {
|
||||
consoleOut.innerHTML = "";
|
||||
}
|
||||
|
||||
console.log = function (message) {
|
||||
consoleOut.innerHTML = consoleOut.innerHTML + "<span style='padding-left: 5px'>" + message + '</span><br/>';
|
||||
consoleOut.scrollTop = consoleOut.scrollHeight;
|
||||
|
||||
};
|
||||
console.error = function (message) {
|
||||
consoleOut.innerHTML = consoleOut.innerHTML + "<span style='color:red; padding-left: 5px'> Error: " + message + '</span><br/>';
|
||||
consoleOut.scrollTop = consoleOut.scrollHeight;
|
||||
};
|
||||
// var h = document.getElementsByTagName("html")[0];
|
||||
// console.log("html margin: " + h.style.marginLeft);
|
||||
// console.log("html padding: " + h.style.paddingLeft);
|
||||
|
||||
// setInterval(function() { console.log("test");}, 1000);
|
||||
// setInterval(function() { console.error("oops");}, 3000);
|
||||
// var script = document.createElement('script');
|
||||
// script.src = "https://cdnjs.cloudflare.com/ajax/libs/firebug-lite/1.4.0/firebug-lite.js#startOpened=true";
|
||||
// document.body.appendChild(script);
|
||||
|
||||
})();
|
File diff suppressed because one or more lines are too long
@ -9,17 +9,35 @@ The lightweight framework for web-like apps
|
||||
*/
|
||||
/* jshint esversion: 6 */
|
||||
|
||||
// IPC Listeners
|
||||
var listeners = [];
|
||||
|
||||
/**
|
||||
* Adds a listener to IPC messages
|
||||
* @param {function} callback
|
||||
*/
|
||||
export function AddIPCListener(callback) {
|
||||
listeners.push(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke sends the given message to the backend
|
||||
*
|
||||
* @param {string} message
|
||||
*/
|
||||
function Invoke(message) {
|
||||
if ( window.wailsbridge ) {
|
||||
if (window.wailsbridge) {
|
||||
window.wailsbridge.websocket.send(message);
|
||||
} else {
|
||||
window.external.invoke(message);
|
||||
}
|
||||
|
||||
// Also send to listeners
|
||||
if (listeners.length > 0) {
|
||||
for (var i = 0; i < listeners.length; i++) {
|
||||
listeners[i](message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -14,6 +14,7 @@ import { On, OnMultiple, Emit, Notify, Heartbeat, Acknowledge } from './events';
|
||||
import { NewBinding } from './bindings';
|
||||
import { Callback } from './calls';
|
||||
import { AddScript, InjectCSS } from './utils';
|
||||
import { AddIPCListener } from './ipc';
|
||||
|
||||
// Initialise global if not already
|
||||
window.wails = window.wails || {};
|
||||
@ -27,6 +28,7 @@ var internal = {
|
||||
AddScript,
|
||||
InjectCSS,
|
||||
Init,
|
||||
AddIPCListener,
|
||||
};
|
||||
|
||||
// Setup runtime structure
|
||||
|
@ -43,6 +43,7 @@ echo "**** WE ARE DONE! ****"
|
||||
func runCommand(command string, args ...string) {
|
||||
cmd := exec.Command(command, args...)
|
||||
output, err := cmd.CombinedOutput()
|
||||
fmt.Println(string(output))
|
||||
if err != nil {
|
||||
log.Println(string(output))
|
||||
log.Fatal(err)
|
||||
|
Loading…
Reference in New Issue
Block a user