From fa7a2997e8a23beb12e8e815eeda8257019f2ac9 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 8 Feb 2026 03:40:49 +0000 Subject: [PATCH] Refactor Application.init into initialization phases Co-authored-by: PR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> --- js/app.js | 70 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 24 deletions(-) diff --git a/js/app.js b/js/app.js index 0f040880..fab8df69 100644 --- a/js/app.js +++ b/js/app.js @@ -1208,36 +1208,58 @@ class Application { await watchHistoryInitPromise; } + async initializeServices() { + await this._initViewManager(); + this._warmupNostrExtension(); + this._initServiceWorker(); + this._initAuthAndModeration(); + } + + initializeUIResources() { + return this._initModals(); + } + + async initializeNetwork() { + await this._initNostr(); + } + + async initializeDataAndSession() { + await this._initTrustedSeeds(); + this._initViewCounter(); + this._initAccessControl(); + + await this._initSessionActor(); + this._initAccessControlListeners(); + } + + initializeUserInterface() { + this._initUI(); + } + + async performAutoLogin() { + await this._initAutoLogin(); + } + + async finalizeInitialization() { + this.setupEventListeners(); + await this._initWatchHistory(); + this.checkUrlParams(); + } + async init() { try { - await this._initViewManager(); - this._warmupNostrExtension(); - this._initServiceWorker(); - this._initAuthAndModeration(); + await this.initializeServices(); - const modalBootstrapPromise = this._initModals(); + const modalPromise = this.initializeUIResources(); + await this.initializeNetwork(); + await modalPromise; - await this._initNostr(); + await this.initializeDataAndSession(); - await modalBootstrapPromise; - - await this._initTrustedSeeds(); - this._initViewCounter(); - this._initAccessControl(); - - await this._initSessionActor(); - this._initAccessControlListeners(); - this._initUI(); - await this._initAutoLogin(); - - // 5. Setup general event listeners - this.setupEventListeners(); - - await this._initWatchHistory(); - - // 9. Check URL ?v= param - this.checkUrlParams(); + this.initializeUserInterface(); + await this.performAutoLogin(); + await this.finalizeInitialization(); } catch (error) { devLogger.error("Init failed:", error); this.showError("Failed to connect to Nostr relay");