mirror of
https://github.com/taigrr/wails.git
synced 2026-04-02 05:08:54 -07:00
Fix Packr deprecation errors
Improved comments
This commit is contained in:
@@ -85,7 +85,7 @@ func newAppConfig(userConfig *AppConfig) (*AppConfig, error) {
|
||||
Resizable: true,
|
||||
Title: "My Wails App",
|
||||
Colour: "#FFF", // White by default
|
||||
HTML: defaultAssets.String("default.html"),
|
||||
HTML: BoxString(&defaultAssets, "default.html"),
|
||||
}
|
||||
|
||||
if userConfig != nil {
|
||||
|
||||
@@ -10,7 +10,7 @@ func init() {
|
||||
assets := packr.NewBox("./bootstrap4default/assets")
|
||||
FrameworkToUse = &Framework{
|
||||
Name: "Bootstrap 4",
|
||||
JS: assets.String("bootstrap.bundle.min.js"),
|
||||
CSS: assets.String("bootstrap.min.css"),
|
||||
JS: BoxString(&assets, "bootstrap.bundle.min.js"),
|
||||
CSS: BoxString(&assets, "bootstrap.min.css"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ func init() {
|
||||
assets := packr.NewBox("./assets")
|
||||
frameworks.FrameworkToUse = &frameworks.Framework{
|
||||
Name: "Bootstrap 4",
|
||||
JS: assets.String("bootstrap.bundle.min.js"),
|
||||
CSS: assets.String("bootstrap.min.css"),
|
||||
JS: BoxString(&assets, "bootstrap.bundle.min.js"),
|
||||
CSS: BoxString(&assets, "bootstrap.min.css"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ func init() {
|
||||
assets := packr.NewBox("./bootstrap4lux/assets")
|
||||
FrameworkToUse = &Framework{
|
||||
Name: "Bootstrap 4 (Lux)",
|
||||
JS: assets.String("bootstrap.bundle.min.js"),
|
||||
CSS: assets.String("bootstrap.min.css"),
|
||||
JS: BoxString(&assets, "bootstrap.bundle.min.js"),
|
||||
CSS: BoxString(&assets, "bootstrap.min.css"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ func init() {
|
||||
assets := packr.NewBox("./assets")
|
||||
frameworks.FrameworkToUse = &frameworks.Framework{
|
||||
Name: "Bootstrap 4 (Lux)",
|
||||
JS: assets.String("bootstrap.bundle.min.js"),
|
||||
CSS: assets.String("bootstrap.min.css"),
|
||||
JS: BoxString(&assets, "bootstrap.bundle.min.js"),
|
||||
CSS: BoxString(&assets, "bootstrap.min.css"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,8 @@ func main() {
|
||||
Width: 1024,
|
||||
Height: 768,
|
||||
Title: "{{.Name}}",
|
||||
JS: assets.String("app.js"),
|
||||
CSS: assets.String("app.css"),
|
||||
JS: BoxString(&assets, "app.js"),
|
||||
CSS: BoxString(&assets, "app.css"),
|
||||
})
|
||||
app.Bind(newQuotesCollection())
|
||||
app.Run()
|
||||
|
||||
@@ -14,8 +14,8 @@ import (
|
||||
var headlessAssets = packr.NewBox("./assets/headless")
|
||||
var defaultAssets = packr.NewBox("./assets/default")
|
||||
|
||||
// Window defines the main application window
|
||||
// Default values in []
|
||||
// Headless is a backend that opens a local web server
|
||||
// and renders the files over a websocket
|
||||
type Headless struct {
|
||||
// Common
|
||||
log *CustomLogger
|
||||
@@ -34,6 +34,7 @@ type Headless struct {
|
||||
theConnection *websocket.Conn
|
||||
}
|
||||
|
||||
// Initialise the Headless Renderer
|
||||
func (h *Headless) Initialise(appConfig *AppConfig, ipcManager *ipcManager, eventManager *eventManager) error {
|
||||
h.ipcManager = ipcManager
|
||||
h.appConfig = appConfig
|
||||
@@ -68,7 +69,7 @@ func (h *Headless) injectCSS(css string) {
|
||||
}
|
||||
|
||||
func (h *Headless) rootHandler(w http.ResponseWriter, r *http.Request) {
|
||||
indexHTML := headlessAssets.String("index.html")
|
||||
indexHTML := BoxString(&headlessAssets, "index.html")
|
||||
fmt.Fprintf(w, "%s", indexHTML)
|
||||
}
|
||||
|
||||
@@ -102,11 +103,11 @@ func (h *Headless) start(conn *websocket.Conn) {
|
||||
// for the html() function
|
||||
if h.appConfig.isHTMLFragment {
|
||||
// Inject jquery
|
||||
jquery := defaultAssets.String("jquery.3.3.1.min.js")
|
||||
jquery := BoxString(&defaultAssets, "jquery.3.3.1.min.js")
|
||||
h.evalJS(jquery)
|
||||
}
|
||||
|
||||
wailsRuntime := defaultAssets.String("wails.js")
|
||||
wailsRuntime := BoxString(&defaultAssets, "wails.js")
|
||||
h.evalJS(wailsRuntime)
|
||||
|
||||
// Inject the initial JS
|
||||
@@ -199,32 +200,49 @@ func (h *Headless) Run() error {
|
||||
return err
|
||||
}
|
||||
|
||||
// NewBinding creates a new binding with the frontend
|
||||
func (h *Headless) NewBinding(methodName string) error {
|
||||
objectCode := fmt.Sprintf("window.wails._.newBinding(`%s`);", methodName)
|
||||
h.bindingCache = append(h.bindingCache, objectCode)
|
||||
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 {
|
||||
h.log.Error("SelectFile() unsupported in headless mode")
|
||||
return ""
|
||||
}
|
||||
|
||||
// SelectDirectory is unsupported for Headless but required
|
||||
// for the Renderer interface
|
||||
func (h *Headless) SelectDirectory() string {
|
||||
h.log.Error("SelectDirectory() unsupported in headless mode")
|
||||
return ""
|
||||
}
|
||||
|
||||
// SelectSaveFile is unsupported for Headless but required
|
||||
// for the Renderer interface
|
||||
func (h *Headless) SelectSaveFile() string {
|
||||
h.log.Error("SelectSaveFile() unsupported in headless mode")
|
||||
return ""
|
||||
}
|
||||
|
||||
// AddJSList adds a slice of JS strings to the list of js
|
||||
// files injected at startup
|
||||
func (h *Headless) AddJSList(jsCache []string) {
|
||||
h.jsCache = jsCache
|
||||
}
|
||||
|
||||
// AddCSSList adds a slice of CSS strings to the list of css
|
||||
// files injected at startup
|
||||
func (h *Headless) AddCSSList(cssCache []string) {
|
||||
h.cssCache = cssCache
|
||||
}
|
||||
@@ -235,6 +253,7 @@ func (h *Headless) Callback(data string) error {
|
||||
return h.evalJS(callbackCMD)
|
||||
}
|
||||
|
||||
// NotifyEvent notifies the frontend of an event
|
||||
func (h *Headless) NotifyEvent(event *eventData) error {
|
||||
|
||||
// Look out! Nils about!
|
||||
@@ -262,19 +281,33 @@ func (h *Headless) NotifyEvent(event *eventData) error {
|
||||
return h.evalJS(message)
|
||||
}
|
||||
|
||||
// SetColour is unsupported for Headless but required
|
||||
// for the Renderer interface
|
||||
func (h *Headless) SetColour(colour string) error {
|
||||
h.log.WarnFields("SetColour ignored for headless more", Fields{"col": colour})
|
||||
return nil
|
||||
}
|
||||
|
||||
// Fullscreen is unsupported for Headless but required
|
||||
// for the Renderer interface
|
||||
func (h *Headless) Fullscreen() {
|
||||
h.log.Warn("Fullscreen() unsupported in headless mode")
|
||||
}
|
||||
|
||||
// UnFullscreen is unsupported for Headless but required
|
||||
// for the Renderer interface
|
||||
func (h *Headless) UnFullscreen() {
|
||||
h.log.Warn("UnFullscreen() unsupported in headless mode")
|
||||
}
|
||||
|
||||
// SetTitle is currently unsupported for Headless but required
|
||||
// for the Renderer interface
|
||||
func (h *Headless) SetTitle(title string) {
|
||||
h.log.WarnFields("SetTitle() unsupported in headless mode", Fields{"title": title})
|
||||
}
|
||||
|
||||
// Close is unsupported for Headless but required
|
||||
// for the Renderer interface
|
||||
func (h *Headless) Close() {
|
||||
h.log.Warn("Close() unsupported in headless mode")
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ func (w *webViewRenderer) Run() error {
|
||||
// Runtime assets
|
||||
assets := packr.NewBox("./assets/default")
|
||||
|
||||
wailsRuntime := assets.String("wails.js")
|
||||
wailsRuntime := BoxString(&assets, "wails.js")
|
||||
w.evalJS(wailsRuntime)
|
||||
|
||||
// Ping the wait channel when the wails runtime is loaded
|
||||
@@ -173,7 +173,7 @@ func (w *webViewRenderer) Run() error {
|
||||
go func() {
|
||||
// Will we mount a custom component
|
||||
// Inject jquery
|
||||
jquery := assets.String("jquery.3.3.1.min.js")
|
||||
jquery := BoxString(&assets, "jquery.3.3.1.min.js")
|
||||
w.evalJSSync(jquery)
|
||||
|
||||
// Inject Bindings
|
||||
|
||||
12
utils.go
12
utils.go
@@ -1,7 +1,10 @@
|
||||
package wails
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/gobuffalo/packr"
|
||||
)
|
||||
|
||||
func escapeJS(js string) (string, error) {
|
||||
@@ -10,3 +13,12 @@ func escapeJS(js string) (string, error) {
|
||||
result = strings.Replace(result, "\n", "\\n", -1)
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// BoxString wraps packr.FindString
|
||||
func BoxString(box *packr.Box, filename string) string {
|
||||
result, err := box.FindString(filename)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user