Skip to content

Commit

Permalink
fix app installable before wasm loading (#953)
Browse files Browse the repository at this point in the history
* fix app installable before wasm loading

* Update browser.go

* cleanup
  • Loading branch information
maxence-charriere authored May 22, 2024
1 parent ea12f18 commit 6d94193
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
17 changes: 13 additions & 4 deletions pkg/app/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,29 @@ func (b *browser) handleAppUpdate(ctx Context, notifyComponentEvent func(any)) {
appUpdate()
return nil
})
if Window().Get("goappOnUpdate").Truthy() {
defer appUpdate()
}
Window().Set("goappOnUpdate", b.appUpdate)

if Window().Get("goappUpdatedBeforeWasmLoaded").Truthy() {
appUpdate()
}
}

func (b *browser) handleAppInstallChange(ctx Context, notifyComponentEvent func(any)) {
b.appInstallChange = FuncOf(func(this Value, args []Value) any {
appInstallChange := func() {
ctx.dispatch(func() {
notifyComponentEvent(appInstallChange{})
})
}

b.appInstallChange = FuncOf(func(this Value, args []Value) any {
appInstallChange()
return nil
})
Window().Set("goappOnAppInstallChange", b.appInstallChange)

if Window().Get("goappAppInstallChangedBeforeWasmLoaded").Truthy() {
appInstallChange()
}
}

func (b *browser) handleAppResize(ctx Context, notifyComponentEvent func(any)) {
Expand Down
16 changes: 10 additions & 6 deletions pkg/app/gen/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@
// go-app
// -----------------------------------------------------------------------------
var goappNav = function () {};
var goappOnUpdate = null;
var goappOnAppInstallChange = function () {};

var goappUpdatedBeforeWasmLoaded = false;
var goappOnUpdate = function () {
goappUpdatedBeforeWasmLoaded = true;
};

var goappAppInstallChangedBeforeWasmLoaded = false;
var goappOnAppInstallChange = function () {
goappAppInstallChangedBeforeWasmLoaded = true;
};

const goappEnv = {{.Env}};
const goappLoadingLabel = "{{.LoadingLabel}}";
Expand Down Expand Up @@ -58,10 +66,6 @@ function goappSetupNotifyUpdate(registration) {
if (newSW.state != "activated") {
return;
}
if (goappOnUpdate == null) {
goappOnUpdate = true;
return;
}
goappOnUpdate();
});
});
Expand Down
Loading

0 comments on commit 6d94193

Please sign in to comment.