forked from sheepzh/time-tracker-4-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
45 lines (36 loc) · 1.31 KB
/
index.ts
File metadata and controls
45 lines (36 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import optionService from "@service/option-service"
import { MILL_PER_MINUTE } from "@util/time"
import { exitFullscreen, type Processor } from "../common"
import { createComponent } from "./component"
class Reminder implements Processor {
private id = 0
private el: HTMLElement | undefined
private darkMode: boolean = false
handleMsg(code: timer.mq.ReqCode, data: unknown): timer.mq.Response | Promise<timer.mq.Response> {
if (code !== 'limitReminder') {
return { code: 'ignore' }
}
this.show(data as timer.limit.ReminderInfo)
return { code: 'success' }
}
private async show(data: timer.limit.ReminderInfo) {
if (!document?.body || this.el) return
await exitFullscreen()
const el = createComponent(this.darkMode, data, () => this.close())
const domId = `time-tracker-notification-${this.id++}`
el.id = domId
document.body.append(el)
this.el = el
const duration = data?.duration
duration && setTimeout(() => this.close(), duration * MILL_PER_MINUTE)
}
private close() {
if (!this.el) return
this.el.remove()
this.el = undefined
}
async init(): Promise<void> {
this.darkMode = await optionService.isDarkMode()
}
}
export default Reminder