forked from sheepzh/time-tracker-4-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathholder.ts
More file actions
36 lines (30 loc) · 977 Bytes
/
Copy pathholder.ts
File metadata and controls
36 lines (30 loc) · 977 Bytes
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
/**
* Copyright (c) 2021 Hengyang Zhang
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
import whitelistDatabase from "@db/whitelist-database"
import WhitelistProcessor from './processor'
/**
* The singleton implementation of whitelist holder
*/
class WhitelistHolder {
private processor = new WhitelistProcessor()
private postHandlers: NoArgCallback[]
constructor() {
whitelistDatabase.selectAll().then(list => this.processor.setWhitelist(list))
whitelistDatabase.addChangeListener(whitelist => {
this.processor.setWhitelist(whitelist)
this.postHandlers.forEach(handler => handler())
})
this.postHandlers = []
}
addPostHandler(handler: () => void) {
this.postHandlers.push(handler)
}
contains(host: string, url: string): boolean {
return this.processor.contains(host, url)
}
}
export default new WhitelistHolder()