From 012131283cb56d70dc3205a7c7a97139017c3efa Mon Sep 17 00:00:00 2001 From: Caleb Allen Date: Wed, 25 Feb 2026 19:10:37 -0500 Subject: [PATCH] fixed startup ondomready call to use wails bindings and call when complete --- backend/app.go | 21 ++++----------------- frontend/index.ts | 13 +++++++++++++ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/backend/app.go b/backend/app.go index 2a2df03..7af31ce 100644 --- a/backend/app.go +++ b/backend/app.go @@ -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() - } - }() } diff --git a/frontend/index.ts b/frontend/index.ts index aaf28d7..49aafe5 100644 --- a/frontend/index.ts +++ b/frontend/index.ts @@ -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();