5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 17:52:29 +08:00

[windows-x] Support OnDomReady, fix build

This commit is contained in:
Lea Anthony 2021-08-26 21:06:54 +10:00
parent 58dc917fb7
commit 5ff3a286cf
3 changed files with 15 additions and 3 deletions

View File

@ -42,7 +42,7 @@ func NewDesktopAssetServer(ctx context.Context, assets embed.FS, bindingsJSON st
var buffer bytes.Buffer var buffer bytes.Buffer
buffer.WriteString(`window.wailsbindings='` + bindingsJSON + `';` + "\n") buffer.WriteString(`window.wailsbindings='` + bindingsJSON + `';` + "\n")
buffer.Write(runtime.RuntimeJS) buffer.Write(runtime.RuntimeDesktopJS)
result.runtimeJS = buffer.Bytes() result.runtimeJS = buffer.Bytes()
err := result.init(assets) err := result.init(assets)
return result, err return result, err

View File

@ -47,6 +47,8 @@ func (f *Frontend) WindowReload() {
func (f *Frontend) Run(ctx context.Context) error { func (f *Frontend) Run(ctx context.Context) error {
f.ctx = context.WithValue(ctx, "frontend", f)
mainWindow := NewWindow(nil, f.frontendOptions) mainWindow := NewWindow(nil, f.frontendOptions)
f.mainWindow = mainWindow f.mainWindow = mainWindow
@ -77,8 +79,9 @@ func (f *Frontend) Run(ctx context.Context) error {
// TODO: Move this into a callback from frontend // TODO: Move this into a callback from frontend
go func() { go func() {
ctx := context.WithValue(ctx, "frontend", f) if f.frontendOptions.OnStartup != nil {
f.frontendOptions.Startup(ctx) f.frontendOptions.OnStartup(f.ctx)
}
}() }()
mainWindow.Run() mainWindow.Run()
@ -172,6 +175,7 @@ func (f *Frontend) setupChromium() {
chromium := edge.NewChromium() chromium := edge.NewChromium()
chromium.MessageCallback = f.processMessage chromium.MessageCallback = f.processMessage
chromium.WebResourceRequestedCallback = f.processRequest chromium.WebResourceRequestedCallback = f.processRequest
chromium.NavigationCompletedCallback = f.navigationCompleted
chromium.Embed(f.mainWindow.Handle()) chromium.Embed(f.mainWindow.Handle())
chromium.Resize() chromium.Resize()
settings, err := chromium.GetSettings() settings, err := chromium.GetSettings()
@ -296,6 +300,12 @@ func (f *Frontend) ExecJS(js string) {
}) })
} }
func (f *Frontend) navigationCompleted(sender *edge.ICoreWebView2, args *edge.ICoreWebView2NavigationCompletedEventArgs) {
if f.frontendOptions.OnDomReady != nil {
f.frontendOptions.OnDomReady(f.ctx)
}
}
func NewFrontend(ctx context.Context, appoptions *options.App, myLogger *logger.Logger, appBindings *binding.Bindings, dispatcher frontend.Dispatcher) *Frontend { func NewFrontend(ctx context.Context, appoptions *options.App, myLogger *logger.Logger, appBindings *binding.Bindings, dispatcher frontend.Dispatcher) *Frontend {
result := &Frontend{ result := &Frontend{

View File

@ -1,3 +1,5 @@
//go:build dev
package devserver package devserver
import ( import (