Skip to content

Commit f1da9dc

Browse files
committed
feat: semi
1 parent 14b3db8 commit f1da9dc

40 files changed

Lines changed: 606 additions & 268 deletions

src/api/sw/focus.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { sendMsg2Runtime } from './common'
2+
3+
export const listFocusPresets = () => sendMsg2Runtime('focus.allPresets')
4+
5+
export const getCurrentSession = () => sendMsg2Runtime('focus.current')
6+
7+
export const focusAction = (request: tt4b.focus.ActionRequest) => sendMsg2Runtime('focus.action', request)

src/background/message-dispatcher.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { exportData, importData, migrateStorage } from "./service/components/imm
1919
import { importOther, previewBackup } from "./service/components/import-processor"
2020
import optionHolder from "./service/components/option-holder"
2121
import { getWeekStartDay, getWeekStartTime } from "./service/components/week-helper"
22-
import { handleAction } from "./service/focus-service"
22+
import { getCurrentSession, handleAction } from "./service/focus-service"
2323
import { getTodayResult } from './service/item-service'
2424
import { getInstallTime, getLastBackUp } from "./service/meta-service"
2525
import notificationProcessor from './service/notification/processor'
@@ -136,6 +136,7 @@ class MessageDispatcher {
136136
.register('focus.addPreset', data => focusPresetDatabase.add(data))
137137
.register('focus.savePreset', data => focusPresetDatabase.update(data))
138138
.register('focus.action', handleAction)
139+
.register('focus.current', getCurrentSession)
139140
// Data immigration
140141
.register('immigration.import', importData)
141142
.register('immigration.export', exportData)

src/background/service/focus-service.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class FocusHolder {
6666
if (this.#session.state !== 'running') return
6767

6868
const now = Date.now()
69-
increaseTime(this.#session, now)
69+
await increaseTime(this.#session, now)
7070
this.#session.end = now
7171
this.#session.state = 'paused'
7272
this.#session.logs.push({ action: 'pause', ts: now })
@@ -98,10 +98,16 @@ class FocusHolder {
9898
this.#session.duration += MILL_PER_MINUTE * 5
9999
await db.save(this.#session)
100100
}
101+
102+
get current(): tt4b.focus.Record | undefined {
103+
return this.#session
104+
}
101105
}
102106

103107
const focusHolder = new FocusHolder()
104108

109+
export const getCurrentSession = () => focusHolder.current
110+
105111
export async function handleAction(request: tt4b.focus.ActionRequest): Promise<void> {
106112
if (typeof request === 'object') {
107113
return focusHolder.start(request.config, request.presetId)

src/i18n/message/app/limit-resource.json

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"enabled": "启用",
1414
"locked": "锁定",
1515
"effectiveDay": "生效日期",
16-
"allowDelay": "可延时",
1716
"or": "或者",
1817
"notEffective": "未生效"
1918
},
@@ -62,7 +61,6 @@
6261
"enabled": "是否啟用",
6362
"locked": "已鎖定",
6463
"effectiveDay": "生效日期",
65-
"allowDelay": "允許延遲",
6664
"or": "",
6765
"notEffective": "未生效"
6866
},
@@ -110,7 +108,6 @@
110108
"enabled": "Enabled",
111109
"locked": "Locked",
112110
"effectiveDay": "Effective On",
113-
"allowDelay": "Allow Delay",
114111
"or": "or",
115112
"notEffective": "Not effective"
116113
},
@@ -204,7 +201,6 @@
204201
"enabled": "Ativo",
205202
"locked": "Bloqueado",
206203
"effectiveDay": "Dias de aplicação",
207-
"allowDelay": "Permitir atraso",
208204
"or": "ou",
209205
"notEffective": "Não aplicável"
210206
},
@@ -252,7 +248,6 @@
252248
"enabled": "Увімкнено",
253249
"locked": "Заблоковано",
254250
"effectiveDay": "Діє",
255-
"allowDelay": "Дозволити затримку",
256251
"or": "або",
257252
"notEffective": "Не діє"
258253
},
@@ -347,7 +342,6 @@
347342
"enabled": "Aktiviert",
348343
"locked": "Gesperrt",
349344
"effectiveDay": "Wirksam auf",
350-
"allowDelay": "Verzögerung zulassen",
351345
"or": "oder",
352346
"notEffective": "Nicht wirksam"
353347
},
@@ -397,7 +391,6 @@
397391
"enabled": "Activé",
398392
"locked": "Verrouillé",
399393
"effectiveDay": "Effectif le",
400-
"allowDelay": "Retardable",
401394
"or": "ou",
402395
"notEffective": "Non efficace"
403396
},
@@ -447,7 +440,6 @@
447440
"enabled": "Включено",
448441
"locked": "Заблокировано",
449442
"effectiveDay": "Эффективный",
450-
"allowDelay": "Разрешить задержку",
451443
"or": "или",
452444
"notEffective": "Не активировано"
453445
},
@@ -541,7 +533,6 @@
541533
"enabled": "Etkinleştirildi",
542534
"locked": "Kilitli",
543535
"effectiveDay": "Geçerli Olduğu Gün(ler)",
544-
"allowDelay": "Ertelenebilir",
545536
"or": "yada",
546537
"notEffective": "Geçerli değil"
547538
},
@@ -588,7 +579,6 @@
588579
"enabled": "Aktywne",
589580
"locked": "Zablokowany",
590581
"effectiveDay": "Aktywna w",
591-
"allowDelay": "Możliwe do przedłużenia",
592582
"or": "lub",
593583
"notEffective": "Nieskuteczny"
594584
},
@@ -636,7 +626,6 @@
636626
"enabled": "Attivata",
637627
"locked": "Bloccato",
638628
"effectiveDay": "Effettivo On",
639-
"allowDelay": "Ritardabile",
640629
"or": "o",
641630
"notEffective": "Non valido"
642631
},

