refactor(frontend): fold main.ts / main.web.ts / main.capacitor.ts into bootstrapApp - #324
Merged
Conversation
…to bootstrapApp
M7-d. The three Vite entry points open-coded the same six-step boot
sequence:
1. await initI18n({ loadPreference, savePreference })
2. bridgeSharedI18n()
3. platform-specific pre-mount setup
4. initPlatform(<factory>)
5. createApp(App).use(Pinia).provide('platform').mount('#app')
6. platform-specific post-mount side effects
Steps 1, 2, 4, 5 were identical text. Steps 3 and 6 were the *only*
things that actually differed (Wails: EventsOn wire; web: prefsSync
engine wiring; capacitor: iOS keyboard accessory + capacitor prefsSync
+ locale storage helpers). Three copies of the same boilerplate had
already drifted — the web entry silently missed the shared-i18n
locale bridge for a stretch, capacitor forgot the prefs:changed hook
that Wails installs, etc.
Fold the common path into `lib/bootstrapApp.ts` with a
`bootstrapApp({ i18n, createPlatform, beforeMount?, afterMount? })`
API. Each main.* becomes a small config object naming what actually
differs:
main.ts 35 → 21 lines
main.web.ts 42 → 26 lines
main.capacitor.ts 65 → 50 lines
bootstrapApp.ts new 66 lines
Behavior is preserved verbatim per entry — same load/save locale hooks,
same platform factory, same prefsSync engines wired at the same point,
same EventsOn hook, same iOS keyboard toggle. The shared-i18n locale
bridge, previously a copy in each file, now runs unconditionally in
bootstrapApp (matches what all three were already doing).
Test update: `App.test.ts > capacitor uses the shared web shell` was
scanning main.capacitor.ts for `import App from './App.vue'` +
`createApp(App)`; both moved into bootstrapApp.ts. The test now checks
that capacitor main calls `bootstrapApp(` with `createCapacitorPlatform`
and never re-introduces the old MobileApp shell.
`npm test` 1631/1631; `npm run build` green.
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
Milestone 7-d. The three Vite entry points open-coded the same six-step boot sequence:
Steps 1, 2, 4, 5 were identical text. Steps 3 and 6 were the only things that actually differed (Wails: `EventsOn` wire; web: prefsSync engine wiring; capacitor: iOS keyboard accessory + capacitor prefsSync + locale storage helpers). Three copies of the same boilerplate had already drifted — the web entry silently missed the shared-i18n locale bridge for a stretch, capacitor forgot the `prefs:changed` hook that Wails installs, etc.
Fold the common path into `lib/bootstrapApp.ts` with a `bootstrapApp({ i18n, createPlatform, beforeMount?, afterMount? })` API. Each main.* becomes a small config object naming what actually differs:
Behavior is preserved verbatim per entry — same load/save locale hooks, same platform factory, same prefsSync engines wired at the same point, same `EventsOn` hook, same iOS keyboard toggle. The shared-i18n locale bridge, previously a copy in each file, now runs unconditionally in `bootstrapApp` (matches what all three were already doing).
Test update: `App.test.ts > capacitor uses the shared web shell` was scanning main.capacitor.ts for `import App from './App.vue'` + `createApp(App)`; both moved into bootstrapApp.ts. The test now checks that capacitor main calls `bootstrapApp(` with `createCapacitorPlatform` and never re-introduces the old MobileApp shell.
Test plan