refactor(main): extract initialization functions and handlers from app.whenReady#43
Merged
flexiondotorg merged 7 commits intomainfrom Mar 24, 2026
Merged
refactor(main): extract initialization functions and handlers from app.whenReady#43flexiondotorg merged 7 commits intomainfrom
flexiondotorg merged 7 commits intomainfrom
Conversation
Extract three initialization functions to improve code organisation and readability: - createSplash() handles splash window creation and promise wiring - setupApplicationMenu() handles menu setup with DevTools conditionals - initPlayerIPC() handles player creation and IPC handler registration The app.whenReady() callback now composes these functions rather than containing their implementation inline. No functional or behavioural changes. Signed-off-by: Martin Wimpress <code@wimpress.io>
Extract two functions to improve code organisation: - initSession(): async function handling Widevine CDM init, cache clearing, and user agent setup - loadAssets(): sync function loading Catppuccin CSS and navigation bar script from disk The app.whenReady() callback now composes these functions rather than containing their implementation inline. No functional changes. Signed-off-by: Martin Wimpress <code@wimpress.io>
Extract two functions from the app.whenReady callback: - createMainWindow(ses): creates BrowserWindow with content readiness polling and 3500ms timeout via Promise.race - setupWindowZoomAndNav(win): configures zoom factor and nav handlers Callback body now delegates to these functions. Signed-off-by: Martin Wimpress <code@wimpress.io>
Extract initCatppuccinCSS and setupSplashTransition from app.whenReady callback to reduce complexity and improve maintainability. Signed-off-by: Martin Wimpress <code@wimpress.io>
Extract three handler setup functions from app.whenReady() callback to improve readability and reduce nesting depth: - setupSessionHeaders: user-agent and request header management - setupWindowEvents: title, load, unload, and window-open handling - setupNavigationHandlers: navigation tracking and storefront persistence No functional change; handlers remain in the same execution order. Signed-off-by: Martin Wimpress <code@wimpress.io>
Completes Phase 1 refactoring by extracting the did-finish-load handler into setupContentHandlers(). Eliminates the firstLoad mutable flag using a self-nullifying initIntegrationsOnce pattern that preserves the original ordering dependency chain. Callback body reduced from 286 lines to 21 lines. All 13 function extractions from the original callback now complete, with callback logic fully linearised into a composed sequence of setup functions. Signed-off-by: Martin Wimpress <code@wimpress.io>
Change the most stable content readiness check after testing alternatives. The amp-lcd[hydrated] selector provides the most predictable behaviour. Visual pop-in of the LCD component is inherent to the Apple Music web app and cannot be cleanly eliminated from the outside. Signed-off-by: Martin Wimpress <code@wimpress.io>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refactored the main application initialization code by extracting related functions and handlers into smaller, more focused units. Improves code organisation and readability by breaking down the complex app.whenReady callback into logical sections without changing behaviour.
Changes
Testing
Related Issues
Resolves code smell concerns raised in refactoring review.