src/i18n/message/app/limit.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export type LimitMessage = {
2424
enabled: string
2525
locked: string
2626
effectiveDay: string
27-
allowDelay: string
2827
delayCount: string
2928
detail: string
3029
or: string

src/i18n/message/app/menu-resource.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"analysis": "Site Analysis",
2929
"productivity": "Productivity & Focus",
3030
"habit": "Habits",
31-
"focus": "Focus Mode",
3231
"siteRule": "Sites & Rules",
3332
"sites": "Site Management",
3433
"whitelist": "Whitelist",

src/i18n/message/app/menu.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,12 @@ export type MenuMessage = {
1212
dashboard: string
1313
record: string
1414
analysis: string
15-
1615
productivity: string
1716
habit: string
18-
focus: string
19-
2017
siteRule: string
2118
sites: string
2219
whitelist: string
2320
mergeRule: string
24-
2521
other: string
2622
migration: string
2723
about: string

src/i18n/message/common/shared-resource.json

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,17 @@
1818
"daily": "Daily limit",
1919
"weekly": "Weekly limit",
2020
"period": "Blocked periods",
21-
"visits": "{n} visits"
21+
"visits": "{n} visits",
22+
"allowDelay": "Allow Delay",
23+
"unlimited": "Unlimited"
24+
},
25+
"focus": {
26+
"menu": "Focus Mode",
27+
"mode": {
28+
"allow": "Allow only",
29+
"block": "Block"
30+
},
31+
"duration": "Focus Time"
2232
}
2333
},
2434
"zh_CN": {
@@ -40,7 +50,8 @@
4050
"daily": "每日上限",
4151
"weekly": "每周上限",
4252
"period": "不可访问的时间段",
43-
"visits": "{n}次访问"
53+
"visits": "{n}次访问",
54+
"allowDelay": "可延时"
4455
}
4556
},
4657
"ja": {
@@ -83,7 +94,8 @@
8394
"daily": "每日上限",
8495
"weekly": "每週上限",
8596
"period": "限制時段",
86-
"visits": "{n}次造訪"
97+
"visits": "{n}次造訪",
98+
"allowDelay": "允許延遲"
8799
}
88100
},
89101
"pt_PT": {
@@ -104,7 +116,8 @@
104116
"daily": "Limite diário",
105117
"weekly": "Limite semanal",
106118
"period": "Períodos bloqueados",
107-
"visits": "{n} visitas"
119+
"visits": "{n} visitas",
120+
"allowDelay": "Permitir atraso"
108121
}
109122
},
110123
"uk": {
@@ -125,7 +138,8 @@
125138
"daily": "Денний ліміт",
126139
"weekly": "Тижневий ліміт",
127140
"period": "Недозволені періоди",
128-
"visits": "{n} відвідування"
141+
"visits": "{n} відвідування",
142+
"allowDelay": "Дозволити затримку"
129143
}
130144
},
131145
"it": {
@@ -147,7 +161,8 @@
147161
"daily": "Limite giornaliero",
148162
"weekly": "Limite settimanale",
149163
"period": "Periodi bloccati",
150-
"visits": "{n} visite"
164+
"visits": "{n} visite",
165+
"allowDelay": "Ritardabile"
151166
}
152167
},
153168
"es": {
@@ -190,7 +205,8 @@
190205
"daily": "Tägliches Limit",
191206
"weekly": "Wöchentliches Limit",
192207
"period": "Unzulässiger Zeitraum",
193-
"visits": "{n} Besuche"
208+
"visits": "{n} Besuche",
209+
"allowDelay": "Verzögerung zulassen"
194210
}
195211
},
196212
"fr": {
@@ -212,7 +228,8 @@
212228
"daily": "Limite quotidienne",
213229
"weekly": "Limite hebdomadaire",
214230
"period": "Périodes bloquées",
215-
"visits": "{n} visites"
231+
"visits": "{n} visites",
232+
"allowDelay": "Retardable"
216233
}
217234
},
218235
"ru": {
@@ -233,7 +250,8 @@
233250
"daily": "Дневной лимит",
234251
"weekly": "Недельный лимит",
235252
"period": "Заблокированное время",
236-
"visits": "{n} посещения"
253+
"visits": "{n} посещения",
254+
"allowDelay": "Разрешить задержку"
237255
}
238256
},
239257
"ar": {
@@ -275,7 +293,8 @@
275293
"daily": "Günlük limit",
276294
"weekly": "Haftalık limit",
277295
"period": "Engellenen periyotlar",
278-
"visits": "{n} ziyaretler"
296+
"visits": "{n} ziyaretler",
297+
"allowDelay": "Ertelenebilir"
279298
}
280299
},
281300
"pl": {
@@ -296,7 +315,8 @@
296315
"daily": "Dzienny limit",
297316
"weekly": "Limit tygodniowy",
298317
"period": "Godziny blokowania",
299-
"visits": "{n} wizyt"
318+
"visits": "{n} wizyt",
319+
"allowDelay": "Możliwe do przedłużenia"
300320
}
301321
}
302322
}

src/i18n/message/common/shared.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ export type SharedMessage = {
1414
weekly: string
1515
period: string
1616
visits: string
17+
allowDelay: string
18+
unlimited: string
19+
}
20+
focus: {
21+
menu: string
22+
mode: Record<tt4b.focus.Mode, string>
23+
duration: string
1724
}
1825
}
1926

src/i18n/message/popup/content.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ export type ContentMessage = {
3737
}
3838
}
3939

40-
const contentMessages = resource as Messages<ContentMessage>
40+
const contentMessages = resource satisfies Messages<ContentMessage>
4141

4242
export default contentMessages

0 commit comments

Comments
 (0)