5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-01 22:42:37 +08:00

Initial commit of simplification

This commit is contained in:
Lea Anthony 2019-01-30 09:00:46 +11:00
parent cd8b4f088f
commit 0ca039e914
No known key found for this signature in database
GPG Key ID: 33DAF7BB90A58405
43 changed files with 73 additions and 1035 deletions

File diff suppressed because one or more lines are too long

9
app.go
View File

@ -2,7 +2,6 @@ package wails
import (
"github.com/wailsapp/wails/cmd"
"github.com/wailsapp/wails/cmd/frameworks"
)
// -------------------------------- Compile time Flags ------------------------------
@ -18,7 +17,6 @@ type App struct {
cli *cmd.Cli // In debug mode, we have a cli
renderer Renderer // The renderer is what we will render the app to
logLevel string // The log level of the app
headless bool // Indicates if the app should be started in headless mode
ipc *ipcManager // Handles the IPC calls
log *CustomLogger // Logger
bindingManager *bindingManager // Handles binding of Go code to renderer
@ -84,7 +82,7 @@ func (a *App) start() error {
a.log.Info("Starting")
// Check if we are to run in headless mode
if a.headless {
if DebugMode == "true" {
a.renderer = &Headless{}
}
@ -109,11 +107,6 @@ func (a *App) start() error {
return err
}
// Inject framework, if specified
if frameworks.FrameworkToUse != nil {
a.renderer.InjectFramework(frameworks.FrameworkToUse.JS, frameworks.FrameworkToUse.CSS)
}
// Inject CSS
a.renderer.AddCSSList(a.cssCache)

View File

@ -15,7 +15,7 @@ func (app *App) setupCli() *cmd.Cli {
// Setup cli to handle loglevel and headless flags
result.
StringFlag("loglevel", "Sets the log level [debug|info|error|panic|fatal]. Default debug", &app.logLevel).
BoolFlag("headless", "Runs the app in headless mode", &app.headless).
// BoolFlag("headless", "Runs the app in headless mode", &app.headless).
Action(app.start)
// Banner

View File

@ -1,214 +0,0 @@
/*
Wails Bridge (c) 2019-present Lea Anthony
This library creates a bridge between your application
and the frontend, allowing you to develop your app using
standard tooling (browser extensions, live reload, etc).
Usage:
```
import Bridge from "./wailsbridge";
Bridge.Start(startApp);
```
The given callback (startApp in the example) will be called
when the bridge has successfully initialised. It passes the
window.wails object back, in case it is not accessible directly.
*/
// Bridge object
window.wailsbridge = {
reconnectOverlay: null,
reconnectTimer: 300,
wsURL: "ws://localhost:34115/bridge",
connectionState: null,
config: {},
websocket: null,
callback: null,
overlayHTML:
'<div class="wails-reconnect-overlay"><div class="wails-reconnect-overlay-content"><div class="wails-reconnect-overlay-title">Wails Bridge</div><br><div class="wails-reconnect-overlay-loadingspinner"></div><br><div id="wails-reconnect-overlay-message">Waiting for backend</div></div></div>',
overlayCSS:
".wails-reconnect-overlay{position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,.6);font-family:sans-serif;display:none;z-index:999999}.wails-reconnect-overlay-content{padding:20px 30px;text-align:center;width:20em;position:relative;height:14em;border-radius:1em;margin:5% auto 0;background-color:#fff;box-shadow:1px 1px 20px 3px;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC8AAAAuCAMAAACPpbA7AAAAqFBMVEUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEBAQAAAAAAAAEBAQAAAAAAAAAAAAEBAQEBAQDAwMBAQEAAAABAQEAAAAAAAAAAAABAQEAAAAAAAACAgICAgIBAQEAAAAAAAAAAAAAAAAAAAAAAAABAQEAAAACAgIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFBQWKCj6oAAAAN3RSTlMALiIqDhkGBAswJjP0GxP6NR4W9/ztjRDMhWU50G9g5eHXvbZ9XEI9xZTcqZl2aldKo55QwoCvZUgzhAAAAs9JREFUSMeNleeWqjAUhU0BCaH3Itiw9zKT93+zG02QK1hm/5HF+jzZJ6fQe6cyXE+jg9X7o9wxuylIIf4Tv2V3+bOrEXnf8dwQ/KQIGDN2/S+4OmVCVXL/ScBnfibxURqIByP/hONE8r8T+bDMlQ98KSl7Y8hzjpS8v1qtDh8u5f8KQpGpfnPPhqG8JeogN37Hq9eaN2xRhIwAaGnvws8F1ShxqK5ob2twYi1FAMD4rXsYtnC/JEiRbl4cUrCWhnMCLRFemXezXbb59QK4WASOsm6n2W1+4CBT2JmtzQ6fsrbGubR/NFbd2g5Y179+5w/GEHaKsHjYCet7CgrXU3txarNC7YxOVJtIj4/ERzMdZfzc31hp+8cD6eGILgarZY9uZ12hAs03vfBD9C171gS5Omz7OcvxALQIn4u8RRBBBcsi9WW2woO9ipLgfzpYlggg3ZRdROUC8KT7QLqq3W9KB5BbdFVg4929kdwp6+qaZnMCCNBdj+NyN1W885Ry/AL3D4AQbsVV4noCiM/C83kyYq80XlDAYQtralOiDzoRAHlotWl8q2tjvYlOgcg1A8jEApZa+C06TBdAz2Qv0wu11I/zZOyJQ6EwGez2P2b8PIQr1hwwnAZsAxwA4UAYOyXUxM/xp6tHAn4GUmPGM9R28oVxgC0e/zQJJI6DyhyZ1r7uzRQhpcW7x7vTaWSzKSG6aep77kroTEl3U81uSVaUTtgEINfC8epx+Q4F9SpplHG84Ek6m4RAq9/TLkOBrxyeuddZhHvGIp1XXfFy3Z3vtwNblKGiDn+J+92vwwABHghj7HnzlS1H5kB49AZvdGCFgiBPq69qfXPr3y++yilF0ON4R8eR7spAsLpZ95NqAW5tab1c4vkZm6aleajchMwYTdILQQTwE2OV411ZM9WztDjPql12caBi6gDpUKmDd4U1XNdQxZ4LIXQ5/Tr4P7I9tYcFrDK3AAAAAElFTkSuQmCC);background-repeat:no-repeat;background-position:center}.wails-reconnect-overlay-title{font-size:2em}.wails-reconnect-overlay-message{font-size:1.3em}.wails-reconnect-overlay-loadingspinner{pointer-events:none;width:2.5em;height:2.5em;border:.4em solid transparent;border-color:#3E67EC #eee #eee;border-radius:50%;animation:loadingspin 1s linear infinite;margin:auto;padding:2.5em}@keyframes loadingspin{100%{transform:rotate(360deg)}}",
log: function (message) {
console.log(
"%c wails bridge %c " + message + " ",
"background: #aa0000; color: #fff; border-radius: 3px 0px 0px 3px; padding: 1px; font-size: 0.7rem",
"background: #009900; color: #fff; border-radius: 0px 3px 3px 0px; padding: 1px; font-size: 0.7rem"
);
}
};
// Adapted from webview - thanks zserge!
function injectCSS(css) {
var elem = document.createElement("style");
elem.setAttribute("type", "text/css");
if (elem.styleSheet) {
elem.styleSheet.cssText = css;
} else {
elem.appendChild(document.createTextNode(css));
}
var head = document.head || document.getElementsByTagName("head")[0];
head.appendChild(elem);
}
// Creates a node in the Dom
function createNode(parent, elementType, id, className, content) {
var d = document.createElement(elementType);
if (id) {
d.id = id;
}
if (className) {
d.className = className;
}
if (content) {
d.innerHTML = content;
}
parent.appendChild(d);
return d;
}
// Sets up the overlay
function setupOverlay() {
var body = document.body;
var wailsBridgeNode = createNode(body, "div", "wails-bridge");
wailsBridgeNode.innerHTML = window.wailsbridge.overlayHTML;
// Inject the overlay CSS
injectCSS(window.wailsbridge.overlayCSS);
}
// Start the Wails Bridge
function startBridge() {
// Setup the overlay
setupOverlay();
window.wailsbridge.websocket = null;
window.wailsbridge.connectTimer = null;
window.wailsbridge.reconnectOverlay = document.querySelector(
".wails-reconnect-overlay"
);
window.wailsbridge.connectionState = "disconnected";
// Shows the overlay
function showReconnectOverlay() {
window.wailsbridge.reconnectOverlay.style.display = "block";
}
// Hides the overlay
function hideReconnectOverlay() {
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.
// Removes it if second parameter is true.
function addScript(script, remove) {
var s = document.createElement("script");
s.textContent = script;
document.head.appendChild(s);
// Remove internal messages from the DOM
if (remove) {
s.parentNode.removeChild(s);
}
}
// Handles incoming websocket connections
function handleConnect() {
window.wailsbridge.log("Connected to backend");
hideReconnectOverlay();
clearInterval(window.wailsbridge.connectTimer);
window.wailsbridge.websocket.onclose = handleDisconnect;
window.wailsbridge.websocket.onmessage = handleMessage;
window.wailsbridge.connectionState = "connected";
}
// Handles websocket disconnects
function handleDisconnect() {
window.wailsbridge.log("Disconnected from backend");
window.wailsbridge.websocket = null;
window.wailsbridge.connectionState = "disconnected";
showReconnectOverlay();
connect();
}
// Try to connect to the backend every 300ms (default value).
// Change this value in the main wailsbridge object.
function connect() {
window.wailsbridge.connectTimer = setInterval(function () {
if (window.wailsbridge.websocket == null) {
window.wailsbridge.websocket = new WebSocket(window.wailsbridge.wsURL);
window.wailsbridge.websocket.onopen = handleConnect;
window.wailsbridge.websocket.onerror = function (e) {
e.stopImmediatePropagation();
e.stopPropagation();
e.preventDefault();
window.wailsbridge.websocket = null;
return false;
};
}
}, window.wailsbridge.reconnectTimer);
}
function handleMessage(message) {
// As a bridge we ignore js and css injections
switch (message.data[0]) {
// Wails library - inject!
case "w":
addScript(message.data.slice(1));
// Now wails runtime is loaded, wails for the ready event
// and callback to the main app
window.wails.events.on("wails:loaded", function () {
window.wailsbridge.log("Wails Ready");
if (window.wailsbridge.callback) {
window.wailsbridge.log("Notifying application");
window.wailsbridge.callback(window.wails);
}
});
window.wailsbridge.log("Loaded Wails Runtime");
break;
// Notifications
case "n":
addScript(message.data.slice(1), true);
break;
// Binding
case "b":
var binding = message.data.slice(1)
//log("Binding: " + binding)
window.wails._.newBinding(binding);
break;
// Call back
case "c":
var callbackData = message.data.slice(1);
log("Callback = " + callbackData);
window.wails._.callback(callbackData);
break;
}
}
// Start by showing the overlay...
showReconnectOverlay();
// ...and attempt to connect
connect();
}
export default {
// The main function
// Passes the main Wails object to the callback if given.
Start: function (callback) {
// Save the callback
window.wailsbridge.callback = callback;
// Start Bridge
startBridge();
}
};

View File

@ -1,15 +0,0 @@
/*
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) {
return callback();
}
};

File diff suppressed because one or more lines are too long

View File

@ -12,7 +12,8 @@
```
The given callback (startApp in the example) will be called
when the bridge has successfully initialised.
when the bridge has successfully initialised. It passes the
window.wails object back, in case it is not accessible directly.
*/
// Bridge object
@ -169,7 +170,7 @@ function startBridge() {
window.wailsbridge.log("Wails Ready");
if (window.wailsbridge.callback) {
window.wailsbridge.log("Notifying application");
window.wailsbridge.callback();
window.wailsbridge.callback(window.wails);
}
});
window.wailsbridge.log("Loaded Wails Runtime");
@ -181,13 +182,13 @@ function startBridge() {
// Binding
case "b":
var binding = message.data.slice(1);
//window.wailsbridge.log("Binding: " + binding)
//log("Binding: " + binding)
window.wails._.newBinding(binding);
break;
// Call back
case "c":
var callbackData = message.data.slice(1);
// window.wailsbridge.log("Callback = " + callbackData);
log("Callback = " + callbackData);
window.wails._.callback(callbackData);
break;
}

View File

@ -10,6 +10,8 @@ export default {
// The main function
// Passes the main Wails object to the callback if given.
Start: function(callback) {
return callback();
if (callback) {
callback();
}
}
};

View File

@ -1,229 +0,0 @@
<html>
<head>
<title>Wails Headless</title>
<style>
.wails-reconnect-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.6);
font-family: sans-serif;
display: none;
z-index: 999999;
}
.wails-reconnect-overlay-content {
padding: 20px 30px;
text-align: center;
width: 20em;
position: relative;
height: 14em;
border-radius: 1em;
margin: 5% auto 0;
background-color: white;
box-shadow: 1px 1px 20px 3px;
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC8AAAAuCAMAAACPpbA7AAAAqFBMVEUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEBAQAAAAAAAAEBAQAAAAAAAAAAAAEBAQEBAQDAwMBAQEAAAABAQEAAAAAAAAAAAABAQEAAAAAAAACAgICAgIBAQEAAAAAAAAAAAAAAAAAAAAAAAABAQEAAAACAgIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFBQWKCj6oAAAAN3RSTlMALiIqDhkGBAswJjP0GxP6NR4W9/ztjRDMhWU50G9g5eHXvbZ9XEI9xZTcqZl2aldKo55QwoCvZUgzhAAAAs9JREFUSMeNleeWqjAUhU0BCaH3Itiw9zKT93+zG02QK1hm/5HF+jzZJ6fQe6cyXE+jg9X7o9wxuylIIf4Tv2V3+bOrEXnf8dwQ/KQIGDN2/S+4OmVCVXL/ScBnfibxURqIByP/hONE8r8T+bDMlQ98KSl7Y8hzjpS8v1qtDh8u5f8KQpGpfnPPhqG8JeogN37Hq9eaN2xRhIwAaGnvws8F1ShxqK5ob2twYi1FAMD4rXsYtnC/JEiRbl4cUrCWhnMCLRFemXezXbb59QK4WASOsm6n2W1+4CBT2JmtzQ6fsrbGubR/NFbd2g5Y179+5w/GEHaKsHjYCet7CgrXU3txarNC7YxOVJtIj4/ERzMdZfzc31hp+8cD6eGILgarZY9uZ12hAs03vfBD9C171gS5Omz7OcvxALQIn4u8RRBBBcsi9WW2woO9ipLgfzpYlggg3ZRdROUC8KT7QLqq3W9KB5BbdFVg4929kdwp6+qaZnMCCNBdj+NyN1W885Ry/AL3D4AQbsVV4noCiM/C83kyYq80XlDAYQtralOiDzoRAHlotWl8q2tjvYlOgcg1A8jEApZa+C06TBdAz2Qv0wu11I/zZOyJQ6EwGez2P2b8PIQr1hwwnAZsAxwA4UAYOyXUxM/xp6tHAn4GUmPGM9R28oVxgC0e/zQJJI6DyhyZ1r7uzRQhpcW7x7vTaWSzKSG6aep77kroTEl3U81uSVaUTtgEINfC8epx+Q4F9SpplHG84Ek6m4RAq9/TLkOBrxyeuddZhHvGIp1XXfFy3Z3vtwNblKGiDn+J+92vwwABHghj7HnzlS1H5kB49AZvdGCFgiBPq69qfXPr3y++yilF0ON4R8eR7spAsLpZ95NqAW5tab1c4vkZm6aleajchMwYTdILQQTwE2OV411ZM9WztDjPql12caBi6gDpUKmDd4U1XNdQxZ4LIXQ5/Tr4P7I9tYcFrDK3AAAAAElFTkSuQmCC");
background-repeat: no-repeat;
background-position: center;
}
.wails-reconnect-overlay-title {
font-size: 2em;
}
.wails-reconnect-overlay-message {
font-size: 1.3em;
}
/* https://codepen.io/EastingAndNorthing/pen/aNWrZz - Cheers Mark! */
.wails-reconnect-overlay-loadingspinner {
pointer-events: none;
width: 2.5em;
height: 2.5em;
border: 0.4em solid transparent;
border-color: #eee;
border-top-color: #3E67EC;
border-radius: 50%;
animation: loadingspin 1s linear infinite;
margin: auto;
padding: 2.5em;
}
@keyframes loadingspin {
100% {
transform: rotate(360deg)
}
}
</style>
</head>
<body>
<div class="wails-reconnect-overlay">
<div class="wails-reconnect-overlay-content">
<div class="wails-reconnect-overlay-title">Disconnected</div><br>
<div class="wails-reconnect-overlay-loadingspinner"></div><br>
<div class="wails-reconnect-overlay-message">Waiting for backend</div>
</div>
</div>
<div id="app"></div>
<script id="wails-headless-runtime">
(function () {
var websocket = null;
var connectTimer = null;
var reconnectOverlay = document.querySelector(".wails-reconnect-overlay");
var connectionState = "disconnected";
function showReconnectOverlay() {
reconnectOverlay.style.display = 'block';
}
function hideReconnectOverlay() {
reconnectOverlay.style.display = 'none';
}
window.external = {
invoke: function (msg) {
websocket.send(msg);
}
};
// Adds a script to the Dom.
// Removes it if second parameter is true.
function addScript(script, remove) {
var s = document.createElement("script");
s.textContent = script;
document.head.appendChild(s);
// Remove internal messages from the DOM
if (remove) {
s.parentNode.removeChild(s);
}
}
// Adapted from webview - thanks zserge!
function injectCSS(css) {
var elem = document.createElement("style");
elem.setAttribute("type", "text/css");
if (elem.styleSheet) {
elem.styleSheet.cssText = css;
} else {
elem.appendChild(document.createTextNode(css));
}
var head = document.head || document.getElementsByTagName("head")[0];
head.appendChild(elem);
}
function handleConnect() {
log("Connected to backend");
hideReconnectOverlay();
clearInterval(connectTimer);
websocket.onclose = handleDisconnect;
websocket.onmessage = handleMessage;
connectionState = "connected";
// websocket.onerror = function () { }
}
function handleDisconnect() {
log("Disconnected from backend");
websocket = null;
connectionState = "disconnected";
showReconnectOverlay();
connect();
}
function connect() {
connectTimer = setInterval(function () {
if (websocket == null) {
websocket = new WebSocket("ws://localhost:34115/ws")
websocket.onopen = handleConnect;
websocket.onerror = function (e) {
e.stopImmediatePropagation();
e.stopPropagation();
e.preventDefault();
websocket = null;
return false
}
}
}, 300);
}
function log(message) {
console.log(
"%c wails headless %c " + message + " ",
"background: #aa0000; color: #fff; border-radius: 3px 0px 0px 3px; padding: 1px; font-size: 0.7rem",
"background: #009900; color: #fff; border-radius: 0px 3px 3px 0px; padding: 1px; font-size: 0.7rem"
);
}
function handleMessage(message) {
// As a bridge we ignore js and css injections
debugger;
switch (message.data[0]) {
// Wails library - inject!
case "w":
addScript(message.data.slice(1));
// Now wails runtime is loaded, wails for the ready event
// and callback to the main app
window.wails.events.on("wails:loaded", function () {
log("Wails Ready");
});
log("Loaded Wails Runtime");
break;
// Notification
case "n":
log("Notification: " + message.data.slice(1))
addScript(message.data.slice(1), true);
break;
// Binding
case "b":
var binding = message.data.slice(1)
//log("Binding: " + binding)
window.wails._.newBinding(binding);
break;
// Call back
case "c":
var callbackData = message.data.slice(1);
log("Callback = " + callbackData);
window.wails._.callback(callbackData);
break;
// CSS
case "s":
addScript(message.data.slice(1), true);
break;
// JS
case "j":
addScript(message.data.slice(1));
break;
// HTML
case "h":
addScript(message.data.slice(1), true);
break;
default:
log("Ignored message: " + message.data.slice(0, 100))
}
}
connect();
}());
</script>
</body>
</html>

View File

@ -1,69 +0,0 @@
package cmd
import (
"encoding/json"
"io/ioutil"
"path"
"path/filepath"
"runtime"
)
// FrameworkMetadata contains information about a given framework
type FrameworkMetadata struct {
Name string `json:"name"`
BuildTag string `json:"buildtag"`
Description string `json:"description"`
}
// Utility function for creating new FrameworkMetadata structs
func loadFrameworkMetadata(pathToMetadataJSON string) (*FrameworkMetadata, error) {
result := &FrameworkMetadata{}
configData, err := ioutil.ReadFile(pathToMetadataJSON)
if err != nil {
return nil, err
}
// Load and unmarshall!
err = json.Unmarshal(configData, result)
if err != nil {
return nil, err
}
return result, nil
}
// GetFrameworks returns information about all the available frameworks
func GetFrameworks() ([]*FrameworkMetadata, error) {
var err error
// Calculate framework base dir
_, filename, _, _ := runtime.Caller(1)
frameworksBaseDir := filepath.Join(path.Dir(filename), "frameworks")
// Get the subdirectories
fs := NewFSHelper()
frameworkDirs, err := fs.GetSubdirs(frameworksBaseDir)
if err != nil {
return nil, err
}
// Prepare result
result := []*FrameworkMetadata{}
// Iterate framework directories, looking for metadata.json files
for _, frameworkDir := range frameworkDirs {
var frameworkMetadata FrameworkMetadata
metadataFile := filepath.Join(frameworkDir, "metadata.json")
jsonData, err := ioutil.ReadFile(metadataFile)
if err != nil {
return nil, err
}
err = json.Unmarshal(jsonData, &frameworkMetadata)
if err != nil {
return nil, err
}
result = append(result, &frameworkMetadata)
}
// Read in framework metadata
return result, nil
}

File diff suppressed because one or more lines are too long

View File

@ -1,16 +0,0 @@
// +build frameworkbootstrap4
package frameworks
import (
"github.com/gobuffalo/packr"
)
func init() {
assets := packr.NewBox("./bootstrap4default/assets")
FrameworkToUse = &Framework{
Name: "Bootstrap 4",
JS: BoxString(&assets, "bootstrap.bundle.min.js"),
CSS: BoxString(&assets, "bootstrap.min.css"),
}
}

File diff suppressed because one or more lines are too long

View File

@ -1,22 +0,0 @@
The MIT License (MIT)
Copyright (c) 2011-2018 Twitter, Inc.
Copyright (c) 2011-2018 The Bootstrap Authors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,17 +0,0 @@
// +build frameworkbootstrap4
package bootstrap4
import (
"github.com/gobuffalo/packr"
"github.com/wailsapp/wails/frameworks"
)
func init() {
assets := packr.NewBox("./assets")
frameworks.FrameworkToUse = &frameworks.Framework{
Name: "Bootstrap 4",
JS: BoxString(&assets, "bootstrap.bundle.min.js"),
CSS: BoxString(&assets, "bootstrap.min.css"),
}
}

View File

@ -1,5 +0,0 @@
{
"Name": "Bootstrap 4",
"Description": "Standard Bootstrap 4 with default theme",
"BuildTag": "frameworkbootstrap4"
}

View File

@ -1,16 +0,0 @@
// +build frameworkbootstrap4lux
package frameworks
import (
"github.com/gobuffalo/packr"
)
func init() {
assets := packr.NewBox("./bootstrap4lux/assets")
FrameworkToUse = &Framework{
Name: "Bootstrap 4 (Lux)",
JS: BoxString(&assets, "bootstrap.bundle.min.js"),
CSS: BoxString(&assets, "bootstrap.min.css"),
}
}

File diff suppressed because one or more lines are too long

View File

@ -1,22 +0,0 @@
The MIT License (MIT)
Copyright (c) 2011-2018 Twitter, Inc.
Copyright (c) 2011-2018 The Bootstrap Authors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,17 +0,0 @@
// +build frameworkbootstrap4lux
package bootstrap4
import (
"github.com/gobuffalo/packr"
"github.com/wailsapp/wails/frameworks"
)
func init() {
assets := packr.NewBox("./assets")
frameworks.FrameworkToUse = &frameworks.Framework{
Name: "Bootstrap 4 (Lux)",
JS: BoxString(&assets, "bootstrap.bundle.min.js"),
CSS: BoxString(&assets, "bootstrap.min.css"),
}
}

View File

@ -1,5 +0,0 @@
{
"Name": "Bootstrap 4 (Lux)",
"Description": "Bootstrap with Lux theme",
"BuildTag": "frameworkbootstrap4lux"
}

View File

@ -1,28 +0,0 @@
package frameworks
import (
"log"
"github.com/gobuffalo/packr"
)
// Framework has details about a specific framework
type Framework struct {
Name string
JS string
CSS string
Options string
}
// FrameworkToUse is the framework we will use when building
// Set by `wails init`, used by `wails build`
var FrameworkToUse *Framework
// BoxString extracts a string from a packr box
func BoxString(box *packr.Box, filename string) string {
result, err := box.FindString(filename)
if err != nil {
log.Fatal(err)
}
return result
}

View File

@ -19,6 +19,7 @@ type frontend struct {
Dir string `json:"dir"`
Install string `json:"install"`
Build string `json:"build"`
Bridge string `json:"bridge"`
}
type framework struct {
@ -161,7 +162,6 @@ type ProjectOptions struct {
BinaryName string `json:"binaryname"`
FrontEnd *frontend `json:"frontend,omitempty"`
NPMProjectName string `json:"-"`
Framework *framework `json:"framework,omitempty"`
system *SystemHelper
log *Logger
templates *TemplateHelper
@ -251,38 +251,6 @@ func (po *ProjectOptions) PromptForInputs() error {
// Setup NPM Project name
po.NPMProjectName = strings.ToLower(strings.Replace(po.Name, " ", "_", -1))
// If we selected custom, prompt for framework
if po.Template == "custom - Choose your own CSS Framework" {
// Ask for the framework
var frameworkName string
frameworks, err := GetFrameworks()
frameworkNames := []string{}
metadataMap := make(map[string]*FrameworkMetadata)
for _, frameworkMetadata := range frameworks {
frameworkDetails := fmt.Sprintf("%s - %s", frameworkMetadata.Name, frameworkMetadata.Description)
metadataMap[frameworkDetails] = frameworkMetadata
frameworkNames = append(frameworkNames, frameworkDetails)
}
if err != nil {
return err
}
var frameworkQuestion []*survey.Question
frameworkQuestion = append(frameworkQuestion, SelectQuestion("Framework", "Select framework", frameworkNames, frameworkNames[0], true))
err = survey.Ask(frameworkQuestion, &frameworkName)
if err != nil {
return err
}
// Get metadata
metadata := metadataMap[frameworkName]
// Add to project config
po.Framework = &framework{
Name: metadata.Name,
BuildTag: metadata.BuildTag,
}
}
// Fix template name
if po.templateNameMap[po.Template] != "" {
po.Template = po.templateNameMap[po.Template]
@ -306,6 +274,12 @@ func (po *ProjectOptions) PromptForInputs() error {
}
po.FrontEnd.Build = templateMetadata["build"].(string)
}
if templateMetadata["bridge"] != nil {
if po.FrontEnd == nil {
return fmt.Errorf("bridge set in template metadata but not frontenddir")
}
po.FrontEnd.Bridge = templateMetadata["bridge"].(string)
}
return nil
}

View File

@ -1,8 +0,0 @@
<div style="text-align:center">
<div
class="wails-logo"
style="width: 25rem;margin: auto;height: 25rem;"
></div>
<h1>Basic Template</h1>
Welcome to your basic Wails app!
</div>

View File

@ -1 +0,0 @@
module {{.BinaryName}}

View File

@ -1,21 +0,0 @@
package main
import (
"github.com/gobuffalo/packr"
wails "github.com/wailsapp/wails"
)
func main() {
// Assets
assets := packr.NewBox("./frontend")
// Initialise the app
app := wails.CreateApp(&wails.AppConfig{
Width: 1024,
Height: 768,
Title: "{{.Name}}",
HTML: wails.BoxString(&assets, "main.html"),
})
app.Run()
}

View File

@ -1,7 +0,0 @@
{
"name": "Basic",
"shortdescription": "A basic template",
"description": "A basic template using vanilla JS",
"author": "Lea Anthony<lea.anthony@gmail.com>",
"created": "2018-10-18"
}

View File

@ -1,8 +0,0 @@
<div style="text-align:center">
<div
class="wails-logo"
style="width: 25rem;margin: auto;height: 25rem;"
></div>
<h1>Custom CSS Template</h1>
Welcome to your basic Wails app with custom CSS!
</div>

View File

@ -1 +0,0 @@
module {{.BinaryName}}

View File

@ -1,21 +0,0 @@
package main
import (
"github.com/gobuffalo/packr"
wails "github.com/wailsapp/wails"
)
func main() {
// Assets
assets := packr.NewBox("./frontend")
// Initialise the app
app := wails.CreateApp(&wails.AppConfig{
Width: 1024,
Height: 768,
Title: "{{.Name}}",
HTML: wails.BoxString(&assets, "main.html"),
})
app.Run()
}

View File

@ -1,7 +0,0 @@
{
"name": "Custom",
"shortdescription": "Choose your own CSS Framework",
"description": "A basic template allowing use of CSS Frameworks",
"author": "Lea Anthony<lea.anthony@gmail.com>",
"created": "2018-10-22"
}

View File

@ -25,7 +25,11 @@ export default {
}
},
created() {
if( !backend ) {
eventBus.$on("ready", this.getNewQuote);
} else {
this.getNewQuote();
}
}
};
</script>

View File

@ -7,8 +7,7 @@ new Vue({
}).$mount("#app");
import Bridge from "./wailsbridge";
Bridge.Start(startApp);
function startApp() {
Bridge.OnReady(() => {
eventBus.$emit("ready");
}
});
Bridge.Start();

View File

@ -6,5 +6,6 @@
"created": "2018-12-01",
"frontenddir": "frontend",
"install": "npm install",
"build": "npm run build"
"build": "npm run build",
"bridge": "src"
}

View File

@ -4,6 +4,9 @@ import (
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
"runtime"
"github.com/leaanthony/slicer"
"github.com/leaanthony/spinner"
@ -56,6 +59,10 @@ func init() {
if projectOptions.FrontEnd.Install == "" {
return fmt.Errorf("Frontend install command not set in project.json")
}
if projectOptions.FrontEnd.Bridge == "" {
return fmt.Errorf("Frontend bridge config not set in project.json")
}
}
// Check pre-requisites are installed
@ -137,6 +144,22 @@ func init() {
ioutil.WriteFile(md5sumFile, []byte(packageJSONMD5), 0644)
}
// Determine which wails bridge to install
var bridgeFile = "wailsbridge.js"
if releaseMode || packageApp {
// Release mode
bridgeFile = "wailsbridge.prod.js"
}
// Copy bridge to project
_, filename, _, _ := runtime.Caller(1)
bridgeFileSource := filepath.Join(path.Dir(filename), "..", "assets", "default", bridgeFile)
bridgeFileTarget := filepath.Join(projectDir, projectOptions.FrontEnd.Dir, projectOptions.FrontEnd.Bridge, "wailsbridge.js")
err = fs.CopyFile(bridgeFileSource, bridgeFileTarget)
if err != nil {
return err
}
// Build frontend
buildFESpinner := spinner.New("Building frontend...")
buildFESpinner.SetSpinSpeed(50)
@ -158,26 +181,6 @@ func init() {
// Support build tags
buildTags := []string{}
// Do we have any frameworks specified?
frameworkSpinner := spinner.New()
frameworkSpinner.SetSpinSpeed(50)
if projectOptions.Framework != nil {
frameworkSpinner.Start()
frameworkSpinner.Success("Compiling support for " + projectOptions.Framework.Name)
buildTags = append(buildTags, projectOptions.Framework.BuildTag)
}
// // Initialise Go Module - if go.mod doesn't exist
// if !fs.FileExists("go.mod") {
// buildSpinner.Start("Initialising Go module...")
// err = program.RunCommand("go mod init " + projectOptions.BinaryName)
// if err != nil {
// buildSpinner.Error()
// return err
// }
// buildSpinner.Success()
// }
depSpinner := spinner.New("Installing Dependencies...")
depSpinner.SetSpinSpeed(50)
depSpinner.Start()

3
go.sum
View File

@ -13,6 +13,7 @@ github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dchest/cssmin v0.0.0-20151210170030-fb8d9b44afdc h1:VBS1z48BFEe00G81z8MKOtwX7f/ISkuH38NscT8iVPw=
github.com/dchest/cssmin v0.0.0-20151210170030-fb8d9b44afdc/go.mod h1:ABJPuor7YlcsHmvJ1QxX38e2NcufLY3hm0yXv+cy9sI=
@ -272,6 +273,7 @@ github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1Cpa
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.0.0 h1:o4VLZ5jqHE+HahLT6drNtSGTrrUA3wPBmtpgqtdbClo=
github.com/rogpeppe/go-internal v1.0.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
@ -302,6 +304,7 @@ github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnIn
github.com/spf13/viper v1.2.1/go.mod h1:P4AexN0a+C9tGAnUFNwDMYYZv3pjFuvmeiMyKRaNVlI=
github.com/spf13/viper v1.3.1/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/unrolled/secure v0.0.0-20180918153822-f340ee86eb8b/go.mod h1:mnPT77IAdsi/kV7+Es7y+pXALeV3h7G6dQF6mNYjcLA=

View File

@ -13,7 +13,6 @@ type Renderer interface {
NotifyEvent(eventData *eventData) error
// Injection
InjectFramework(js string, css string)
AddJSList(js []string)
AddCSSList(css []string)

View File

@ -11,7 +11,6 @@ import (
"github.com/gorilla/websocket"
)
var headlessAssets = packr.NewBox("./assets/headless")
var defaultAssets = packr.NewBox("./assets/default")
type messageType int
@ -48,8 +47,6 @@ type Headless struct {
initialisationJS []string
server *http.Server
theConnection *websocket.Conn
bridgeMode bool
connectionType string
}
// Initialise the Headless Renderer
@ -57,9 +54,6 @@ func (h *Headless) Initialise(appConfig *AppConfig, ipcManager *ipcManager, even
h.ipcManager = ipcManager
h.appConfig = appConfig
h.eventManager = eventManager
h.bridgeMode = false
h.connectionType = "Websocket"
ipcManager.bindRenderer(h)
h.log = newCustomLogger("Headless")
return nil
@ -95,26 +89,15 @@ func (h *Headless) injectCSS(css string) {
h.evalJS(inject, cssMessage)
}
func (h *Headless) rootHandler(w http.ResponseWriter, r *http.Request) {
indexHTML := BoxString(&headlessAssets, "index.html")
fmt.Fprintf(w, "%s", indexHTML)
}
func (h *Headless) wsBridgeHandler(w http.ResponseWriter, r *http.Request) {
h.bridgeMode = true
h.connectionType = "Bridge"
h.wsHandler(w, r)
}
func (h *Headless) wsHandler(w http.ResponseWriter, r *http.Request) {
conn, err := websocket.Upgrade(w, r, w.Header(), 1024, 1024)
if err != nil {
http.Error(w, "Could not open websocket connection", http.StatusBadRequest)
}
h.theConnection = conn
h.log.Infof("%s connection accepted [%p].", h.connectionType, h.theConnection)
h.log.Infof("Connection from frontend accepted.", h.theConnection)
conn.SetCloseHandler(func(int, string) error {
h.log.Infof("%s connection dropped [%p].", h.connectionType, h.theConnection)
h.log.Infof("Connection dropped [%p].", h.theConnection)
h.theConnection = nil
return nil
})
@ -127,73 +110,14 @@ func (h *Headless) sendMessage(conn *websocket.Conn, msg string) {
}
}
func (h *Headless) injectAllFiles() {
// Inject Framework
if h.frameworkJS != "" {
h.evalJS(h.frameworkJS, jsMessage)
}
if h.frameworkCSS != "" {
h.injectCSS(h.frameworkCSS)
}
// Inject user CSS
if h.appConfig.CSS != "" {
outputCSS := fmt.Sprintf("%.45s", h.appConfig.CSS)
if len(outputCSS) > 45 {
outputCSS += "..."
}
h.log.DebugFields("Inject User CSS", Fields{"css": outputCSS})
h.injectCSS(h.appConfig.CSS)
} else {
// Use default wails css
h.log.Debug("Injecting Default Wails CSS")
defaultCSS := BoxString(&defaultAssets, "wails.css")
h.injectCSS(defaultCSS)
}
// Inject all the CSS files that have been added
for _, css := range h.cssCache {
h.injectCSS(css)
}
// Inject all the JS files that have been added
for _, js := range h.jsCache {
h.evalJS(js, jsMessage)
}
// Inject user JS
if h.appConfig.JS != "" {
outputJS := fmt.Sprintf("%.45s", h.appConfig.JS)
if len(outputJS) > 45 {
outputJS += "..."
}
h.log.DebugFields("Inject User JS", Fields{"js": outputJS})
h.evalJS(h.appConfig.JS, jsMessage)
}
var injectHTML string
if h.appConfig.isHTMLFragment {
injectHTML = fmt.Sprintf("$('#app').html('%s')", h.appConfig.HTML)
h.evalJS(injectHTML, htmlMessage)
}
}
func (h *Headless) start(conn *websocket.Conn) {
// set external.invoke
h.log.Infof("Connected to frontend.")
h.log.Infof("Mode = %s", h.connectionType)
wailsRuntime := BoxString(&defaultAssets, "wails.js")
h.evalJS(wailsRuntime, wailsRuntimeMessage)
if !h.bridgeMode {
// Inject jquery
jquery := BoxString(&defaultAssets, "jquery.3.3.1.min.js")
h.evalJS(jquery, jsMessage)
}
// Inject the initial JS
for _, js := range h.initialisationJS {
h.sendMessage(h.theConnection, js)
@ -204,11 +128,6 @@ func (h *Headless) start(conn *websocket.Conn) {
h.evalJS(binding, bindingMessage)
}
// In standard headless mode, we send all of the files
if !h.bridgeMode {
h.injectAllFiles()
}
// Emit that everything is loaded and ready
h.eventManager.Emit("wails:ready")
@ -231,13 +150,10 @@ func (h *Headless) start(conn *websocket.Conn) {
// Run the app in headless mode!
func (h *Headless) Run() error {
h.server = &http.Server{Addr: ":34115"}
http.HandleFunc("/ws", h.wsHandler)
http.HandleFunc("/bridge", h.wsBridgeHandler)
http.HandleFunc("/", h.rootHandler)
h.log.Info("Headless mode started.")
h.log.Info("If using the Wails bridge, it will connect automatically.")
h.log.Info("You may also connect manually by browsing to http://localhost:34115")
h.log.Info("The Wails bridge will connect automatically.")
err := h.server.ListenAndServe()
if err != nil {
@ -252,13 +168,6 @@ func (h *Headless) NewBinding(methodName string) error {
return nil
}
// InjectFramework sets up what JS/CSS should be injected
// at startup
func (h *Headless) InjectFramework(js, css string) {
h.frameworkJS = js
h.frameworkCSS = css
}
// SelectFile is unsupported for Headless but required
// for the Renderer interface
func (h *Headless) SelectFile() string {

View File

@ -171,10 +171,6 @@ func (w *webViewRenderer) Run() error {
// Run this in a different go routine to free up the main process
go func() {
// Will we mount a custom component
// Inject jquery
jquery := BoxString(&assets, "jquery.3.3.1.min.js")
w.evalJSSync(jquery)
// Inject Bindings
for _, binding := range w.bindingCache {
@ -189,17 +185,6 @@ func (w *webViewRenderer) Run() error {
w.injectCSS(w.frameworkCSS)
}
// Do we have custom html?
// If given an HMTL fragment, mount it on #app
// Otherwise, replace the html tag
var injectHTML string
if w.config.isHTMLFragment {
injectHTML = fmt.Sprintf("$('#app').html('%s')", w.config.HTML)
} else {
injectHTML = fmt.Sprintf("$('html').html('%s')", w.config.HTML)
}
w.evalJSSync(injectHTML)
// Inject user CSS
if w.config.CSS != "" {
outputCSS := fmt.Sprintf("%.45s", w.config.CSS)
@ -254,11 +239,6 @@ func (w *webViewRenderer) NewBinding(methodName string) error {
return nil
}
func (w *webViewRenderer) InjectFramework(js, css string) {
w.frameworkJS = js
w.frameworkCSS = css
}
func (w *webViewRenderer) SelectFile() string {
var result string