@@ -48,6 +48,7 @@ function updateUITexts() {
4848 document . body . dir = i18n . language === 'ar' ? 'rtl' : 'ltr' ;
4949 updateProgressBar ( ) ;
5050}
51+
5152function updateProgressBar ( ) {
5253 const isLimitEnabled = toggleLimit . checked ;
5354 const isTimeEnabled = toggleTime . checked ;
@@ -98,6 +99,40 @@ function updateProgressBar() {
9899 }
99100}
100101
102+ function syncUIState (
103+ isBlocked : boolean ,
104+ count : number ,
105+ timeMs : number ,
106+ isLimitEnabled : boolean ,
107+ isTimeEnabled : boolean ,
108+ ) {
109+ const timeSpentMins = Math . floor ( timeMs / ( 60 * 1000 ) ) ;
110+ const hasConsumed = count > 0 || timeSpentMins > 0 ;
111+
112+ if ( isBlocked ) {
113+ limitInput . disabled = true ;
114+ timeInput . disabled = true ;
115+ toggleLimit . disabled = true ;
116+ toggleTime . disabled = true ;
117+ btnSave . disabled = true ;
118+ btnSave . textContent = i18n . t . popup . lockedBtn ;
119+ } else if ( hasConsumed ) {
120+ limitInput . disabled = true ;
121+ timeInput . disabled = true ;
122+ toggleLimit . disabled = true ;
123+ toggleTime . disabled = true ;
124+ btnSave . disabled = true ;
125+ btnSave . textContent = i18n . t . popup . sessionActiveBtn ;
126+ } else {
127+ limitInput . disabled = ! isLimitEnabled ;
128+ timeInput . disabled = ! isTimeEnabled ;
129+ toggleLimit . disabled = false ;
130+ toggleTime . disabled = false ;
131+ btnSave . disabled = false ;
132+ btnSave . textContent = i18n . t . popup . saveBtn ;
133+ }
134+ }
135+
101136function lockUIForSelection ( ) {
102137 limitInput . value = '' ;
103138 timeInput . value = '' ;
@@ -139,24 +174,7 @@ async function loadPlatformData() {
139174 toggleLimit . checked = isLimitEnabled ;
140175 toggleTime . checked = isTimeEnabled ;
141176
142- if ( isBlocked ) {
143- limitInput . disabled = true ;
144- timeInput . disabled = true ;
145- toggleLimit . disabled = true ;
146- toggleTime . disabled = true ;
147- btnSave . disabled = true ;
148- btnSave . textContent = i18n . t . popup . lockedBtn ;
149- btnSave . classList . add ( 'warning' ) ;
150- } else {
151- limitInput . disabled = ! isLimitEnabled ;
152- timeInput . disabled = ! isTimeEnabled ;
153- toggleLimit . disabled = false ;
154- toggleTime . disabled = false ;
155- btnSave . disabled = false ;
156- btnSave . textContent = i18n . t . popup . saveBtn ;
157- btnSave . classList . remove ( 'warning' ) ;
158- }
159-
177+ syncUIState ( isBlocked , count , timeSpentMs , isLimitEnabled , isTimeEnabled ) ;
160178 updateProgressBar ( ) ;
161179}
162180
@@ -322,15 +340,13 @@ chrome.storage.onChanged.addListener((changes) => {
322340
323341 if ( checkLock ) {
324342 void storage . isCurrentlyBlocked ( activePlatform ) . then ( ( isBlocked ) => {
325- if ( isBlocked && ! btnSave . disabled ) {
326- limitInput . disabled = true ;
327- timeInput . disabled = true ;
328- toggleLimit . disabled = true ;
329- toggleTime . disabled = true ;
330- btnSave . disabled = true ;
331- btnSave . textContent = i18n . t . popup . lockedBtn ;
332- btnSave . classList . add ( 'warning' ) ;
333- }
343+ syncUIState (
344+ isBlocked ,
345+ currentConsumedCount ,
346+ currentConsumedTimeMs ,
347+ toggleLimit . checked ,
348+ toggleTime . checked ,
349+ ) ;
334350 } ) ;
335351 }
336352} ) ;
@@ -340,7 +356,11 @@ chrome.storage.onChanged.addListener((changes) => {
340356 if ( ! activePlatform ) return ;
341357
342358 const isBlocked = await storage . isCurrentlyBlocked ( activePlatform ) ;
343- if ( isBlocked ) {
359+ const count = await storage . getCount ( activePlatform ) ;
360+ const timeSpentMs = await storage . getTimeSpent ( activePlatform ) ;
361+ const hasConsumed = count > 0 || Math . floor ( timeSpentMs / ( 60 * 1000 ) ) > 0 ;
362+
363+ if ( isBlocked || hasConsumed ) {
344364 toggleLimit . disabled = true ;
345365 toggleTime . disabled = true ;
346366 limitInput . disabled = true ;
0 commit comments