-
-
Notifications
You must be signed in to change notification settings - Fork 138
/
detector.ts
44 lines (39 loc) · 1.09 KB
/
detector.ts
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
/*
* @Author: tackchen
* @Date: 2022-09-27 22:10:25
* @Description: Coding something
*/
import {closeWindow} from 'src/utils/close-window';
import {config} from 'src/utils/config';
import {DetectorType} from 'src/utils/enum';
import {clearDDInterval, clearDDTimeout, registInterval} from 'src/utils/interval';
import {markDevToolOpenState} from 'src/utils/open-state';
export interface IDetectorConfig {
type: DetectorType;
enabled?: boolean;
}
export abstract class Detector {
type: DetectorType = DetectorType.Unknown;
enabled: boolean = true;
constructor ({
type, enabled = true
}: IDetectorConfig) {
this.type = type;
this.enabled = enabled;
if (this.enabled) {
registInterval(this);
this.init();
}
}
onDevToolOpen () {
console.warn(`You don't have permission to use DEVTOOL!【type = ${this.type}】`);
if (config.clearIntervalWhenDevOpenTrigger) {
clearDDInterval();
}
clearDDTimeout();
config.ondevtoolopen(this.type, closeWindow);
markDevToolOpenState(this.type);
}
init () {};
abstract detect (time: number): void;
}