feat: delay mask import

This commit is contained in:
Simon
2026-01-28 17:16:39 +08:00
parent 142231a16c
commit 04d51c566d
2 changed files with 13 additions and 11 deletions

View File

@@ -15,8 +15,7 @@ export function initPageController() {
function getPC(): PageController { function getPC(): PageController {
if (!pageController) { if (!pageController) {
pageController = new PageController({ enableMask: true }) pageController = new PageController({ enableMask: false })
pageController.hideMask()
} }
return pageController return pageController
} }
@@ -35,7 +34,9 @@ export function initPageController() {
// }) // })
if (shouldShowMask) { if (shouldShowMask) {
await getPC().showMask() const pc = getPC()
pc.initMask()
await pc.showMask()
} else { } else {
// await getPC().hideMask() // await getPC().hideMask()
if (pageController) { if (pageController) {

View File

@@ -94,17 +94,18 @@ export class PageController extends EventTarget {
patchReact(this) patchReact(this)
if (config.enableMask) { if (config.enableMask) this.initMask()
this.maskReady = this.initMask()
}
} }
/** /**
* Initialize mask asynchronously (dynamic import to avoid CSS loading in Node) * Initialize mask asynchronously (dynamic import to avoid CSS loading in Node)
*/ */
private async initMask(): Promise<void> { initMask() {
const { SimulatorMask } = await import('./mask/SimulatorMask') if (this.maskReady !== null) return
this.mask = new SimulatorMask() this.maskReady = (async () => {
const { SimulatorMask } = await import('./mask/SimulatorMask')
this.mask = new SimulatorMask()
})()
} }
// ======= State Queries ======= // ======= State Queries =======
@@ -394,7 +395,7 @@ export class PageController extends EventTarget {
/** /**
* Show the visual mask overlay. * Show the visual mask overlay.
* Only works if enableMask was set to true in config. * Only works after mask is setup.
*/ */
async showMask(): Promise<void> { async showMask(): Promise<void> {
await this.maskReady await this.maskReady
@@ -403,7 +404,7 @@ export class PageController extends EventTarget {
/** /**
* Hide the visual mask overlay. * Hide the visual mask overlay.
* Only works if enableMask was set to true in config. * Only works after mask is setup.
*/ */
async hideMask(): Promise<void> { async hideMask(): Promise<void> {
await this.maskReady await this.maskReady