mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-04 01:50:09 +08:00
Merge pull request #113 from wailsapp/112-deprecate-backend-injection-of-css-js
112 deprecate backend injection of css js
This commit is contained in:
commit
dcc3e5fa79
@ -8,5 +8,6 @@ Wails is what it is because of the time and effort given by these great people.
|
|||||||
* [Adrian Lanzafame](https://github.com/lanzafame)
|
* [Adrian Lanzafame](https://github.com/lanzafame)
|
||||||
* [0xflotus](https://github.com/0xflotus)
|
* [0xflotus](https://github.com/0xflotus)
|
||||||
* [Michael D Henderson](https://github.com/mdhender)
|
* [Michael D Henderson](https://github.com/mdhender)
|
||||||
* [fred2104] (https://github.com/fishfishfish2104)
|
* [fred2104](https://github.com/fishfishfish2104)
|
||||||
* [intelwalk] (https://github.com/intelwalk)
|
* [intelwalk](https://github.com/intelwalk)
|
||||||
|
* [Mark Stenglein](https://github.com/ocelotsloth)
|
||||||
|
23
app.go
23
app.go
@ -22,11 +22,6 @@ type App struct {
|
|||||||
bindingManager *bindingManager // Handles binding of Go code to renderer
|
bindingManager *bindingManager // Handles binding of Go code to renderer
|
||||||
eventManager *eventManager // Handles all the events
|
eventManager *eventManager // Handles all the events
|
||||||
runtime *Runtime // The runtime object for registered structs
|
runtime *Runtime // The runtime object for registered structs
|
||||||
|
|
||||||
// This is a list of all the JS/CSS that needs injecting
|
|
||||||
// It will get injected in order
|
|
||||||
jsCache []string
|
|
||||||
cssCache []string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateApp creates the application window with the given configuration
|
// CreateApp creates the application window with the given configuration
|
||||||
@ -111,12 +106,6 @@ func (a *App) start() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inject CSS
|
|
||||||
a.renderer.AddCSSList(a.cssCache)
|
|
||||||
|
|
||||||
// Inject JS
|
|
||||||
a.renderer.AddJSList(a.jsCache)
|
|
||||||
|
|
||||||
// Run the renderer
|
// Run the renderer
|
||||||
return a.renderer.Run()
|
return a.renderer.Run()
|
||||||
}
|
}
|
||||||
@ -126,15 +115,3 @@ func (a *App) start() error {
|
|||||||
func (a *App) Bind(object interface{}) {
|
func (a *App) Bind(object interface{}) {
|
||||||
a.bindingManager.bind(object)
|
a.bindingManager.bind(object)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddJS adds a piece of Javascript to a cache that
|
|
||||||
// gets injected at runtime
|
|
||||||
func (a *App) AddJS(js string) {
|
|
||||||
a.jsCache = append(a.jsCache, js)
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddCSS adds a CSS string to a cache that
|
|
||||||
// gets injected at runtime
|
|
||||||
func (a *App) AddCSS(js string) {
|
|
||||||
a.cssCache = append(a.cssCache, js)
|
|
||||||
}
|
|
||||||
|
@ -12,10 +12,6 @@ type Renderer interface {
|
|||||||
// Events
|
// Events
|
||||||
NotifyEvent(eventData *eventData) error
|
NotifyEvent(eventData *eventData) error
|
||||||
|
|
||||||
// Injection
|
|
||||||
AddJSList(js []string)
|
|
||||||
AddCSSList(css []string)
|
|
||||||
|
|
||||||
// Dialog Runtime
|
// Dialog Runtime
|
||||||
SelectFile() string
|
SelectFile() string
|
||||||
SelectDirectory() string
|
SelectDirectory() string
|
||||||
|
@ -37,10 +37,6 @@ type Headless struct {
|
|||||||
appConfig *AppConfig
|
appConfig *AppConfig
|
||||||
eventManager *eventManager
|
eventManager *eventManager
|
||||||
bindingCache []string
|
bindingCache []string
|
||||||
frameworkJS string
|
|
||||||
frameworkCSS string
|
|
||||||
jsCache []string
|
|
||||||
cssCache []string
|
|
||||||
|
|
||||||
// Headless specific
|
// Headless specific
|
||||||
initialisationJS []string
|
initialisationJS []string
|
||||||
@ -190,18 +186,6 @@ func (h *Headless) SelectSaveFile() string {
|
|||||||
return ""
|
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
|
|
||||||
}
|
|
||||||
|
|
||||||
// Callback sends a callback to the frontend
|
// Callback sends a callback to the frontend
|
||||||
func (h *Headless) Callback(data string) error {
|
func (h *Headless) Callback(data string) error {
|
||||||
return h.evalJS(data, callbackMessage)
|
return h.evalJS(data, callbackMessage)
|
||||||
|
@ -21,13 +21,6 @@ type webViewRenderer struct {
|
|||||||
config *AppConfig
|
config *AppConfig
|
||||||
eventManager *eventManager
|
eventManager *eventManager
|
||||||
bindingCache []string
|
bindingCache []string
|
||||||
frameworkJS string
|
|
||||||
frameworkCSS string
|
|
||||||
|
|
||||||
// This is a list of all the JS/CSS that needs injecting
|
|
||||||
// It will get injected in order
|
|
||||||
jsCache []string
|
|
||||||
cssCache []string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialise sets up the WebView
|
// Initialise sets up the WebView
|
||||||
@ -175,13 +168,13 @@ func (w *webViewRenderer) Run() error {
|
|||||||
w.evalJSSync(binding)
|
w.evalJSSync(binding)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inject Framework
|
// // Inject Framework
|
||||||
if w.frameworkJS != "" {
|
// if w.frameworkJS != "" {
|
||||||
w.evalJSSync(w.frameworkJS)
|
// w.evalJSSync(w.frameworkJS)
|
||||||
}
|
// }
|
||||||
if w.frameworkCSS != "" {
|
// if w.frameworkCSS != "" {
|
||||||
w.injectCSS(w.frameworkCSS)
|
// w.injectCSS(w.frameworkCSS)
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Inject user CSS
|
// Inject user CSS
|
||||||
if w.config.CSS != "" {
|
if w.config.CSS != "" {
|
||||||
@ -199,16 +192,6 @@ func (w *webViewRenderer) Run() error {
|
|||||||
w.injectCSS(defaultCSS)
|
w.injectCSS(defaultCSS)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inject all the CSS files that have been added
|
|
||||||
for _, css := range w.cssCache {
|
|
||||||
w.injectCSS(css)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inject all the JS files that have been added
|
|
||||||
for _, js := range w.jsCache {
|
|
||||||
w.evalJSSync(js)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inject user JS
|
// Inject user JS
|
||||||
if w.config.JS != "" {
|
if w.config.JS != "" {
|
||||||
outputJS := fmt.Sprintf("%.45s", w.config.JS)
|
outputJS := fmt.Sprintf("%.45s", w.config.JS)
|
||||||
@ -289,17 +272,6 @@ func (w *webViewRenderer) SelectSaveFile() string {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddJS adds a piece of Javascript to a cache that
|
|
||||||
// gets injected at runtime
|
|
||||||
func (w *webViewRenderer) AddJSList(jsCache []string) {
|
|
||||||
w.jsCache = jsCache
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddCSSList sets the cssCache to the given list of strings
|
|
||||||
func (w *webViewRenderer) AddCSSList(cssCache []string) {
|
|
||||||
w.cssCache = cssCache
|
|
||||||
}
|
|
||||||
|
|
||||||
// Callback sends a callback to the frontend
|
// Callback sends a callback to the frontend
|
||||||
func (w *webViewRenderer) Callback(data string) error {
|
func (w *webViewRenderer) Callback(data string) error {
|
||||||
callbackCMD := fmt.Sprintf("window.wails._.callback('%s');", data)
|
callbackCMD := fmt.Sprintf("window.wails._.callback('%s');", data)
|
||||||
|
Loading…
Reference in New Issue
Block a user