@@ -41,9 +41,10 @@ export class AppOrchestrator {
4141 let limit = await storage . getLimit ( pId ) ;
4242 const initialCount = await storage . getCount ( pId ) ;
4343 let isLimitEnabled = await storage . getEnableLimit ( pId ) ;
44- const timeLimitMins = await storage . getTimeLimit ( pId ) ;
45- const timeSpentMs = await storage . getTimeSpent ( pId ) ;
46- const isTimeEnabled = await storage . getEnableTime ( pId ) ;
44+
45+ let timeLimitMins = await storage . getTimeLimit ( pId ) ;
46+ let timeSpentMs = await storage . getTimeSpent ( pId ) ;
47+ let isTimeEnabled = await storage . getEnableTime ( pId ) ;
4748
4849 const limiter = new Limiter (
4950 { limit : isLimitEnabled ? limit : 0 } ,
@@ -67,16 +68,31 @@ export class AppOrchestrator {
6768 }
6869 limiter . setLimit ( isLimitEnabled ? limit : 0 ) ;
6970 }
71+
7072 if ( changes [ `limitra_${ pId } _count` ] ) {
7173 const newVal = Number ( changes [ `limitra_${ pId } _count` ] . newValue ) || 0 ;
7274 limiter . setInitialCount ( newVal ) ;
7375 if ( isLimitEnabled && limit > 0 && newVal >= limit ) {
7476 void safeBlock ( 'count' ) ;
7577 }
7678 }
79+
80+ if ( changes [ `limitra_${ pId } _time_limit` ] || changes [ `limitra_${ pId } _enable_time` ] ) {
81+ if ( changes [ `limitra_${ pId } _time_limit` ] ) {
82+ timeLimitMins = Number ( changes [ `limitra_${ pId } _time_limit` ] . newValue ) || 0 ;
83+ }
84+ if ( changes [ `limitra_${ pId } _enable_time` ] ) {
85+ isTimeEnabled = Boolean ( changes [ `limitra_${ pId } _enable_time` ] . newValue ) ;
86+ }
87+
88+ if ( isTimeEnabled && timeLimitMins > 0 && timeSpentMs >= timeLimitMins * 60 * 1000 ) {
89+ void safeBlock ( 'time' ) ;
90+ }
91+ }
92+
7793 if ( changes [ `limitra_${ pId } _time_spent` ] ) {
78- const newTime = Number ( changes [ `limitra_${ pId } _time_spent` ] . newValue ) || 0 ;
79- if ( isTimeEnabled && timeLimitMins > 0 && newTime >= timeLimitMins * 60 * 1000 ) {
94+ timeSpentMs = Number ( changes [ `limitra_${ pId } _time_spent` ] . newValue ) || 0 ;
95+ if ( isTimeEnabled && timeLimitMins > 0 && timeSpentMs >= timeLimitMins * 60 * 1000 ) {
8096 void safeBlock ( 'time' ) ;
8197 }
8298 }
0 commit comments