mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 15:11:53 +08:00

* v1.10.1 * Fix vue template dependencies versions (fixes #574) (#576) * resolve angular routing broken when app is built * Revert "resolve angular routing broken when app is built" This reverts commite0aab7c27f
. * Update issue templates * v1.8.1 (#546) * resolve angular routing broken when app is built * Updated contributors * handle Set error on Update method * Remove incorrect build flag * v1.8.1-pre1 * added Get method * fixed return * implement gopath handling during cross compilation * update messages to output xgo version TODO: allow image override * use wailsapp/xgo:1.0.1 for cross-compiling * Support platform list in templates * Add warnings for windows builds * add fields Tags to ProjectOptions * add args tags to func BuildNative * add tags to func BuildDocker * delete escape tags * Update Contributors * feat: Vue3, Vue Router, Vuex, and Typescript Template * converted spaces to tabs in vue.config.js * single quotes and tabs Converted vue.config.js to using single quotes Converted example.spec.ts to tabs instead of spaces. * Added semicolons and mocha import * Update contributors * Make vue 3 template linux/mac only * Add tags to build * Add v2 artefacts * Update Vuetify in package.json (#537) * Update contributors * Replaced the old v-content tag with the new v-main (#536) * v1.8.1-pre4 * v1.8.1-pre5 * Update issue templates (#541) * Updated Contributors * Remove zero copy string conversion * v1.8.1-pre6 * Initial support for firebug (#543) * Initial support for firebug * Remove windows message * v1.8.1-pre7 * Update contributors * Allow use of custom HTML * Allow use of custom HTML (#545) * v1.8.1 Co-authored-by: Arthur Wiebe <arthur@artooro.com> Co-authored-by: Ilgıt Yıldırım <ilgit.yildirim@triplebits.com> Co-authored-by: Travis McLane <tmclane@gmail.com> Co-authored-by: Altynbek <go.gelleson@gmail.com> Co-authored-by: Kyle Muchmore <kyle.muchmore@kickview.com> Co-authored-by: Balakrishna Prasad Ganne <balkripra.1996@gmail.com> * v1.10.1 (#572) * fix dependencies versions Co-authored-by: Arthur Wiebe <arthur@artooro.com> Co-authored-by: Lea Anthony <lea.anthony@gmail.com> Co-authored-by: Ilgıt Yıldırım <ilgit.yildirim@triplebits.com> Co-authored-by: Travis McLane <tmclane@gmail.com> Co-authored-by: Altynbek <go.gelleson@gmail.com> Co-authored-by: Kyle Muchmore <kyle.muchmore@kickview.com> Co-authored-by: Balakrishna Prasad Ganne <balkripra.1996@gmail.com> * v1.11.0-rc1 * v1.11.0-pre1 * Bump ini from 1.3.5 to 1.3.8 in /runtime/js/runtime (#575) * resolve angular routing broken when app is built * Revert "resolve angular routing broken when app is built" This reverts commite0aab7c27f
. * Update issue templates * v1.8.1 (#546) * resolve angular routing broken when app is built * Updated contributors * handle Set error on Update method * Remove incorrect build flag * v1.8.1-pre1 * added Get method * fixed return * implement gopath handling during cross compilation * update messages to output xgo version TODO: allow image override * use wailsapp/xgo:1.0.1 for cross-compiling * Support platform list in templates * Add warnings for windows builds * add fields Tags to ProjectOptions * add args tags to func BuildNative * add tags to func BuildDocker * delete escape tags * Update Contributors * feat: Vue3, Vue Router, Vuex, and Typescript Template * converted spaces to tabs in vue.config.js * single quotes and tabs Converted vue.config.js to using single quotes Converted example.spec.ts to tabs instead of spaces. * Added semicolons and mocha import * Update contributors * Make vue 3 template linux/mac only * Add tags to build * Add v2 artefacts * Update Vuetify in package.json (#537) * Update contributors * Replaced the old v-content tag with the new v-main (#536) * v1.8.1-pre4 * v1.8.1-pre5 * Update issue templates (#541) * Updated Contributors * Remove zero copy string conversion * v1.8.1-pre6 * Initial support for firebug (#543) * Initial support for firebug * Remove windows message * v1.8.1-pre7 * Update contributors * Allow use of custom HTML * Allow use of custom HTML (#545) * v1.8.1 Co-authored-by: Arthur Wiebe <arthur@artooro.com> Co-authored-by: Ilgıt Yıldırım <ilgit.yildirim@triplebits.com> Co-authored-by: Travis McLane <tmclane@gmail.com> Co-authored-by: Altynbek <go.gelleson@gmail.com> Co-authored-by: Kyle Muchmore <kyle.muchmore@kickview.com> Co-authored-by: Balakrishna Prasad Ganne <balkripra.1996@gmail.com> * v1.10.1 (#572) * Bump ini from 1.3.5 to 1.3.8 in /runtime/js/runtime Bumps [ini](https://github.com/isaacs/ini) from 1.3.5 to 1.3.8. - [Release notes](https://github.com/isaacs/ini/releases) - [Commits](https://github.com/isaacs/ini/compare/v1.3.5...v1.3.8) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Arthur Wiebe <arthur@artooro.com> Co-authored-by: Lea Anthony <lea.anthony@gmail.com> Co-authored-by: Ilgıt Yıldırım <ilgit.yildirim@triplebits.com> Co-authored-by: Travis McLane <tmclane@gmail.com> Co-authored-by: Altynbek <go.gelleson@gmail.com> Co-authored-by: Kyle Muchmore <kyle.muchmore@kickview.com> Co-authored-by: Balakrishna Prasad Ganne <balkripra.1996@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump ini from 1.3.5 to 1.3.8 in /runtime/js (#573) * resolve angular routing broken when app is built * Revert "resolve angular routing broken when app is built" This reverts commite0aab7c27f
. * Update issue templates * v1.8.1 (#546) * resolve angular routing broken when app is built * Updated contributors * handle Set error on Update method * Remove incorrect build flag * v1.8.1-pre1 * added Get method * fixed return * implement gopath handling during cross compilation * update messages to output xgo version TODO: allow image override * use wailsapp/xgo:1.0.1 for cross-compiling * Support platform list in templates * Add warnings for windows builds * add fields Tags to ProjectOptions * add args tags to func BuildNative * add tags to func BuildDocker * delete escape tags * Update Contributors * feat: Vue3, Vue Router, Vuex, and Typescript Template * converted spaces to tabs in vue.config.js * single quotes and tabs Converted vue.config.js to using single quotes Converted example.spec.ts to tabs instead of spaces. * Added semicolons and mocha import * Update contributors * Make vue 3 template linux/mac only * Add tags to build * Add v2 artefacts * Update Vuetify in package.json (#537) * Update contributors * Replaced the old v-content tag with the new v-main (#536) * v1.8.1-pre4 * v1.8.1-pre5 * Update issue templates (#541) * Updated Contributors * Remove zero copy string conversion * v1.8.1-pre6 * Initial support for firebug (#543) * Initial support for firebug * Remove windows message * v1.8.1-pre7 * Update contributors * Allow use of custom HTML * Allow use of custom HTML (#545) * v1.8.1 Co-authored-by: Arthur Wiebe <arthur@artooro.com> Co-authored-by: Ilgıt Yıldırım <ilgit.yildirim@triplebits.com> Co-authored-by: Travis McLane <tmclane@gmail.com> Co-authored-by: Altynbek <go.gelleson@gmail.com> Co-authored-by: Kyle Muchmore <kyle.muchmore@kickview.com> Co-authored-by: Balakrishna Prasad Ganne <balkripra.1996@gmail.com> * v1.10.1 (#572) * Bump ini from 1.3.5 to 1.3.8 in /runtime/js Bumps [ini](https://github.com/isaacs/ini) from 1.3.5 to 1.3.8. - [Release notes](https://github.com/isaacs/ini/releases) - [Commits](https://github.com/isaacs/ini/compare/v1.3.5...v1.3.8) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Arthur Wiebe <arthur@artooro.com> Co-authored-by: Lea Anthony <lea.anthony@gmail.com> Co-authored-by: Ilgıt Yıldırım <ilgit.yildirim@triplebits.com> Co-authored-by: Travis McLane <tmclane@gmail.com> Co-authored-by: Altynbek <go.gelleson@gmail.com> Co-authored-by: Kyle Muchmore <kyle.muchmore@kickview.com> Co-authored-by: Balakrishna Prasad Ganne <balkripra.1996@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Remove debug info * v1.11.0-pre2 * Limit v1 updates to v1 * v1.11.0-pre3 * Test fix for linux high CPU usage * v1.11.0 * Add Pace to Thanks * Remove spec option in babel config (#593) * v1.12.0-pre1 * Update Contributors * Expose Once and OnMultiple * v1.12.0-pre2 * Fix potential nil conditions in webview * Fix issue with expired listeners * v1.12.0-pre3 * Don't manipulate listeners array when expired * add support for crux linux (#581) * Add support for Crux Linux (http://crux.nu) * Update linuxdb.yaml fix typo * Update linux.go fixed comment typo * Update linuxdb.yaml fixed more typos Co-authored-by: Lea Anthony <lea.anthony@gmail.com> * v1.12.0-pre4 * Update contributors * Put main window into focus after a dialog closes (#609) * v1.11.0 (#582) * v1.10.1 * Fix vue template dependencies versions (fixes #574) (#576) * resolve angular routing broken when app is built * Revert "resolve angular routing broken when app is built" This reverts commite0aab7c27f
. * Update issue templates * v1.8.1 (#546) * resolve angular routing broken when app is built * Updated contributors * handle Set error on Update method * Remove incorrect build flag * v1.8.1-pre1 * added Get method * fixed return * implement gopath handling during cross compilation * update messages to output xgo version TODO: allow image override * use wailsapp/xgo:1.0.1 for cross-compiling * Support platform list in templates * Add warnings for windows builds * add fields Tags to ProjectOptions * add args tags to func BuildNative * add tags to func BuildDocker * delete escape tags * Update Contributors * feat: Vue3, Vue Router, Vuex, and Typescript Template * converted spaces to tabs in vue.config.js * single quotes and tabs Converted vue.config.js to using single quotes Converted example.spec.ts to tabs instead of spaces. * Added semicolons and mocha import * Update contributors * Make vue 3 template linux/mac only * Add tags to build * Add v2 artefacts * Update Vuetify in package.json (#537) * Update contributors * Replaced the old v-content tag with the new v-main (#536) * v1.8.1-pre4 * v1.8.1-pre5 * Update issue templates (#541) * Updated Contributors * Remove zero copy string conversion * v1.8.1-pre6 * Initial support for firebug (#543) * Initial support for firebug * Remove windows message * v1.8.1-pre7 * Update contributors * Allow use of custom HTML * Allow use of custom HTML (#545) * v1.8.1 Co-authored-by: Arthur Wiebe <arthur@artooro.com> Co-authored-by: Ilgıt Yıldırım <ilgit.yildirim@triplebits.com> Co-authored-by: Travis McLane <tmclane@gmail.com> Co-authored-by: Altynbek <go.gelleson@gmail.com> Co-authored-by: Kyle Muchmore <kyle.muchmore@kickview.com> Co-authored-by: Balakrishna Prasad Ganne <balkripra.1996@gmail.com> * v1.10.1 (#572) * fix dependencies versions Co-authored-by: Arthur Wiebe <arthur@artooro.com> Co-authored-by: Lea Anthony <lea.anthony@gmail.com> Co-authored-by: Ilgıt Yıldırım <ilgit.yildirim@triplebits.com> Co-authored-by: Travis McLane <tmclane@gmail.com> Co-authored-by: Altynbek <go.gelleson@gmail.com> Co-authored-by: Kyle Muchmore <kyle.muchmore@kickview.com> Co-authored-by: Balakrishna Prasad Ganne <balkripra.1996@gmail.com> * v1.11.0-rc1 * v1.11.0-pre1 * Bump ini from 1.3.5 to 1.3.8 in /runtime/js/runtime (#575) * resolve angular routing broken when app is built * Revert "resolve angular routing broken when app is built" This reverts commite0aab7c27f
. * Update issue templates * v1.8.1 (#546) * resolve angular routing broken when app is built * Updated contributors * handle Set error on Update method * Remove incorrect build flag * v1.8.1-pre1 * added Get method * fixed return * implement gopath handling during cross compilation * update messages to output xgo version TODO: allow image override * use wailsapp/xgo:1.0.1 for cross-compiling * Support platform list in templates * Add warnings for windows builds * add fields Tags to ProjectOptions * add args tags to func BuildNative * add tags to func BuildDocker * delete escape tags * Update Contributors * feat: Vue3, Vue Router, Vuex, and Typescript Template * converted spaces to tabs in vue.config.js * single quotes and tabs Converted vue.config.js to using single quotes Converted example.spec.ts to tabs instead of spaces. * Added semicolons and mocha import * Update contributors * Make vue 3 template linux/mac only * Add tags to build * Add v2 artefacts * Update Vuetify in package.json (#537) * Update contributors * Replaced the old v-content tag with the new v-main (#536) * v1.8.1-pre4 * v1.8.1-pre5 * Update issue templates (#541) * Updated Contributors * Remove zero copy string conversion * v1.8.1-pre6 * Initial support for firebug (#543) * Initial support for firebug * Remove windows message * v1.8.1-pre7 * Update contributors * Allow use of custom HTML * Allow use of custom HTML (#545) * v1.8.1 Co-authored-by: Arthur Wiebe <arthur@artooro.com> Co-authored-by: Ilgıt Yıldırım <ilgit.yildirim@triplebits.com> Co-authored-by: Travis McLane <tmclane@gmail.com> Co-authored-by: Altynbek <go.gelleson@gmail.com> Co-authored-by: Kyle Muchmore <kyle.muchmore@kickview.com> Co-authored-by: Balakrishna Prasad Ganne <balkripra.1996@gmail.com> * v1.10.1 (#572) * Bump ini from 1.3.5 to 1.3.8 in /runtime/js/runtime Bumps [ini](https://github.com/isaacs/ini) from 1.3.5 to 1.3.8. - [Release notes](https://github.com/isaacs/ini/releases) - [Commits](https://github.com/isaacs/ini/compare/v1.3.5...v1.3.8) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Arthur Wiebe <arthur@artooro.com> Co-authored-by: Lea Anthony <lea.anthony@gmail.com> Co-authored-by: Ilgıt Yıldırım <ilgit.yildirim@triplebits.com> Co-authored-by: Travis McLane <tmclane@gmail.com> Co-authored-by: Altynbek <go.gelleson@gmail.com> Co-authored-by: Kyle Muchmore <kyle.muchmore@kickview.com> Co-authored-by: Balakrishna Prasad Ganne <balkripra.1996@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump ini from 1.3.5 to 1.3.8 in /runtime/js (#573) * resolve angular routing broken when app is built * Revert "resolve angular routing broken when app is built" This reverts commite0aab7c27f
. * Update issue templates * v1.8.1 (#546) * resolve angular routing broken when app is built * Updated contributors * handle Set error on Update method * Remove incorrect build flag * v1.8.1-pre1 * added Get method * fixed return * implement gopath handling during cross compilation * update messages to output xgo version TODO: allow image override * use wailsapp/xgo:1.0.1 for cross-compiling * Support platform list in templates * Add warnings for windows builds * add fields Tags to ProjectOptions * add args tags to func BuildNative * add tags to func BuildDocker * delete escape tags * Update Contributors * feat: Vue3, Vue Router, Vuex, and Typescript Template * converted spaces to tabs in vue.config.js * single quotes and tabs Converted vue.config.js to using single quotes Converted example.spec.ts to tabs instead of spaces. * Added semicolons and mocha import * Update contributors * Make vue 3 template linux/mac only * Add tags to build * Add v2 artefacts * Update Vuetify in package.json (#537) * Update contributors * Replaced the old v-content tag with the new v-main (#536) * v1.8.1-pre4 * v1.8.1-pre5 * Update issue templates (#541) * Updated Contributors * Remove zero copy string conversion * v1.8.1-pre6 * Initial support for firebug (#543) * Initial support for firebug * Remove windows message * v1.8.1-pre7 * Update contributors * Allow use of custom HTML * Allow use of custom HTML (#545) * v1.8.1 Co-authored-by: Arthur Wiebe <arthur@artooro.com> Co-authored-by: Ilgıt Yıldırım <ilgit.yildirim@triplebits.com> Co-authored-by: Travis McLane <tmclane@gmail.com> Co-authored-by: Altynbek <go.gelleson@gmail.com> Co-authored-by: Kyle Muchmore <kyle.muchmore@kickview.com> Co-authored-by: Balakrishna Prasad Ganne <balkripra.1996@gmail.com> * v1.10.1 (#572) * Bump ini from 1.3.5 to 1.3.8 in /runtime/js Bumps [ini](https://github.com/isaacs/ini) from 1.3.5 to 1.3.8. - [Release notes](https://github.com/isaacs/ini/releases) - [Commits](https://github.com/isaacs/ini/compare/v1.3.5...v1.3.8) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Arthur Wiebe <arthur@artooro.com> Co-authored-by: Lea Anthony <lea.anthony@gmail.com> Co-authored-by: Ilgıt Yıldırım <ilgit.yildirim@triplebits.com> Co-authored-by: Travis McLane <tmclane@gmail.com> Co-authored-by: Altynbek <go.gelleson@gmail.com> Co-authored-by: Kyle Muchmore <kyle.muchmore@kickview.com> Co-authored-by: Balakrishna Prasad Ganne <balkripra.1996@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Remove debug info * v1.11.0-pre2 * Limit v1 updates to v1 * v1.11.0-pre3 * Test fix for linux high CPU usage * v1.11.0 Co-authored-by: Elie Grenon (DrunkenPoney) <elie.grenon.1@gmail.com> Co-authored-by: Arthur Wiebe <arthur@artooro.com> Co-authored-by: Ilgıt Yıldırım <ilgit.yildirim@triplebits.com> Co-authored-by: Travis McLane <tmclane@gmail.com> Co-authored-by: Altynbek <go.gelleson@gmail.com> Co-authored-by: Kyle Muchmore <kyle.muchmore@kickview.com> Co-authored-by: Balakrishna Prasad Ganne <balkripra.1996@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Add Pace to Thanks * Redo thanks section * Put main window into focus after dialogs close * Update CONTRIBUTORS.md * v1.12.0-pre5 * update scripts/build.sh to run test only on v1 * fix: typo in comment (#627) * feat(cli): use gitconfig name as name prompt default value * Add hi019 to CONTRIBUTORS * v1.12.0-pre6 * v1.12.0 * fix(cli): use npm run serve as serve command in all templates (#635) * Fix typo in webview.h * v1.12.1 Co-authored-by: Elie Grenon (DrunkenPoney) <elie.grenon.1@gmail.com> Co-authored-by: Arthur Wiebe <arthur@artooro.com> Co-authored-by: Ilgıt Yıldırım <ilgit.yildirim@triplebits.com> Co-authored-by: Travis McLane <tmclane@gmail.com> Co-authored-by: Altynbek <go.gelleson@gmail.com> Co-authored-by: Kyle Muchmore <kyle.muchmore@kickview.com> Co-authored-by: Balakrishna Prasad Ganne <balkripra.1996@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Sophie Au <SophieAu@users.noreply.github.com> Co-authored-by: Alexander Matviychuk <githubcom@huskmail.com> Co-authored-by: RH12503 <48951973+RH12503@users.noreply.github.com> Co-authored-by: hi019 <65871571+hi019@users.noreply.github.com>
391 lines
9.4 KiB
Go
391 lines
9.4 KiB
Go
package renderer
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"math/rand"
|
|
"strings"
|
|
"sync"
|
|
"time"
|
|
|
|
"github.com/go-playground/colors"
|
|
"github.com/leaanthony/mewn"
|
|
"github.com/wailsapp/wails/lib/interfaces"
|
|
"github.com/wailsapp/wails/lib/logger"
|
|
"github.com/wailsapp/wails/lib/messages"
|
|
wv "github.com/wailsapp/wails/lib/renderer/webview"
|
|
)
|
|
|
|
// WebView defines the main webview application window
|
|
// Default values in []
|
|
|
|
// UseFirebug indicates whether to inject the firebug console
|
|
var UseFirebug = ""
|
|
|
|
type WebView struct {
|
|
window wv.WebView // The webview object
|
|
ipc interfaces.IPCManager
|
|
log *logger.CustomLogger
|
|
config interfaces.AppConfig
|
|
eventManager interfaces.EventManager
|
|
bindingCache []string
|
|
}
|
|
|
|
// NewWebView returns a new WebView struct
|
|
func NewWebView() *WebView {
|
|
return &WebView{}
|
|
}
|
|
|
|
// Initialise sets up the WebView
|
|
func (w *WebView) Initialise(config interfaces.AppConfig, ipc interfaces.IPCManager, eventManager interfaces.EventManager) error {
|
|
|
|
// Store reference to eventManager
|
|
w.eventManager = eventManager
|
|
|
|
// Set up logger
|
|
w.log = logger.NewCustomLogger("WebView")
|
|
|
|
// Set up the dispatcher function
|
|
w.ipc = ipc
|
|
ipc.BindRenderer(w)
|
|
|
|
// Save the config
|
|
w.config = config
|
|
|
|
// Create the WebView instance
|
|
w.window = wv.NewWebview(wv.Settings{
|
|
Width: config.GetWidth(),
|
|
Height: config.GetHeight(),
|
|
Title: config.GetTitle(),
|
|
Resizable: config.GetResizable(),
|
|
URL: config.GetHTML(),
|
|
Debug: !config.GetDisableInspector(),
|
|
ExternalInvokeCallback: func(_ wv.WebView, message string) {
|
|
w.ipc.Dispatch(message, w.callback)
|
|
},
|
|
})
|
|
|
|
// SignalManager.OnExit(w.Exit)
|
|
|
|
// Set colour
|
|
err := w.SetColour(config.GetColour())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
w.log.Info("Initialised")
|
|
return nil
|
|
}
|
|
|
|
// SetColour sets the window colour
|
|
func (w *WebView) SetColour(colour string) error {
|
|
color, err := colors.Parse(colour)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
rgba := color.ToRGBA()
|
|
alpha := uint8(255 * rgba.A)
|
|
w.window.Dispatch(func() {
|
|
w.window.SetColor(rgba.R, rgba.G, rgba.B, alpha)
|
|
})
|
|
|
|
return nil
|
|
}
|
|
|
|
// evalJS evaluates the given js in the WebView
|
|
// I should rename this to evilJS lol
|
|
func (w *WebView) evalJS(js string) error {
|
|
outputJS := fmt.Sprintf("%.45s", js)
|
|
if len(js) > 45 {
|
|
outputJS += "..."
|
|
}
|
|
w.log.DebugFields("Eval", logger.Fields{"js": outputJS})
|
|
//
|
|
w.window.Dispatch(func() {
|
|
w.window.Eval(js)
|
|
})
|
|
return nil
|
|
}
|
|
|
|
// Escape the Javascripts!
|
|
func escapeJS(js string) (string, error) {
|
|
result := strings.Replace(js, "\\", "\\\\", -1)
|
|
result = strings.Replace(result, "'", "\\'", -1)
|
|
result = strings.Replace(result, "\n", "\\n", -1)
|
|
return result, nil
|
|
}
|
|
|
|
// evalJSSync evaluates the given js in the WebView synchronously
|
|
// Do not call this from the main thread or you'll nuke your app because
|
|
// you won't get the callback.
|
|
func (w *WebView) evalJSSync(js string) error {
|
|
|
|
minified, err := escapeJS(js)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
outputJS := fmt.Sprintf("%.45s", js)
|
|
if len(js) > 45 {
|
|
outputJS += "..."
|
|
}
|
|
w.log.DebugFields("EvalSync", logger.Fields{"js": outputJS})
|
|
|
|
ID := fmt.Sprintf("syncjs:%d:%d", time.Now().Unix(), rand.Intn(9999))
|
|
var wg sync.WaitGroup
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
exit := false
|
|
// We are done when we receive the Callback ID
|
|
w.log.Debug("SyncJS: sending with ID = " + ID)
|
|
w.eventManager.On(ID, func(...interface{}) {
|
|
w.log.Debug("SyncJS: Got callback ID = " + ID)
|
|
wg.Done()
|
|
exit = true
|
|
})
|
|
command := fmt.Sprintf("wails._.AddScript('%s', '%s')", minified, ID)
|
|
w.window.Dispatch(func() {
|
|
w.window.Eval(command)
|
|
})
|
|
for exit == false {
|
|
time.Sleep(time.Millisecond * 1)
|
|
}
|
|
}()
|
|
|
|
wg.Wait()
|
|
|
|
return nil
|
|
}
|
|
|
|
// injectCSS adds the given CSS to the WebView
|
|
func (w *WebView) injectCSS(css string) {
|
|
w.window.Dispatch(func() {
|
|
w.window.InjectCSS(css)
|
|
})
|
|
}
|
|
|
|
// Exit closes the window
|
|
func (w *WebView) Exit() {
|
|
w.window.Exit()
|
|
}
|
|
|
|
// Run the window main loop
|
|
func (w *WebView) Run() error {
|
|
|
|
w.log.Info("Running...")
|
|
|
|
// Inject firebug in debug mode on Windows
|
|
if UseFirebug != "" {
|
|
w.log.Debug("Injecting Firebug")
|
|
w.evalJS(`window.usefirebug=true;`)
|
|
}
|
|
|
|
// Runtime assets
|
|
wailsRuntime := mewn.String("../../runtime/assets/wails.js")
|
|
w.evalJS(wailsRuntime)
|
|
|
|
// Ping the wait channel when the wails runtime is loaded
|
|
w.eventManager.On("wails:loaded", func(...interface{}) {
|
|
|
|
// Run this in a different go routine to free up the main process
|
|
go func() {
|
|
|
|
// Inject Bindings
|
|
for _, binding := range w.bindingCache {
|
|
w.evalJSSync(binding)
|
|
}
|
|
|
|
// Inject user CSS
|
|
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())
|
|
}
|
|
|
|
// Emit that everything is loaded and ready
|
|
w.eventManager.Emit("wails:ready")
|
|
}()
|
|
})
|
|
|
|
// Kick off main window loop
|
|
w.window.Run()
|
|
|
|
return nil
|
|
}
|
|
|
|
// NewBinding registers a new binding with the frontend
|
|
func (w *WebView) NewBinding(methodName string) error {
|
|
objectCode := fmt.Sprintf("window.wails._.NewBinding('%s');", methodName)
|
|
w.bindingCache = append(w.bindingCache, objectCode)
|
|
return nil
|
|
}
|
|
|
|
// SelectFile opens a dialog that allows the user to select a file
|
|
func (w *WebView) SelectFile(title string, filter string) string {
|
|
var result string
|
|
|
|
// We need to run this on the main thread, however Dispatch is
|
|
// non-blocking so we launch this in a goroutine and wait for
|
|
// dispatch to finish before returning the result
|
|
var wg sync.WaitGroup
|
|
wg.Add(1)
|
|
go func() {
|
|
w.window.Dispatch(func() {
|
|
result = w.window.Dialog(wv.DialogTypeOpen, 0, title, "", filter)
|
|
wg.Done()
|
|
})
|
|
}()
|
|
|
|
defer w.focus() // Ensure the main window is put back into focus afterwards
|
|
|
|
wg.Wait()
|
|
return result
|
|
}
|
|
|
|
// SelectDirectory opens a dialog that allows the user to select a directory
|
|
func (w *WebView) SelectDirectory() string {
|
|
var result string
|
|
// We need to run this on the main thread, however Dispatch is
|
|
// non-blocking so we launch this in a goroutine and wait for
|
|
// dispatch to finish before returning the result
|
|
var wg sync.WaitGroup
|
|
wg.Add(1)
|
|
go func() {
|
|
w.window.Dispatch(func() {
|
|
result = w.window.Dialog(wv.DialogTypeOpen, wv.DialogFlagDirectory, "Select Directory", "", "")
|
|
wg.Done()
|
|
})
|
|
}()
|
|
|
|
defer w.focus() // Ensure the main window is put back into focus afterwards
|
|
|
|
wg.Wait()
|
|
return result
|
|
}
|
|
|
|
// SelectSaveFile opens a dialog that allows the user to select a file to save
|
|
func (w *WebView) SelectSaveFile(title string, filter string) string {
|
|
var result string
|
|
// We need to run this on the main thread, however Dispatch is
|
|
// non-blocking so we launch this in a goroutine and wait for
|
|
// dispatch to finish before returning the result
|
|
var wg sync.WaitGroup
|
|
wg.Add(1)
|
|
go func() {
|
|
w.window.Dispatch(func() {
|
|
result = w.window.Dialog(wv.DialogTypeSave, 0, title, "", filter)
|
|
wg.Done()
|
|
})
|
|
}()
|
|
|
|
defer w.focus() // Ensure the main window is put back into focus afterwards
|
|
|
|
wg.Wait()
|
|
return result
|
|
}
|
|
|
|
// focus puts the main window into focus
|
|
func (w *WebView) focus() {
|
|
w.window.Dispatch(func() {
|
|
w.window.Focus()
|
|
})
|
|
}
|
|
|
|
// callback sends a callback to the frontend
|
|
func (w *WebView) callback(data string) error {
|
|
callbackCMD := fmt.Sprintf("window.wails._.Callback('%s');", data)
|
|
return w.evalJS(callbackCMD)
|
|
}
|
|
|
|
// NotifyEvent notifies the frontend about a backend runtime event
|
|
func (w *WebView) NotifyEvent(event *messages.EventData) error {
|
|
|
|
// Look out! Nils about!
|
|
var err error
|
|
if event == nil {
|
|
err = fmt.Errorf("Sent nil event to renderer.WebView")
|
|
w.log.Error(err.Error())
|
|
return err
|
|
}
|
|
|
|
// Default data is a blank array
|
|
data := []byte("[]")
|
|
|
|
// Process event data
|
|
if event.Data != nil {
|
|
// Marshall the data
|
|
data, err = json.Marshal(event.Data)
|
|
if err != nil {
|
|
w.log.Errorf("Cannot unmarshall JSON data in event: %s ", err.Error())
|
|
return err
|
|
}
|
|
}
|
|
|
|
// Double encode data to ensure everything is escaped correctly.
|
|
data, err = json.Marshal(string(data))
|
|
if err != nil {
|
|
w.log.Errorf("Cannot marshal JSON data in event: %s ", err.Error())
|
|
return err
|
|
}
|
|
|
|
message := "window.wails._.Notify('" + event.Name + "'," + string(data) + ")"
|
|
return w.evalJS(message)
|
|
}
|
|
|
|
// Fullscreen makes the main window go fullscreen
|
|
func (w *WebView) Fullscreen() {
|
|
if w.config.GetResizable() == false {
|
|
w.log.Warn("Cannot call Fullscreen() - App.Resizable = false")
|
|
return
|
|
}
|
|
w.window.Dispatch(func() {
|
|
w.window.SetFullscreen(true)
|
|
})
|
|
}
|
|
|
|
// UnFullscreen returns the window to the position prior to a fullscreen call
|
|
func (w *WebView) UnFullscreen() {
|
|
if w.config.GetResizable() == false {
|
|
w.log.Warn("Cannot call UnFullscreen() - App.Resizable = false")
|
|
return
|
|
}
|
|
w.window.Dispatch(func() {
|
|
w.window.SetFullscreen(false)
|
|
})
|
|
}
|
|
|
|
// SetTitle sets the window title
|
|
func (w *WebView) SetTitle(title string) {
|
|
w.window.Dispatch(func() {
|
|
w.window.SetTitle(title)
|
|
})
|
|
}
|
|
|
|
// Close closes the window
|
|
func (w *WebView) Close() {
|
|
w.window.Dispatch(func() {
|
|
w.window.Terminate()
|
|
})
|
|
}
|