feat(PageController): make showMask and hideMask async

This commit is contained in:
Simon
2026-01-19 12:54:33 +08:00
parent ef2777b521
commit 6820eec676
2 changed files with 9 additions and 5 deletions

View File

@@ -198,7 +198,7 @@ export class PageAgent extends EventTarget {
await onBeforeTask.call(this) await onBeforeTask.call(this)
// Show mask // Show mask
this.pageController.showMask() await this.pageController.showMask()
if (this.#abortController) { if (this.#abortController) {
this.#abortController.abort() this.#abortController.abort()
@@ -556,7 +556,7 @@ export class PageAgent extends EventTarget {
#onDone(text: string, success = true) { #onDone(text: string, success = true) {
this.pageController.cleanUpHighlights() this.pageController.cleanUpHighlights()
this.pageController.hideMask() this.pageController.hideMask() // No await - fire and forget
this.#setStatus(success ? 'completed' : 'error') this.#setStatus(success ? 'completed' : 'error')
this.#abortController.abort() this.#abortController.abort()
} }

View File

@@ -82,6 +82,7 @@ export class PageController extends EventTarget {
/** Visual mask overlay for blocking user interaction during automation */ /** Visual mask overlay for blocking user interaction during automation */
private mask: InstanceType<typeof import('./mask/SimulatorMask').SimulatorMask> | null = null private mask: InstanceType<typeof import('./mask/SimulatorMask').SimulatorMask> | null = null
private maskReady: Promise<void> | null = null
constructor(config: PageControllerConfig = {}) { constructor(config: PageControllerConfig = {}) {
super() super()
@@ -91,9 +92,10 @@ 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)
*/ */
@@ -369,7 +371,8 @@ 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 if enableMask was set to true in config.
*/ */
showMask(): void { async showMask(): Promise<void> {
await this.maskReady
this.mask?.show() this.mask?.show()
} }
@@ -377,7 +380,8 @@ 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 if enableMask was set to true in config.
*/ */
hideMask(): void { async hideMask(): Promise<void> {
await this.maskReady
this.mask?.hide() this.mask?.hide()
} }