[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

@@ -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{