fixed startup ondomready call to use wails bindings and call when complete

This commit is contained in:
2026-02-25 19:10:37 -05:00
parent cf144bf0dd
commit 012131283c
2 changed files with 17 additions and 17 deletions
+4 -17
View File
@@ -8,7 +8,6 @@ import (
"errors"
"fmt"
"log/slog"
"time"
wailsruntime "github.com/wailsapp/wails/v2/pkg/runtime"
@@ -202,25 +201,13 @@ func (yj *YellowJacketApp) OnShutdown(_ context.Context) {
}
// OnDomReady handles post-DOM initialization and startup error reporting.
// State synchronisation (player volume, track info, queue contents) is
// driven by the frontend: once its stores have registered their event
// listeners, index.ts calls Player.EmitCurrentState() and
// Queue.EmitCurrentState() via Wails bindings.
func (yj *YellowJacketApp) OnDomReady(ctx context.Context) {
if startupErr != nil {
yj.logger.Error("startup error", "err", startupErr.Error())
wailsruntime.Quit(ctx)
}
// Push current player and queue state to the frontend. The heavy lifting
// (file load, seek, volume) already happened during OnStartup via
// RestoreState; this just emits events. A short delay ensures the
// frontend JS modules have loaded and registered their event listeners.
go func() {
time.Sleep(200 * time.Millisecond)
if yj.player != nil {
yj.player.EmitCurrentState()
}
if yj.queue != nil {
yj.queue.EmitCurrentState()
}
}()
}
+13
View File
@@ -19,6 +19,8 @@ import '@awesome.me/webawesome/dist/components/icon/icon.js';
import { setBasePath } from '@awesome.me/webawesome/dist/webawesome.js';
import { queueStore } from '@store/queue-store';
import { searchStore } from '@store/search-store';
import * as Player from '@go/player/Player';
import * as Queue from '@go/queue/Queue';
// Importing the theme store triggers initialization: it fetches the saved
// theme from the backend and applies CSS custom properties to :root.
import '@store/theme-store';
@@ -164,3 +166,14 @@ document.addEventListener('keydown', (e: KeyboardEvent) => {
}
}
});
// ---------------------------------------------------------------
// Request current state from the backend
// ---------------------------------------------------------------
// All stores have registered their EventsOn listeners by now
// (module-level singletons are instantiated during import
// evaluation), so the state-push events emitted by these
// binding calls will be received deterministically — no sleep
// or timing assumptions needed.
void Player.EmitCurrentState();
void Queue.EmitCurrentState();