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:
parent
58dc917fb7
commit
5ff3a286cf
@ -42,7 +42,7 @@ func NewDesktopAssetServer(ctx context.Context, assets embed.FS, bindingsJSON st
|
||||
|
||||
var buffer bytes.Buffer
|
||||
buffer.WriteString(`window.wailsbindings='` + bindingsJSON + `';` + "\n")
|
||||
buffer.Write(runtime.RuntimeJS)
|
||||
buffer.Write(runtime.RuntimeDesktopJS)
|
||||
result.runtimeJS = buffer.Bytes()
|
||||
err := result.init(assets)
|
||||
return result, err
|
||||
|
@ -47,6 +47,8 @@ func (f *Frontend) WindowReload() {
|
||||
|
||||
func (f *Frontend) Run(ctx context.Context) error {
|
||||
|
||||
f.ctx = context.WithValue(ctx, "frontend", f)
|
||||
|
||||
mainWindow := NewWindow(nil, f.frontendOptions)
|
||||
f.mainWindow = mainWindow
|
||||
|
||||
@ -77,8 +79,9 @@ func (f *Frontend) Run(ctx context.Context) error {
|
||||
|
||||
// TODO: Move this into a callback from frontend
|
||||
go func() {
|
||||
ctx := context.WithValue(ctx, "frontend", f)
|
||||
f.frontendOptions.Startup(ctx)
|
||||
if f.frontendOptions.OnStartup != nil {
|
||||
f.frontendOptions.OnStartup(f.ctx)
|
||||
}
|
||||
}()
|
||||
|
||||
mainWindow.Run()
|
||||
@ -172,6 +175,7 @@ func (f *Frontend) setupChromium() {
|
||||
chromium := edge.NewChromium()
|
||||
chromium.MessageCallback = f.processMessage
|
||||
chromium.WebResourceRequestedCallback = f.processRequest
|
||||
chromium.NavigationCompletedCallback = f.navigationCompleted
|
||||
chromium.Embed(f.mainWindow.Handle())
|
||||
chromium.Resize()
|
||||
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 {
|
||||
|
||||
result := &Frontend{
|
||||
|
@ -1,3 +1,5 @@
|
||||
//go:build dev
|
||||
|
||||
package devserver
|
||||
|
||||
import (
|
||||
|
Loading…
Reference in New Issue
Block a user