11import { trySendMsg2Runtime } from '@api/sw/common'
2- import { getOption } from '@api/sw/option'
32import LocationWatcher from '@cs/location-watcher'
43import DelayCoordinator from '../manager/delay-coordinator'
54import LimitState from '../manager/state'
@@ -12,17 +11,17 @@ const TIMER_INTERVAL = 1000
1211export default class Countdown {
1312 #enabled: boolean = false
1413 #visible: boolean = false
15- #state = new CountdownState ( )
16- #component = new CountdownComponent ( )
1714 #interval?: ReturnType < typeof setInterval >
18- #onVisibleChange = ( ) => document . visibilityState === 'visible' && this . #sync( )
15+ readonly #state = new CountdownState ( )
16+ readonly #component = new CountdownComponent ( )
17+ readonly #onVisibleChange = ( ) => document . visibilityState === 'visible' && this . #sync( )
1918
2019 get isEffective ( ) {
2120 return this . #enabled && ! this . #visible && ! this . location . isWhite
2221 }
2322
2423 constructor ( private readonly location : LocationWatcher , initialOption : tt4b . option . LimitOption ) {
25- this . # applyOption( initialOption )
24+ this . applyOption ( initialOption )
2625 }
2726
2827 async init ( state : LimitState , visit : VisitProcessor , delayCoord : DelayCoordinator ) {
@@ -57,15 +56,10 @@ export default class Countdown {
5756 document . removeEventListener ( 'visibilitychange' , this . #onVisibleChange)
5857 }
5958
60- async fetchOption ( ) {
61- const option = await getOption ( )
62- this . #applyOption( option )
63- this . #sync( )
64- }
65-
66- #applyOption( option : tt4b . option . LimitOption ) {
59+ applyOption ( option : tt4b . option . LimitOption ) {
6760 this . #state. delayDuration = option . limitDelayDuration
6861 this . #enabled = option . limitCountdown
62+ this . #sync( )
6963 }
7064
7165 async #sync( ) {
@@ -91,7 +85,7 @@ export default class Countdown {
9185 this . #interval = undefined
9286 }
9387
94- async #render( ) {
88+ #render( ) {
9589 const data = this . #state. data
9690 this . #component. render ( data )
9791 data ? this . #startTimer( ) : this . #stopTimer( )
0 commit comments