Skip to content

Commit

Permalink
remove auto update interval (#936)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxence-charriere committed Mar 11, 2024
1 parent 3ace962 commit cd97cdc
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 17 deletions.
4 changes: 1 addition & 3 deletions docs/src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"path"
"sync"
"syscall"
"time"

"github.com/SherClockHolmes/webpush-go"
"github.com/maxence-charriere/go-app/v10/pkg/analytics"
Expand Down Expand Up @@ -130,7 +129,7 @@ func main() {
ThemeColor: backgroundColor,
LoadingLabel: "go-app documentation {progress}%",
Styles: []string{
"https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500&display=swap",
// "https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500&display=swap",
"/web/css/prism.css",
"/web/css/docs.css",
},
Expand All @@ -147,7 +146,6 @@ func main() {
"/web/documents/home.md",
"/web/documents/home-next.md",
},
AutoUpdateInterval: time.Minute,
}

switch cli.Load() {
Expand Down
9 changes: 9 additions & 0 deletions pkg/app/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ func (ctx Context) AppUpdateAvailable() bool {
return ctx.appUpdatable
}

// TryUpdateApp attempts to update the application in the browser. On success,
// it notifies components implementing the AppUpdater interface that an update
// is ready.
func (ctx Context) TryUpdateApp() {
if tryUpdate := Window().Get("goappTryUpdate"); IsClient && tryUpdate.Truthy() {
tryUpdate.Invoke()
}
}

// IsAppInstallable verifies if the app is eligible for installation.
func (ctx Context) IsAppInstallable() bool {
if Window().Get("goappIsAppInstallable").Truthy() {
Expand Down
10 changes: 3 additions & 7 deletions pkg/app/gen/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,11 @@ function goappSetupNotifyUpdate(registration) {
});
}

function goappSetupAutoUpdate(registration) {
const autoUpdateInterval = "{{.AutoUpdateInterval}}";
if (autoUpdateInterval == 0) {
function goappTryUpdate() {
if (!goappServiceWorkerRegistration) {
return;
}

window.setInterval(() => {
registration.update();
}, autoUpdateInterval);
goappServiceWorkerRegistration.update();
}

// -----------------------------------------------------------------------------
Expand Down
6 changes: 0 additions & 6 deletions pkg/app/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ type Handler struct {
// Body returns the page's body element. Defaults to app.Body().
Body func() HTMLBody

// AutoUpdateInterval sets how often the app auto-updates in the browser.
// Disabled if set to 0. Defaults to 0.
AutoUpdateInterval time.Duration

// Env passes environment variables to the PWA. Note: Reserved keys
// (GOAPP_VERSION, GOAPP_GOAPP_STATIC_RESOURCES_URL) cannot be
// overridden and are used for internal configuration.
Expand Down Expand Up @@ -324,15 +320,13 @@ func (h *Handler) makeAppJS() []byte {
WasmContentLength string
WasmContentLengthHeader string
WorkerJS string
AutoUpdateInterval int64
}{
Env: jsonString(h.Env),
LoadingLabel: h.LoadingLabel,
Wasm: h.Resources.Resolve("/web/app.wasm"),
WasmContentLength: h.WasmContentLength,
WasmContentLengthHeader: h.WasmContentLengthHeader,
WorkerJS: h.Resources.Resolve("/app-worker.js"),
AutoUpdateInterval: h.AutoUpdateInterval.Milliseconds(),
}); err != nil {
panic(errors.New("initializing app.js failed").Wrap(err))
}
Expand Down

0 comments on commit cd97cdc

Please sign in to comment.