Skip to content

refactor(main): extract initialization functions and handlers from app.whenReady#43

Merged
flexiondotorg merged 7 commits intomainfrom
no-smell
Mar 24, 2026
Merged

refactor(main): extract initialization functions and handlers from app.whenReady#43
flexiondotorg merged 7 commits intomainfrom
no-smell

Conversation

@flexiondotorg
Copy link
Copy Markdown
Member

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

  • Extract initSession and loadAssets functions
  • Extract window creation and setup logic
  • Extract Catppuccin CSS and splash transition setup
  • Extract session, window, and navigation event handlers
  • Extract content handlers and eliminate firstLoad flag
  • Set content readiness selector to amp-lcd[hydrated]

Testing

  • Application initialization follows the same flow as before
  • No functional changes; all existing features work identically
  • Code structure improved for maintainability

Related Issues

Resolves code smell concerns raised in refactoring review.

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>
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Requires human review: This PR is a code refactor that reorganizes application initialization logic and modifies content readiness selectors, which requires human review per the defined safety guidelines.

@flexiondotorg flexiondotorg merged commit c8cec9d into main Mar 24, 2026
11 checks passed
@flexiondotorg flexiondotorg deleted the no-smell branch March 24, 2026 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant