Skip to content

Commit 634b3fd

Browse files
committed
Fix OnDomReady callback being run multiple times
1 parent d05c5ad commit 634b3fd

1 file changed

Lines changed: 27 additions & 24 deletions

File tree

main.go

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,32 @@ func main() {
143143

144144
migration.Init()
145145

146+
// OnDomReady is called on every refresh
147+
onDomReadyOnce := sync.OnceFunc(func() {
148+
// Wails doesn't expose the user agent configuration, it only uses wails.io for dev app/browser detection
149+
// I don't really feel like properly implementing this into wails2, with wails3 around the corner
150+
// which will no longer rely on wails.io being in the user agent, so the current code that sets it to wails.io
151+
// can be replaced with a configurable value
152+
// But for now, hacky reflection it is, to append our own user agent
153+
// On Windows and Linux, this can be done on startup,
154+
// but for Darwin, it uses evaluateJavaScript to get the default user agent,
155+
// and that crashes if the webview is not yet ready
156+
// The only requests made before this are the initial asset requests, for which we don't really care about the user agent
157+
wailsextras.AddUserAgent("SatisfactoryModManager", viper.GetString("version"))
158+
159+
if startUpdateFound {
160+
if autoupdate.Updater.Updater.PendingUpdate != nil && autoupdate.Updater.Updater.PendingUpdate.Ready {
161+
autoupdate.Updater.UpdateAndRestart() //nolint:contextcheck
162+
} else {
163+
autoupdate.Updater.Updater.UpdateReady.Once(func(_ interface{}) {
164+
autoupdate.Updater.UpdateAndRestart()
165+
})
166+
}
167+
}
168+
backend.ProcessArguments(os.Args[1:]) //nolint:contextcheck
169+
autoupdate.Updater.CheckInterval(5 * time.Minute)
170+
})
171+
146172
// Create application with options
147173
err = wails.Run(&options.App{
148174
Title: "SatisfactoryModManager",
@@ -185,30 +211,7 @@ func main() {
185211
},
186212
OnDomReady: func(_ context.Context) {
187213
// OnDomReady is called on every refresh
188-
sync.OnceFunc(func() {
189-
// Wails doesn't expose the user agent configuration, it only uses wails.io for dev app/browser detection
190-
// I don't really feel like properly implementing this into wails2, with wails3 around the corner
191-
// which will no longer rely on wails.io being in the user agent, so the current code that sets it to wails.io
192-
// can be replaced with a configurable value
193-
// But for now, hacky reflection it is, to append our own user agent
194-
// On Windows and Linux, this can be done on startup,
195-
// but for Darwin, it uses evaluateJavaScript to get the default user agent,
196-
// and that crashes if the webview is not yet ready
197-
// The only requests made before this are the initial asset requests, for which we don't really care about the user agent
198-
wailsextras.AddUserAgent("SatisfactoryModManager", viper.GetString("version"))
199-
200-
if startUpdateFound {
201-
if autoupdate.Updater.Updater.PendingUpdate != nil && autoupdate.Updater.Updater.PendingUpdate.Ready {
202-
autoupdate.Updater.UpdateAndRestart() //nolint:contextcheck
203-
} else {
204-
autoupdate.Updater.Updater.UpdateReady.Once(func(_ interface{}) {
205-
autoupdate.Updater.UpdateAndRestart()
206-
})
207-
}
208-
}
209-
backend.ProcessArguments(os.Args[1:]) //nolint:contextcheck
210-
autoupdate.Updater.CheckInterval(5 * time.Minute)
211-
})()
214+
onDomReadyOnce()
212215
},
213216
OnShutdown: func(_ context.Context) {
214217
app.App.StopWindowWatcher()

0 commit comments

Comments
 (0)